diff --git a/src/test/java/com/google/gson/TypeAdapterTest.java b/src/test/java/com/google/gson/TypeAdapterTest.java new file mode 100644 index 000000000..07efe5c03 --- /dev/null +++ b/src/test/java/com/google/gson/TypeAdapterTest.java @@ -0,0 +1,32 @@ +package com.google.gson; + +import com.google.gson.stream.JsonReader; +import com.google.gson.stream.JsonWriter; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +public final class TypeAdapterTest { + + @Test + public void testTypeAdapterNullSafe() { + final TypeAdapter unit = typeAdapter; + final TypeAdapter nullSafeUnit1 = unit.nullSafe(); + final TypeAdapter nullSafeUnit2 = unit.nullSafe(); + Assertions.assertNotSame(nullSafeUnit1, nullSafeUnit2); + Assertions.assertSame(nullSafeUnit1, nullSafeUnit2.nullSafe(), () -> String.format("Must pass the test once %s is resolved", "https://github.com/google/gson/issues/2729")); + Assertions.assertSame(nullSafeUnit1.nullSafe(), nullSafeUnit2, () -> String.format("Must pass the test once %s is resolved", "https://github.com/google/gson/issues/2729")); + } + + private static final TypeAdapter typeAdapter = new TypeAdapter<>() { + @Override + public void write(final JsonWriter out, final Object value) { + throw new AssertionError(); + } + + @Override + public Object read(final JsonReader in) { + throw new AssertionError(); + } + }; + +} diff --git a/src/test/java/com/google/gson/package-info.java b/src/test/java/com/google/gson/package-info.java new file mode 100644 index 000000000..d080970a8 --- /dev/null +++ b/src/test/java/com/google/gson/package-info.java @@ -0,0 +1,4 @@ +@Nonnull +package com.google.gson; + +import javax.annotation.Nonnull;