From 5ae89bcb2ca869fc527ed485ea5513ffa5a2124c Mon Sep 17 00:00:00 2001 From: Oliver Drotbohm Date: Thu, 28 Nov 2019 15:01:16 +0100 Subject: [PATCH] #593 - Polishing. Refactored existing unit tests to use the newly introduced test fixture type. Refactored ticket references to use the current style. --- .../hateoas/UriTemplateUnitTest.java | 175 ++++-------------- 1 file changed, 39 insertions(+), 136 deletions(-) diff --git a/src/test/java/org/springframework/hateoas/UriTemplateUnitTest.java b/src/test/java/org/springframework/hateoas/UriTemplateUnitTest.java index 15cd1b907..df5914ac2 100755 --- a/src/test/java/org/springframework/hateoas/UriTemplateUnitTest.java +++ b/src/test/java/org/springframework/hateoas/UriTemplateUnitTest.java @@ -48,10 +48,8 @@ */ class UriTemplateUnitTest { - /** - * @see #137 - */ - @Test + @Test // #137 + @SuppressWarnings("null") void discoversTemplate() { assertThat(UriTemplate.isTemplate("/foo{?bar}")).isTrue(); @@ -60,10 +58,7 @@ void discoversTemplate() { assertThat(UriTemplate.isTemplate("")).isFalse(); } - /** - * @see #137 - */ - @Test + @Test // #137 void discoversRequestParam() { UriTemplate template = UriTemplate.of("/foo{?bar}"); @@ -71,10 +66,7 @@ void discoversRequestParam() { assertVariables(template, new TemplateVariable("bar", VariableType.REQUEST_PARAM)); } - /** - * @see #137 - */ - @Test + @Test // #137 void discoversRequestParamCntinued() { UriTemplate template = UriTemplate.of("/foo?bar{&foobar}"); @@ -82,10 +74,7 @@ void discoversRequestParamCntinued() { assertVariables(template, new TemplateVariable("foobar", VariableType.REQUEST_PARAM_CONTINUED)); } - /** - * @see #137 - */ - @Test + @Test // #137 void discoversOptionalPathVariable() { UriTemplate template = UriTemplate.of("/foo{/bar}"); @@ -93,10 +82,7 @@ void discoversOptionalPathVariable() { assertVariables(template, new TemplateVariable("bar", VariableType.SEGMENT)); } - /** - * @see #137 - */ - @Test + @Test // #137 void discoversPathVariable() { UriTemplate template = UriTemplate.of("/foo/{bar}"); @@ -104,10 +90,7 @@ void discoversPathVariable() { assertVariables(template, new TemplateVariable("bar", VariableType.PATH_VARIABLE)); } - /** - * @see #137 - */ - @Test + @Test // #137 void discoversFragment() { UriTemplate template = UriTemplate.of("/foo{#bar}"); @@ -115,10 +98,7 @@ void discoversFragment() { assertVariables(template, new TemplateVariable("bar", VariableType.FRAGMENT)); } - /** - * @see #137 - */ - @Test + @Test // #137 void discoversMultipleRequestParam() { UriTemplate template = UriTemplate.of("/foo{?bar,foobar}"); @@ -127,10 +107,7 @@ void discoversMultipleRequestParam() { new TemplateVariable("foobar", VariableType.REQUEST_PARAM)); } - /** - * @see #137 - */ - @Test + @Test // #137 void expandsRequestParameter() { UriTemplate template = UriTemplate.of("/foo{?bar}"); @@ -139,10 +116,7 @@ void expandsRequestParameter() { assertThat(uri.toString()).isEqualTo("/foo?bar=myBar"); } - /** - * @see #137 - */ - @Test + @Test // #137 void expandsMultipleRequestParameters() { Map parameters = new HashMap<>(); @@ -155,10 +129,7 @@ void expandsMultipleRequestParameters() { assertThat(uri.toString()).isEqualTo("/foo?bar=myBar&fooBar=myFooBar"); } - /** - * @see #137 - */ - @Test + @Test // #137 void rejectsMissingRequiredPathVariable() { UriTemplate template = UriTemplate.of("/foo/{bar}"); @@ -168,10 +139,7 @@ void rejectsMissingRequiredPathVariable() { }); } - /** - * @see #137 - */ - @Test + @Test // #137 void expandsMultipleVariablesViaArray() { UriTemplate template = UriTemplate.of("/foo{/bar}{?firstname,lastname}{#anchor}"); @@ -179,37 +147,25 @@ void expandsMultipleVariablesViaArray() { assertThat(uri.toString()).isEqualTo("/foo/path?firstname=Dave&lastname=Matthews#discography"); } - /** - * @see #137 - */ - @Test + @Test // #137 void expandsTemplateWithoutVariablesCorrectly() { assertThat(UriTemplate.of("/foo").expand().toString()).isEqualTo("/foo"); } - /** - * @see #137 - */ - @Test + @Test // #137 void correctlyExpandsFullUri() { assertThat(UriTemplate.of("http://localhost:8080/foo{?bar}").expand().toString()) .isEqualTo("http://localhost:8080/foo"); } - /** - * @see #137 - */ - @Test + @Test // #137 void rendersUriTempalteWithPathVariable() { UriTemplate template = UriTemplate.of("/{foo}/bar{?page}"); assertThat(template.toString()).isEqualTo("/{foo}/bar{?page}"); } - /** - * #@see 137 - */ - @Test + @Test // #137 void addsTemplateVariables() { UriTemplate source = UriTemplate.of("/{foo}/bar{?page}"); @@ -222,10 +178,7 @@ void addsTemplateVariables() { assertVariables(source.with(new TemplateVariables(toAdd)), expected); } - /** - * @see #217 - */ - @Test + @Test // #217 void doesNotAddVariablesForAlreadyExistingRequestParameters() { UriTemplate template = UriTemplate.of("/?page=2"); @@ -236,10 +189,7 @@ void doesNotAddVariablesForAlreadyExistingRequestParameters() { assertThat(result.getVariableNames()).isEmpty(); } - /** - * @see #217 - */ - @Test + @Test // #217 void doesNotAddVariablesForAlreadyExistingFragment() { UriTemplate template = UriTemplate.of("/#fragment"); @@ -247,31 +197,16 @@ void doesNotAddVariablesForAlreadyExistingFragment() { assertThat(result.getVariableNames()).isEmpty(); } - /** - * @see #271 - */ - @Test - void expandASimplePathVariable() { - - UriTemplate template = UriTemplate.of("/foo/{id}"); - assertThat(template.expand(2).toString()).isEqualTo("/foo/2"); - } - - /** - * @see #273 - */ - @Test + @Test // #273 + @SuppressWarnings("null") void rejectsEmptyBaseUri() { assertThatIllegalArgumentException().isThrownBy(() -> { - new UriTemplate(null, TemplateVariables.NONE); + UriTemplate.of(null, TemplateVariables.NONE); }); } - /** - * @see #281 - */ - @Test + @Test // #281 void allowsAddingTemplateVariable() { UriTemplate template = UriTemplate.of("/").with("q", VariableType.REQUEST_PARAM); @@ -279,10 +214,7 @@ void allowsAddingTemplateVariable() { assertThat(template.toString()).isEqualTo("/{?q}"); } - /** - * @see #483 - */ - @Test + @Test // #483 void compositveValuesAreRecognisedAsVariableType() { UriTemplate template = UriTemplate.of("/foo{&bar,foobar*}"); @@ -291,66 +223,37 @@ void compositveValuesAreRecognisedAsVariableType() { new TemplateVariable("foobar", VariableType.COMPOSITE_PARAM)); } - /** - * @see #483 - */ - @Test + @Test // #483 @SuppressWarnings("serial") void expandsCompositeValueAsAssociativeArray() { - UriTemplate template = UriTemplate.of("/foo{&bar,foobar*}"); - - String expandedTemplate = template.expand(new HashMap() { - { - put("bar", "barExpanded"); - put("foobar", new HashMap() { + of("/foo{&bar,foobar*}", "/foo?bar=barExpanded&city=Clarksville&state=TN") // + .param("bar", "barExpanded") // + .param("foobar", new HashMap() { { put("city", "Clarksville"); put("state", "TN"); } - }); - } - }).toString(); - - assertThat(expandedTemplate).isEqualTo("/foo?bar=barExpanded&city=Clarksville&state=TN"); + }) // + .verify(); } - /** - * @see #483 - */ - @Test - @SuppressWarnings("serial") + @Test // #483 void expandsCompositeValueAsList() { - UriTemplate template = UriTemplate.of("/foo{&bar,foobar*}"); - - String expandedTemplate = template.expand(new HashMap() { - { - put("bar", "barExpanded"); - put("foobar", Arrays.asList("foo1", "foo2")); - } - }).toString(); - - assertThat(expandedTemplate).isEqualTo("/foo?bar=barExpanded&foobar=foo1&foobar=foo2"); + of("/foo{&bar,foobar*}", "/foo?bar=barExpanded&foobar=foo1&foobar=foo2") // + .param("bar", "barExpanded") // + .param("foobar", Arrays.asList("foo1", "foo2")) // + .verify(); } - /** - * @see #483 - */ - @Test - @SuppressWarnings("serial") + @Test // #483 void handlesCompositeValueAsSingleValue() { - UriTemplate template = UriTemplate.of("/foo{&bar,foobar*}"); - - String expandedTemplate = template.expand(new HashMap() { - { - put("bar", "barExpanded"); - put("foobar", "singleValue"); - } - }).toString(); - - assertThat(expandedTemplate).isEqualTo("/foo?bar=barExpanded&foobar=singleValue"); + of("/foo{&bar,foobar*}", "/foo?bar=barExpanded&foobar=singleValue") // + .param("bar", "barExpanded") // + .param("foobar", "singleValue") // + .verify(); } @Test // #1127