From 13466eb1c7f40b9efb781e1f384bff08d9c836e5 Mon Sep 17 00:00:00 2001 From: Jens Schauder Date: Mon, 15 Apr 2019 10:30:36 +0200 Subject: [PATCH] #980 - Polishing. Moved to latest JUnit version. Limited assertions of exceptions to one method call. --- pom.xml | 2 +- .../hateoas/RepresentationModelUnitTest.java | 6 ++++-- .../hateoas/UriTemplateUnitTest.java | 3 ++- .../mediatype/hal/HalEmbeddedBuilderUnitTest.java | 4 +++- .../server/mvc/ControllerLinkBuilderUnitTest.java | 14 ++++++++------ 5 files changed, 18 insertions(+), 11 deletions(-) diff --git a/pom.xml b/pom.xml index 9907b7ee9..5636b4f16 100644 --- a/pom.xml +++ b/pom.xml @@ -78,7 +78,7 @@ spring.hateoas 2.2.0 3.0.2 - 5.3.2 + 5.4.1 2.2.1 Californium-SR4 1.7.25 diff --git a/src/test/java/org/springframework/hateoas/RepresentationModelUnitTest.java b/src/test/java/org/springframework/hateoas/RepresentationModelUnitTest.java index 75e307154..784c97558 100755 --- a/src/test/java/org/springframework/hateoas/RepresentationModelUnitTest.java +++ b/src/test/java/org/springframework/hateoas/RepresentationModelUnitTest.java @@ -85,8 +85,9 @@ public void addsLinksCorrectly() { @Test public void preventsNullLinkBeingAdded() { + RepresentationModel support = new RepresentationModel<>(); + assertThatIllegalArgumentException().isThrownBy(() -> { - RepresentationModel support = new RepresentationModel<>(); support.add((Link) null); }); } @@ -94,8 +95,9 @@ public void preventsNullLinkBeingAdded() { @Test public void preventsNullLinksBeingAdded() { + RepresentationModel support = new RepresentationModel<>(); + assertThatIllegalArgumentException().isThrownBy(() -> { - RepresentationModel support = new RepresentationModel<>(); support.add((Iterable) null); }); } diff --git a/src/test/java/org/springframework/hateoas/UriTemplateUnitTest.java b/src/test/java/org/springframework/hateoas/UriTemplateUnitTest.java index 26cdd2491..0ed491107 100755 --- a/src/test/java/org/springframework/hateoas/UriTemplateUnitTest.java +++ b/src/test/java/org/springframework/hateoas/UriTemplateUnitTest.java @@ -150,8 +150,9 @@ public void expandsMultipleRequestParameters() { @Test public void rejectsMissingRequiredPathVariable() { + UriTemplate template = UriTemplate.of("/foo/{bar}"); + assertThatIllegalArgumentException().isThrownBy(() -> { - UriTemplate template = UriTemplate.of("/foo/{bar}"); template.expand(Collections.emptyMap()); }); } diff --git a/src/test/java/org/springframework/hateoas/mediatype/hal/HalEmbeddedBuilderUnitTest.java b/src/test/java/org/springframework/hateoas/mediatype/hal/HalEmbeddedBuilderUnitTest.java index 41b5837a5..58ea51346 100755 --- a/src/test/java/org/springframework/hateoas/mediatype/hal/HalEmbeddedBuilderUnitTest.java +++ b/src/test/java/org/springframework/hateoas/mediatype/hal/HalEmbeddedBuilderUnitTest.java @@ -176,8 +176,10 @@ public void forcesCollectionRelToBeUsedIfConfiguredWithCurieProvider() { @Test public void rejectsInvalidEmbeddedWrapper() { + HalEmbeddedBuilder builder = new HalEmbeddedBuilder(provider, curieProvider, false); + assertThatIllegalStateException().isThrownBy(() -> { - new HalEmbeddedBuilder(provider, curieProvider, false).add(mock(EmbeddedWrapper.class)); + builder.add(mock(EmbeddedWrapper.class)); }); } diff --git a/src/test/java/org/springframework/hateoas/server/mvc/ControllerLinkBuilderUnitTest.java b/src/test/java/org/springframework/hateoas/server/mvc/ControllerLinkBuilderUnitTest.java index 1a59da75e..21e21880e 100755 --- a/src/test/java/org/springframework/hateoas/server/mvc/ControllerLinkBuilderUnitTest.java +++ b/src/test/java/org/springframework/hateoas/server/mvc/ControllerLinkBuilderUnitTest.java @@ -301,9 +301,10 @@ public void appendsOptionalParameterVariableForUnsetParameter() { @Test public void rejectsMissingPathVariable() { + ControllerLinkBuilder builder = linkTo(methodOn(ControllerWithMethods.class).methodWithPathVariable(null)); + assertThatIllegalArgumentException().isThrownBy(() -> { - linkTo(methodOn(ControllerWithMethods.class).methodWithPathVariable(null))// - .withSelfRel().expand(); + builder.withSelfRel().expand(); }); } @@ -313,10 +314,10 @@ public void rejectsMissingPathVariable() { @Test public void rejectsMissingRequiredRequestParam() { - assertThatIllegalArgumentException().isThrownBy(() -> { - Link link = linkTo(methodOn(ControllerWithMethods.class).methodWithRequestParam(null)).withSelfRel(); + Link link = linkTo(methodOn(ControllerWithMethods.class).methodWithRequestParam(null)).withSelfRel(); - assertThat(link.getVariableNames()).containsExactly("id"); + assertThat(link.getVariableNames()).containsExactly("id"); + assertThatIllegalArgumentException().isThrownBy(() -> { link.expand(); }); @@ -521,7 +522,8 @@ public void addsOptionalRequestParameterTemplateForMissingValue() { Link link = linkTo(methodOn(ControllerWithMethods.class).methodForNextPage("1", null, 5)).withSelfRel(); - assertThat(link.getVariables()).containsExactly(new TemplateVariable("offset", VariableType.REQUEST_PARAM_CONTINUED)); + assertThat(link.getVariables()) + .containsExactly(new TemplateVariable("offset", VariableType.REQUEST_PARAM_CONTINUED)); UriComponents components = toComponents(link);