Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test that nulls are correctly serialised #539

Merged
merged 1 commit into from
Dec 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion transactionoutbox-core/pom.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>transactionoutbox-parent</artifactId>
<groupId>com.gruelbox</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -32,9 +29,10 @@ Stream<DynamicNode> 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 =
Expand Down Expand Up @@ -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));
}

Expand All @@ -135,7 +140,6 @@ void testJavaTimeClasses() {
Instant.class,
LocalDate.class,
LocalDateTime.class,
LocalDateTime.class,
MonthDay.class,
Period.class,
Year.class,
Expand All @@ -147,7 +151,6 @@ void testJavaTimeClasses() {
Instant.now(),
LocalDate.now(),
LocalDateTime.now(),
null,
MonthDay.of(1, 1),
Period.ofMonths(1),
Year.now(),
Expand All @@ -157,13 +160,37 @@ 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};
Object[] values = {ExampleCustomEnum.ONE, ExampleCustomEnum.TWO};
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};
Expand All @@ -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));
Expand All @@ -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()));
}
}
Expand All @@ -207,6 +241,7 @@ enum ExampleCustomEnum {
TWO
}

@Getter
static class ExampleCustomClass {

private final String arg1;
Expand All @@ -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 + '\'' + '}';
Expand Down
Loading