From c9de80db7e3df82aa82fd3029dfa797546f0bce8 Mon Sep 17 00:00:00 2001 From: Oliver Drotbohm Date: Wed, 14 Aug 2024 14:12:33 +0200 Subject: [PATCH] GH-2209 - Upgrade to JUnit 5.11. --- pom.xml | 2 +- .../hateoas/CollectionModelUnitTest.java | 10 +++++--- .../hateoas/UriTemplateUnitTest.java | 25 +++++++++++-------- .../html/HtmlInputTypeUnitTests.java | 10 +++++--- 4 files changed, 27 insertions(+), 20 deletions(-) diff --git a/pom.xml b/pom.xml index f3f6983e..7e1b35e0 100644 --- a/pom.xml +++ b/pom.xml @@ -79,7 +79,7 @@ 2.17.2 spring.hateoas 2.9.0 - 5.10.3 + 5.11.0 1.18.34 2024.0.0-M5 2.0.16 diff --git a/src/test/java/org/springframework/hateoas/CollectionModelUnitTest.java b/src/test/java/org/springframework/hateoas/CollectionModelUnitTest.java index e7baf083..27aadc0d 100755 --- a/src/test/java/org/springframework/hateoas/CollectionModelUnitTest.java +++ b/src/test/java/org/springframework/hateoas/CollectionModelUnitTest.java @@ -25,6 +25,7 @@ import java.util.Set; import java.util.stream.Stream; import org.junit.jupiter.api.DynamicTest; +import org.junit.jupiter.api.NamedExecutable; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestFactory; import org.springframework.lang.Nullable; @@ -79,11 +80,11 @@ class CollectionModelUnitTest { @TestFactory // #1590 Stream exposesElementTypeForCollection() { - return DynamicTest.stream(Fixture.probes(), Fixture::toString, Fixture::verify); + return DynamicTest.stream(Fixture.probes()); } @Value(staticConstructor = "$") - static class Fixture { + static class Fixture implements NamedExecutable { CollectionModel model; @Nullable Class expectedElementType; @@ -98,12 +99,13 @@ class CollectionModelUnitTest { Contact.class)); } - void verify() { + @Override + public void execute() throws Throwable { assertThat(model.getResolvableType().getGeneric(0).resolve()).isEqualTo(expectedElementType); } @Override - public String toString() { + public String getName() { return String.format("Expect element type %s for collection model %s.", expectedElementType, model); } } diff --git a/src/test/java/org/springframework/hateoas/UriTemplateUnitTest.java b/src/test/java/org/springframework/hateoas/UriTemplateUnitTest.java index 8e53fd87..53ea879f 100755 --- a/src/test/java/org/springframework/hateoas/UriTemplateUnitTest.java +++ b/src/test/java/org/springframework/hateoas/UriTemplateUnitTest.java @@ -37,6 +37,7 @@ import java.util.stream.Stream; import org.apache.commons.io.output.ByteArrayOutputStream; import org.junit.jupiter.api.DynamicTest; +import org.junit.jupiter.api.NamedExecutable; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestFactory; import org.springframework.hateoas.TemplateVariable.VariableType; @@ -228,7 +229,7 @@ class UriTemplateUnitTest { put("state", "TN"); } }) // - .verify(); + .execute(); } @Test // #483 @@ -237,7 +238,7 @@ class UriTemplateUnitTest { of("/foo{?bar,foobar*}", "/foo?bar=barExpanded&foobar=foo1&foobar=foo2") // .param("bar", "barExpanded") // .param("foobar", Arrays.asList("foo1", "foo2")) // - .verify(); + .execute(); } @Test // #483 @@ -246,7 +247,7 @@ class UriTemplateUnitTest { of("/foo{?bar,foobar*}", "/foo?bar=barExpanded&foobar=singleValue") // .param("bar", "barExpanded") // .param("foobar", "singleValue") // - .verify(); + .execute(); } @Test // #1127 @@ -254,15 +255,15 @@ class UriTemplateUnitTest { of("https://example.org/foo and bar/{baz}", "https://example.org/foo%20and%20bar/xyzzy") // .param("baz", "xyzzy") // - .verify(); + .execute(); - of("/foo?foo=bar{&baz}", "/foo?foo=bar&baz=xyz").param("baz", "xyz").verify(); - of("?foo=bar{&baz}", "?foo=bar&baz=xyz").param("baz", "xyz").verify(); + of("/foo?foo=bar{&baz}", "/foo?foo=bar&baz=xyz").param("baz", "xyz").execute(); + of("?foo=bar{&baz}", "?foo=bar&baz=xyz").param("baz", "xyz").execute(); } @TestFactory // #593 public Stream uriTemplateExpansionsShouldWork() { - return DynamicTest.stream(getEncodingFixtures(), EncodingFixture::toString, EncodingFixture::verify); + return DynamicTest.stream(getEncodingFixtures()); } @Test // #593 @@ -420,7 +421,7 @@ class UriTemplateUnitTest { @TestFactory Stream rfcExamples() { - return DynamicTest.stream(foo(), EncodingFixture::toShortString, EncodingFixture::verify); + return DynamicTest.stream(foo()); } private static Stream foo() { @@ -622,7 +623,7 @@ class UriTemplateUnitTest { of("/foo/b%22ar{?x}", "/foo/b%22ar?x=1").param("x", 1)); } - static class EncodingFixture { + static class EncodingFixture implements NamedExecutable { private final String template; private final URI uri; @@ -657,7 +658,8 @@ class UriTemplateUnitTest { return new EncodingFixture(template, uri, parameters, false); } - public void verify() { + @Override + public void execute() { UriTemplate uriTemplate = UriTemplate.of(template); @@ -668,7 +670,8 @@ class UriTemplateUnitTest { } } - public String toShortString() { + @Override + public String getName() { return String.format("Expanding %s to %s", template, uri); } diff --git a/src/test/java/org/springframework/hateoas/mediatype/html/HtmlInputTypeUnitTests.java b/src/test/java/org/springframework/hateoas/mediatype/html/HtmlInputTypeUnitTests.java index a8a03b95..30fe558f 100644 --- a/src/test/java/org/springframework/hateoas/mediatype/html/HtmlInputTypeUnitTests.java +++ b/src/test/java/org/springframework/hateoas/mediatype/html/HtmlInputTypeUnitTests.java @@ -27,6 +27,7 @@ import java.time.LocalTime; import java.util.stream.Stream; import org.junit.jupiter.api.DynamicTest; +import org.junit.jupiter.api.NamedExecutable; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestFactory; @@ -60,21 +61,22 @@ public class HtmlInputTypeUnitTests { $.of(URI.class, HtmlInputType.URL) // ); - return DynamicTest.stream(Stream.concat(numbers, others), $::toString, $::verify); + return DynamicTest.stream(Stream.concat(numbers, others)); } @Value(staticConstructor = "of") - static class $ { + static class $ implements NamedExecutable { Class type; HtmlInputType expected; - public void verify() { + @Override + public void execute() throws Throwable { assertThat(HtmlInputType.from(type)).isEqualTo(expected); } @Override - public String toString() { + public String getName() { return String.format("Derives %s from %s.", expected, type); } }