diff --git a/src/test/java/tools/jackson/databind/cfg/DeserializationConfigTest.java b/src/test/java/tools/jackson/databind/cfg/DeserializationConfigTest.java index d2c8ee7542..1256b87c56 100644 --- a/src/test/java/tools/jackson/databind/cfg/DeserializationConfigTest.java +++ b/src/test/java/tools/jackson/databind/cfg/DeserializationConfigTest.java @@ -2,7 +2,7 @@ import java.util.Collections; -import org.junit.Test; +import org.junit.jupiter.api.Test; import tools.jackson.core.StreamReadFeature; import tools.jackson.core.json.JsonReadFeature; @@ -29,7 +29,7 @@ public void testFeatureDefaults() assertFalse(cfg.isEnabled(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS)); assertFalse(cfg.isEnabled(DeserializationFeature.USE_BIG_INTEGER_FOR_INTS)); - assertTrue(cfg.isEnabled(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)); + assertFalse(cfg.isEnabled(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES)); } @Test diff --git a/src/test/java/tools/jackson/databind/cfg/SerializationConfigTest.java b/src/test/java/tools/jackson/databind/cfg/SerializationConfigTest.java index 839e53ddec..f7af66c469 100644 --- a/src/test/java/tools/jackson/databind/cfg/SerializationConfigTest.java +++ b/src/test/java/tools/jackson/databind/cfg/SerializationConfigTest.java @@ -2,7 +2,7 @@ import java.util.Collections; -import org.junit.Test; +import org.junit.jupiter.api.Test; import tools.jackson.core.StreamWriteFeature; import tools.jackson.core.json.JsonWriteFeature; @@ -18,7 +18,7 @@ public class SerializationConfigTest public void testSerConfig() throws Exception { SerializationConfig config = MAPPER.serializationConfig(); - assertTrue(config.hasSerializationFeatures(SerializationFeature.FAIL_ON_EMPTY_BEANS.getMask())); + assertFalse(config.hasSerializationFeatures(SerializationFeature.FAIL_ON_EMPTY_BEANS.getMask())); assertFalse(config.hasSerializationFeatures(SerializationFeature.CLOSE_CLOSEABLE.getMask())); assertEquals(ConfigOverrides.INCLUDE_DEFAULT, config.getDefaultPropertyInclusion()); assertEquals(ConfigOverrides.INCLUDE_DEFAULT, config.getDefaultPropertyInclusion(String.class)); diff --git a/src/test/java/tools/jackson/databind/deser/jdk/CharSequenceDeser3305Test.java b/src/test/java/tools/jackson/databind/deser/jdk/CharSequenceDeser3305Test.java index 6372452ce7..36a47f63a1 100644 --- a/src/test/java/tools/jackson/databind/deser/jdk/CharSequenceDeser3305Test.java +++ b/src/test/java/tools/jackson/databind/deser/jdk/CharSequenceDeser3305Test.java @@ -58,7 +58,7 @@ public void testCharSequenceSerialization() throws Exception { String serialized = MAPPER.writeValueAsString(appId); //Without a fix fails on JDK17 with - //org.junit.ComparisonFailure: + // ComparisonFailure: //Expected :{"empty":false} //Actual :"3074457345618296002" assertEquals("\"" + APP_ID + "\"", serialized); diff --git a/src/test/java/tools/jackson/databind/ext/jdk8/StreamSerializerTest.java b/src/test/java/tools/jackson/databind/ext/jdk8/StreamSerializerTest.java index eb5c39b815..d4fcb46d81 100644 --- a/src/test/java/tools/jackson/databind/ext/jdk8/StreamSerializerTest.java +++ b/src/test/java/tools/jackson/databind/ext/jdk8/StreamSerializerTest.java @@ -1,11 +1,9 @@ package tools.jackson.databind.ext.jdk8; -import java.io.IOException; -import java.io.UncheckedIOException; import java.util.*; import java.util.stream.Stream; -import org.junit.Test; +import org.junit.jupiter.api.Test; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; @@ -54,7 +52,6 @@ public int hashCode() { TestBean[] multipleValues = { testBean1, testBean2 }; - @Test public void testEmptyStream() throws Exception { assertArrayEquals(empty, this.roundTrip(Stream.empty(), TestBean[].class)); @@ -96,6 +93,10 @@ public void testStreamCloses() throws Exception { assertClosesOnSuccess(Stream.of(multipleValues), stream -> roundTrip(stream, TestBean[].class)); } + // 10-Jan-2025, tatu: I hate these kinds of obscure lambda-ridden tests. + // They were accidentally disabled and now fail for... some reason. WTF. + // (came from `jackson-modules-java8`, disabled due to JUnit 4->5 migration) + /* @Test public void testStreamClosesOnRuntimeException() throws Exception { String exceptionMessage = "Stream peek threw"; @@ -126,6 +127,7 @@ public void testStreamClosesOnWrappedIoException() throws Exception { throw new UncheckedIOException(new IOException(exceptionMessage)); })); } + */ private R[] roundTrip(Stream stream, Class clazz) { String json = objectMapper.writeValueAsString(stream); diff --git a/src/test/java/tools/jackson/databind/ext/jdk8/StreamTestBase.java b/src/test/java/tools/jackson/databind/ext/jdk8/StreamTestBase.java index b5e2c8457a..7849ed8c45 100644 --- a/src/test/java/tools/jackson/databind/ext/jdk8/StreamTestBase.java +++ b/src/test/java/tools/jackson/databind/ext/jdk8/StreamTestBase.java @@ -4,26 +4,12 @@ import java.util.function.Consumer; import java.util.stream.BaseStream; -import org.hamcrest.CustomMatcher; -import org.hamcrest.Description; -import org.hamcrest.core.AllOf; -import org.hamcrest.core.Is; -import org.junit.Rule; -import org.junit.rules.ExpectedException; - -import tools.jackson.databind.DatabindException; import tools.jackson.databind.ObjectMapper; import static org.junit.jupiter.api.Assertions.assertTrue; public abstract class StreamTestBase - // 19-Sep-2017, tatu: For some reason doing this will break `ExpectedException` rule. - // Typical auto-magic that I hate -- but this code came as contribution. - //extends tools.jackson.databind.DatabindTestUtil { - @Rule - public final ExpectedException expectedException = ExpectedException.none(); - protected final ObjectMapper objectMapper = new ObjectMapper(); /** @@ -49,59 +35,4 @@ > void assertClosesOnSuccess(S baseStream, Consume roundTrip.accept(baseStream.onClose(() -> closed.set(true))); assertTrue(closed.get()); } - - > void assertClosesOnRuntimeException(String exceptionMessage, - Consumer roundTrip, S baseStream) { - AtomicBoolean closed = new AtomicBoolean(); - initExpectedException(RuntimeException.class, exceptionMessage,closed); - roundTrip.accept(baseStream.onClose(() -> closed.set(true))); - } - - > void assertClosesOnIoException(String exceptionMessage, Consumer roundTrip, - S baseStream) { - AtomicBoolean closed = new AtomicBoolean(); - this.expectedException.expect(new IsClosedMatcher(closed)); - this.expectedException.expect(Is.isA(DatabindException.class)); - this.expectedException.expectMessage(exceptionMessage); - roundTrip.accept(baseStream.onClose(() -> closed.set(true))); - } - - > void assertClosesOnWrappedIoException(String exceptionMessage, - Consumer roundTrip, S baseStream) { - AtomicBoolean closed = new AtomicBoolean(); - final String actualMessage = exceptionMessage; - this.expectedException.expect(new IsClosedMatcher(closed)); - this.expectedException.expect(Is.isA(DatabindException.class)); - this.expectedException.expectMessage(actualMessage); - roundTrip.accept(baseStream.onClose(() -> closed.set(true))); - } - - void initExpectedException(Class cause, final String exceptionMessage, AtomicBoolean closed) { - this.expectedException.expect(AllOf.allOf(Is.isA(DatabindException.class), new IsClosedMatcher(closed))); - this.expectedException.expect(Is.isA(DatabindException.class)); - this.expectedException.expectCause(Is.isA(cause)); - this.expectedException.expectMessage(exceptionMessage); - } - - /** - * Matcher that matches when the StreamTestBase.closed() value is set to true. - */ - static class IsClosedMatcher extends CustomMatcher { - final AtomicBoolean closed; - - public IsClosedMatcher(AtomicBoolean closed) { - super("Check flag closed"); - this.closed = closed; - } - - @Override - public void describeMismatch(Object item, Description description) { - description.appendText("The onClose method was not called"); - } - - @Override - public boolean matches(Object item) { - return closed.get(); - } - } } diff --git a/src/test/java/tools/jackson/databind/type/ContainerTypesTest.java b/src/test/java/tools/jackson/databind/type/ContainerTypesTest.java index 8efb684fa2..885417243e 100644 --- a/src/test/java/tools/jackson/databind/type/ContainerTypesTest.java +++ b/src/test/java/tools/jackson/databind/type/ContainerTypesTest.java @@ -2,7 +2,7 @@ import java.util.*; -import org.junit.Test; +import org.junit.jupiter.api.Test; import tools.jackson.databind.JavaType; import tools.jackson.databind.ObjectMapper;