From 99d2faf97d4bc67ab1d8809a1cbfce3d4a71a9f3 Mon Sep 17 00:00:00 2001 From: anhefti Date: Wed, 11 Sep 2019 12:59:43 +0200 Subject: [PATCH] tests and PMD and coverage --- pmd-rulesets.xml | 2 ++ pom.xml | 14 +++---------- .../ethz/seb/sebserver/gbl/util/Result.java | 8 ++++---- .../impl/AbstractTableFieldBuilder.java | 1 + .../examconfig/impl/ViewGridBuilder.java | 2 ++ .../page/impl/ComposerServiceImpl.java | 2 +- .../gui/service/page/impl/PageAction.java | 8 ++++---- .../service/page/impl/PageContextImpl.java | 4 ++-- .../remote/webservice/api/RestCall.java | 20 +++++++++---------- 9 files changed, 29 insertions(+), 32 deletions(-) diff --git a/pmd-rulesets.xml b/pmd-rulesets.xml index efb5d8a5..4ae9a427 100644 --- a/pmd-rulesets.xml +++ b/pmd-rulesets.xml @@ -15,6 +15,8 @@ + + diff --git a/pom.xml b/pom.xml index 598c35cb..124f7ea6 100644 --- a/pom.xml +++ b/pom.xml @@ -173,14 +173,6 @@ report - - - ch/ethz/seb/sebserver/gui/content/**/* - ch/ethz/seb/sebserver/gui/form/**/* - ch/ethz/seb/sebserver/gui/table/**/* - ch/ethz/seb/sebserver/gui/widget/**/* - - post-unit-test @@ -198,9 +190,9 @@ - - ch/ethz/seb/sebserver/* - + + + ch/ethz/seb/sebserver/gui/content/**/* ch/ethz/seb/sebserver/gui/form/**/* diff --git a/src/main/java/ch/ethz/seb/sebserver/gbl/util/Result.java b/src/main/java/ch/ethz/seb/sebserver/gbl/util/Result.java index 2653e82e..5ffa2bf1 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gbl/util/Result.java +++ b/src/main/java/ch/ethz/seb/sebserver/gbl/util/Result.java @@ -207,8 +207,8 @@ public final class Result { throw new IllegalArgumentException("Use flatMap instead!"); } return Result.of(result); - } catch (final Throwable t) { - return Result.ofError(t); + } catch (final Exception e) { + return Result.ofError(e); } } else { return Result.ofError(this.error); @@ -230,8 +230,8 @@ public final class Result { if (this.error == null) { try { return mapf.apply(this.value); - } catch (final Throwable t) { - return Result.ofError(t); + } catch (final Exception e) { + return Result.ofError(e); } } else { return Result.ofError(this.error); diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/service/examconfig/impl/AbstractTableFieldBuilder.java b/src/main/java/ch/ethz/seb/sebserver/gui/service/examconfig/impl/AbstractTableFieldBuilder.java index b9882fcf..4d0b55ae 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/service/examconfig/impl/AbstractTableFieldBuilder.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/service/examconfig/impl/AbstractTableFieldBuilder.java @@ -151,6 +151,7 @@ public abstract class AbstractTableFieldBuilder implements InputFieldBuilder { } default: { item.setText(cellIndex, getValue(attribute, tableValue)); + break; } } } diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/service/examconfig/impl/ViewGridBuilder.java b/src/main/java/ch/ethz/seb/sebserver/gui/service/examconfig/impl/ViewGridBuilder.java index 4fc18003..d616749d 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/service/examconfig/impl/ViewGridBuilder.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/service/examconfig/impl/ViewGridBuilder.java @@ -145,6 +145,8 @@ public class ViewGridBuilder { break; } default: { + // do nothing + break; } } } catch (final ArrayIndexOutOfBoundsException e) { diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/service/page/impl/ComposerServiceImpl.java b/src/main/java/ch/ethz/seb/sebserver/gui/service/page/impl/ComposerServiceImpl.java index e24b2eff..aca472d3 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/service/page/impl/ComposerServiceImpl.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/service/page/impl/ComposerServiceImpl.java @@ -120,7 +120,7 @@ public class ComposerServiceImpl implements ComposerService { try { composer.compose(pageContext); PageService.updateScrolledComposite(pageContext.getParent()); - } catch (final Throwable e) { + } catch (final Exception e) { log.error("Failed to compose: {}, pageContext: {}", name, pageContext, e); } diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/service/page/impl/PageAction.java b/src/main/java/ch/ethz/seb/sebserver/gui/service/page/impl/PageAction.java index 4d3ba278..c2aef318 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/service/page/impl/PageAction.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/service/page/impl/PageAction.java @@ -143,10 +143,10 @@ public final class PageAction { PageAction.this.pageContext.notifyError("action.error.unexpected.message", restCallError); } return Result.ofError(restCallError); - } catch (final Throwable t) { - log.error("Failed to execute action: {}", PageAction.this, t); - PageAction.this.pageContext.notifyError("action.error.unexpected.message", t); - return Result.ofError(t); + } catch (final Exception e) { + log.error("Failed to execute action: {}", PageAction.this, e); + PageAction.this.pageContext.notifyError("action.error.unexpected.message", e); + return Result.ofError(e); } } diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/service/page/impl/PageContextImpl.java b/src/main/java/ch/ethz/seb/sebserver/gui/service/page/impl/PageContextImpl.java index 1673a4cb..a73edb4f 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/service/page/impl/PageContextImpl.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/service/page/impl/PageContextImpl.java @@ -327,10 +327,10 @@ public class PageContextImpl implements PageContext { if (returnCode == SWT.OK) { try { this.onOK.accept(true); - } catch (final Throwable t) { + } catch (final Exception e) { log.error( "Unexpected on confirm callback execution. This should not happen, plase secure the given onOK Runnable", - t); + e); this.onOK.accept(false); } } diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/service/remote/webservice/api/RestCall.java b/src/main/java/ch/ethz/seb/sebserver/gui/service/remote/webservice/api/RestCall.java index f1e1b744..ac9c52ca 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/service/remote/webservice/api/RestCall.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/service/remote/webservice/api/RestCall.java @@ -115,11 +115,11 @@ public abstract class RestCall { return handleRestCallError(responseEntity); } - } catch (final Throwable t) { - final RestCallError restCallError = new RestCallError("Unexpected error while rest call", t); + } catch (final Exception e) { + final RestCallError restCallError = new RestCallError("Unexpected error while rest call", e); try { - final String responseBody = ((RestClientResponseException) t).getResponseBodyAsString(); + final String responseBody = ((RestClientResponseException) e).getResponseBodyAsString(); restCallError.errors.addAll(RestCall.this.jsonMapper.readValue( responseBody, @@ -127,16 +127,16 @@ public abstract class RestCall { })); } catch (final ClassCastException cce) { - log.error("Unexpected error-response while webservice API call for: {}", builder, t); - restCallError.errors.add(APIMessage.ErrorMessage.UNEXPECTED.of(t)); + log.error("Unexpected error-response while webservice API call for: {}", builder, e); + restCallError.errors.add(APIMessage.ErrorMessage.UNEXPECTED.of(e)); } catch (final RuntimeException re) { log.error("Unexpected runtime error while webservice API call for: {}", builder, re); - log.error("Unexpected runtime error cause: ", t); + log.error("Unexpected runtime error cause: ", e); restCallError.errors.add(APIMessage.ErrorMessage.UNEXPECTED.of(re)); - } catch (final Exception e) { - log.error("Unexpected error while webservice API call for: {}", builder, e); - log.error("Unexpected error cause: ", t); - restCallError.errors.add(APIMessage.ErrorMessage.UNEXPECTED.of(e)); + } catch (final Exception ee) { + log.error("Unexpected error while webservice API call for: {}", builder, ee); + log.error("Unexpected error cause: ", e); + restCallError.errors.add(APIMessage.ErrorMessage.UNEXPECTED.of(ee)); } return Result.ofError(restCallError);