diff --git a/transactionoutbox-core/pom.xml b/transactionoutbox-core/pom.xml index e9258da0..28647bfd 100644 --- a/transactionoutbox-core/pom.xml +++ b/transactionoutbox-core/pom.xml @@ -1,5 +1,6 @@ - + transactionoutbox-parent com.gruelbox diff --git a/transactionoutbox-core/src/test/java/com/gruelbox/transactionoutbox/TestDefaultInvocationSerializer.java b/transactionoutbox-core/src/test/java/com/gruelbox/transactionoutbox/TestDefaultInvocationSerializer.java index 19f3a30a..4a1c9426 100644 --- a/transactionoutbox-core/src/test/java/com/gruelbox/transactionoutbox/TestDefaultInvocationSerializer.java +++ b/transactionoutbox-core/src/test/java/com/gruelbox/transactionoutbox/TestDefaultInvocationSerializer.java @@ -4,12 +4,9 @@ import java.io.StringWriter; import java.time.*; import java.time.temporal.ChronoUnit; -import java.util.Date; -import java.util.Map; -import java.util.Objects; -import java.util.Set; -import java.util.UUID; +import java.util.*; import java.util.stream.Stream; +import lombok.Getter; import lombok.extern.slf4j.Slf4j; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.DynamicNode; @@ -32,9 +29,10 @@ Stream versions() { Stream.of(Arguments.of(1), Arguments.of(2), Arguments.of(new Object[] {null}))); } + @SuppressWarnings("JUnitMalformedDeclaration") static class Inner { - private DefaultInvocationSerializer serializer; + private final DefaultInvocationSerializer serializer; Inner(Integer version) { this.serializer = @@ -121,10 +119,17 @@ void testJavaDateEnums() { check(new Invocation(CLASS_NAME, METHOD_NAME, primitives, values)); } + @Test + void testJavaDateEnumsNulls() { + Class[] primitives = {DayOfWeek.class, Month.class, ChronoUnit.class}; + Object[] values = {null, null, null}; + check(new Invocation(CLASS_NAME, METHOD_NAME, primitives, values)); + } + @Test void testJavaUtilDate() { - Class[] primitives = {Date.class}; - Object[] values = {new Date()}; + Class[] primitives = {Date.class, Date.class}; + Object[] values = {new Date(), null}; check(new Invocation(CLASS_NAME, METHOD_NAME, primitives, values)); } @@ -135,7 +140,6 @@ void testJavaTimeClasses() { Instant.class, LocalDate.class, LocalDateTime.class, - LocalDateTime.class, MonthDay.class, Period.class, Year.class, @@ -147,7 +151,6 @@ void testJavaTimeClasses() { Instant.now(), LocalDate.now(), LocalDateTime.now(), - null, MonthDay.of(1, 1), Period.ofMonths(1), Year.now(), @@ -157,6 +160,23 @@ void testJavaTimeClasses() { check(new Invocation(CLASS_NAME, METHOD_NAME, primitives, values)); } + @Test + void testJavaTimeClassesNulls() { + Class[] primitives = { + Duration.class, + Instant.class, + LocalDate.class, + LocalDateTime.class, + MonthDay.class, + Period.class, + Year.class, + YearMonth.class, + ZonedDateTime.class + }; + Object[] values = new Object[9]; + check(new Invocation(CLASS_NAME, METHOD_NAME, primitives, values)); + } + @Test void testCustomEnum() { Class[] primitives = {ExampleCustomEnum.class, ExampleCustomEnum.class}; @@ -164,6 +184,13 @@ void testCustomEnum() { check(new Invocation(CLASS_NAME, METHOD_NAME, primitives, values)); } + @Test + void testCustomEnumNulls() { + Class[] primitives = {ExampleCustomEnum.class}; + Object[] values = {null}; + check(new Invocation(CLASS_NAME, METHOD_NAME, primitives, values)); + } + @Test void testCustomComplexClass() { Class[] primitives = {ExampleCustomClass.class, ExampleCustomClass.class}; @@ -188,6 +215,13 @@ void testUUID() { check(new Invocation(CLASS_NAME, METHOD_NAME, primitives, values)); } + @Test + void testUUIDNull() { + Class[] primitives = {UUID.class}; + Object[] values = {null}; + check(new Invocation(CLASS_NAME, METHOD_NAME, primitives, values)); + } + void check(Invocation invocation) { Invocation deserialized = serdeser(invocation); Assertions.assertEquals(deserialized, serdeser(invocation)); @@ -197,7 +231,7 @@ void check(Invocation invocation) { Invocation serdeser(Invocation invocation) { var writer = new StringWriter(); serializer.serializeInvocation(invocation, writer); - log.info("Serialised as: {}", writer.toString()); + log.info("Serialised as: {}", writer); return serializer.deserializeInvocation(new StringReader(writer.toString())); } } @@ -207,6 +241,7 @@ enum ExampleCustomEnum { TWO } + @Getter static class ExampleCustomClass { private final String arg1; @@ -217,14 +252,6 @@ static class ExampleCustomClass { this.arg2 = arg2; } - public String getArg1() { - return arg1; - } - - public String getArg2() { - return arg2; - } - @Override public String toString() { return "ExampleCustomClass{" + "arg1='" + arg1 + '\'' + ", arg2='" + arg2 + '\'' + '}';