From 6194d284f5559acc5f23a402f577bac655878f92 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Tue, 14 Jul 2026 18:41:17 +0100 Subject: Rename java-junit to java --- examples/10-transient-0/hobgoblin.json5 | 4 +- .../10-transient-0/output/java-junit/.gitignore | 2 - examples/10-transient-0/output/java-junit/pom.xml | 1 - .../java/org/zwobble/example/Transient0Tests.java | 185 --------------------- examples/10-transient-0/output/java/.gitignore | 2 + examples/10-transient-0/output/java/pom.xml | 1 + .../java/org/zwobble/example/Transient0Tests.java | 185 +++++++++++++++++++++ 7 files changed, 190 insertions(+), 190 deletions(-) delete mode 100644 examples/10-transient-0/output/java-junit/.gitignore delete mode 120000 examples/10-transient-0/output/java-junit/pom.xml delete mode 100644 examples/10-transient-0/output/java-junit/src/test/java/org/zwobble/example/Transient0Tests.java create mode 100644 examples/10-transient-0/output/java/.gitignore create mode 120000 examples/10-transient-0/output/java/pom.xml create mode 100644 examples/10-transient-0/output/java/src/test/java/org/zwobble/example/Transient0Tests.java (limited to 'examples/10-transient-0') diff --git a/examples/10-transient-0/hobgoblin.json5 b/examples/10-transient-0/hobgoblin.json5 index ee08699..f3e455d 100644 --- a/examples/10-transient-0/hobgoblin.json5 +++ b/examples/10-transient-0/hobgoblin.json5 @@ -8,11 +8,11 @@ generators: [ { generator: "java-types", - path: "output/java-junit/src/gen/java", + path: "output/java/src/gen/java", }, { generator: "java-transient-0", - path: "output/java-junit/src/gen/java", + path: "output/java/src/gen/java", }, ], } diff --git a/examples/10-transient-0/output/java-junit/.gitignore b/examples/10-transient-0/output/java-junit/.gitignore deleted file mode 100644 index ff511d4..0000000 --- a/examples/10-transient-0/output/java-junit/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -/src/gen/ -/target/ diff --git a/examples/10-transient-0/output/java-junit/pom.xml b/examples/10-transient-0/output/java-junit/pom.xml deleted file mode 120000 index 445fa65..0000000 --- a/examples/10-transient-0/output/java-junit/pom.xml +++ /dev/null @@ -1 +0,0 @@ -../../../templates/java-junit/pom.xml \ No newline at end of file diff --git a/examples/10-transient-0/output/java-junit/src/test/java/org/zwobble/example/Transient0Tests.java b/examples/10-transient-0/output/java-junit/src/test/java/org/zwobble/example/Transient0Tests.java deleted file mode 100644 index e28e926..0000000 --- a/examples/10-transient-0/output/java-junit/src/test/java/org/zwobble/example/Transient0Tests.java +++ /dev/null @@ -1,185 +0,0 @@ -package org.zwobble.example; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.util.List; -import java.util.Optional; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; -import org.zwobble.example.types.data.EnumWithVariants; -import org.zwobble.example.types.data.HobgoblinTransient0Data; -import org.zwobble.example.types.data.InnerStruct; -import org.zwobble.example.types.data.OuterStruct; -import org.zwobble.example.types.data.StructWithBool; -import org.zwobble.example.types.data.StructWithInt32; -import org.zwobble.example.types.data.StructWithInt64; -import org.zwobble.example.types.data.StructWithList; -import org.zwobble.example.types.data.StructWithOption; -import org.zwobble.example.types.data.StructWithString; -import org.zwobble.example.types.data.VariantOne; -import org.zwobble.example.types.data.VariantTwo; - -public class Transient0Tests { - @Test - public void structWithBool() throws IOException { - var value = new StructWithBool(true, false); - - assertRoundTripEncoding( - value, - HobgoblinTransient0Data::encodeStructWithBool, - HobgoblinTransient0Data::decodeStructWithBool - ); - } - - @Test - public void structWithInt32() throws IOException { - var value = new StructWithInt32(10, 25); - - assertRoundTripEncoding( - value, - HobgoblinTransient0Data::encodeStructWithInt32, - HobgoblinTransient0Data::decodeStructWithInt32 - ); - } - - @Test - public void structWithInt64() throws IOException { - var value = new StructWithInt64(10, 25); - - assertRoundTripEncoding( - value, - HobgoblinTransient0Data::encodeStructWithInt64, - HobgoblinTransient0Data::decodeStructWithInt64 - ); - } - - @Test - public void structWithString() throws IOException { - var value = new StructWithString("abc", "def"); - - assertRoundTripEncoding( - value, - HobgoblinTransient0Data::encodeStructWithString, - HobgoblinTransient0Data::decodeStructWithString - ); - } - - @Test - public void nestedStruct() throws IOException { - var value = new OuterStruct(new InnerStruct(10, 25), 42); - - assertRoundTripEncoding( - value, - HobgoblinTransient0Data::encodeOuterStruct, - HobgoblinTransient0Data::decodeOuterStruct - ); - } - - @Test - public void structWithList() throws IOException { - var value = new StructWithList( - List.of(10L, 25L), - List.of( - new InnerStruct(42, 47), - new InnerStruct(52, 57), - new InnerStruct(62, 67) - ) - ); - - assertRoundTripEncoding( - value, - HobgoblinTransient0Data::encodeStructWithList, - HobgoblinTransient0Data::decodeStructWithList - ); - } - - @Test - public void structWithOptionNone() throws IOException { - var value = new StructWithOption( - Optional.empty(), - Optional.empty() - ); - - assertRoundTripEncoding( - value, - HobgoblinTransient0Data::encodeStructWithOption, - HobgoblinTransient0Data::decodeStructWithOption - ); - } - - @Test - public void structWithOptionSome() throws IOException { - var value = new StructWithOption( - Optional.of(10L), - Optional.of(new InnerStruct(42, 47)) - ); - - assertRoundTripEncoding( - value, - HobgoblinTransient0Data::encodeStructWithOption, - HobgoblinTransient0Data::decodeStructWithOption - ); - } - - @Test - public void enumWithVariants() throws IOException { - assertRoundTripEncoding( - EnumWithVariants.ZERO, - HobgoblinTransient0Data::encodeEnumWithVariants, - HobgoblinTransient0Data::decodeEnumWithVariants - ); - - assertRoundTripEncoding( - EnumWithVariants.ONE, - HobgoblinTransient0Data::encodeEnumWithVariants, - HobgoblinTransient0Data::decodeEnumWithVariants - ); - - assertRoundTripEncoding( - EnumWithVariants.TWO, - HobgoblinTransient0Data::encodeEnumWithVariants, - HobgoblinTransient0Data::decodeEnumWithVariants - ); - } - - @Test - public void sumWithVariants() throws IOException { - assertRoundTripEncoding( - new VariantOne(10), - HobgoblinTransient0Data::encodeSumWithVariants, - HobgoblinTransient0Data::decodeSumWithVariants - ); - - assertRoundTripEncoding( - new VariantTwo(25), - HobgoblinTransient0Data::encodeSumWithVariants, - HobgoblinTransient0Data::decodeSumWithVariants - ); - } - - private void assertRoundTripEncoding( - T value, - Encoder encoder, - Decoder decoder - ) throws IOException { - var outputStream = new ByteArrayOutputStream(); - encoder.encode(value, outputStream); - var bytes = outputStream.toByteArray(); - - var inputStream = new ByteArrayInputStream(bytes); - var decodedValue = decoder.decode(inputStream); - - Assertions.assertEquals(value, decodedValue); - } - - private interface Encoder { - void encode(T value, OutputStream outputStream) throws IOException; - } - - private interface Decoder { - T decode(InputStream inputStream) throws IOException; - } -} diff --git a/examples/10-transient-0/output/java/.gitignore b/examples/10-transient-0/output/java/.gitignore new file mode 100644 index 0000000..ff511d4 --- /dev/null +++ b/examples/10-transient-0/output/java/.gitignore @@ -0,0 +1,2 @@ +/src/gen/ +/target/ diff --git a/examples/10-transient-0/output/java/pom.xml b/examples/10-transient-0/output/java/pom.xml new file mode 120000 index 0000000..445fa65 --- /dev/null +++ b/examples/10-transient-0/output/java/pom.xml @@ -0,0 +1 @@ +../../../templates/java-junit/pom.xml \ No newline at end of file diff --git a/examples/10-transient-0/output/java/src/test/java/org/zwobble/example/Transient0Tests.java b/examples/10-transient-0/output/java/src/test/java/org/zwobble/example/Transient0Tests.java new file mode 100644 index 0000000..e28e926 --- /dev/null +++ b/examples/10-transient-0/output/java/src/test/java/org/zwobble/example/Transient0Tests.java @@ -0,0 +1,185 @@ +package org.zwobble.example; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.util.List; +import java.util.Optional; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.zwobble.example.types.data.EnumWithVariants; +import org.zwobble.example.types.data.HobgoblinTransient0Data; +import org.zwobble.example.types.data.InnerStruct; +import org.zwobble.example.types.data.OuterStruct; +import org.zwobble.example.types.data.StructWithBool; +import org.zwobble.example.types.data.StructWithInt32; +import org.zwobble.example.types.data.StructWithInt64; +import org.zwobble.example.types.data.StructWithList; +import org.zwobble.example.types.data.StructWithOption; +import org.zwobble.example.types.data.StructWithString; +import org.zwobble.example.types.data.VariantOne; +import org.zwobble.example.types.data.VariantTwo; + +public class Transient0Tests { + @Test + public void structWithBool() throws IOException { + var value = new StructWithBool(true, false); + + assertRoundTripEncoding( + value, + HobgoblinTransient0Data::encodeStructWithBool, + HobgoblinTransient0Data::decodeStructWithBool + ); + } + + @Test + public void structWithInt32() throws IOException { + var value = new StructWithInt32(10, 25); + + assertRoundTripEncoding( + value, + HobgoblinTransient0Data::encodeStructWithInt32, + HobgoblinTransient0Data::decodeStructWithInt32 + ); + } + + @Test + public void structWithInt64() throws IOException { + var value = new StructWithInt64(10, 25); + + assertRoundTripEncoding( + value, + HobgoblinTransient0Data::encodeStructWithInt64, + HobgoblinTransient0Data::decodeStructWithInt64 + ); + } + + @Test + public void structWithString() throws IOException { + var value = new StructWithString("abc", "def"); + + assertRoundTripEncoding( + value, + HobgoblinTransient0Data::encodeStructWithString, + HobgoblinTransient0Data::decodeStructWithString + ); + } + + @Test + public void nestedStruct() throws IOException { + var value = new OuterStruct(new InnerStruct(10, 25), 42); + + assertRoundTripEncoding( + value, + HobgoblinTransient0Data::encodeOuterStruct, + HobgoblinTransient0Data::decodeOuterStruct + ); + } + + @Test + public void structWithList() throws IOException { + var value = new StructWithList( + List.of(10L, 25L), + List.of( + new InnerStruct(42, 47), + new InnerStruct(52, 57), + new InnerStruct(62, 67) + ) + ); + + assertRoundTripEncoding( + value, + HobgoblinTransient0Data::encodeStructWithList, + HobgoblinTransient0Data::decodeStructWithList + ); + } + + @Test + public void structWithOptionNone() throws IOException { + var value = new StructWithOption( + Optional.empty(), + Optional.empty() + ); + + assertRoundTripEncoding( + value, + HobgoblinTransient0Data::encodeStructWithOption, + HobgoblinTransient0Data::decodeStructWithOption + ); + } + + @Test + public void structWithOptionSome() throws IOException { + var value = new StructWithOption( + Optional.of(10L), + Optional.of(new InnerStruct(42, 47)) + ); + + assertRoundTripEncoding( + value, + HobgoblinTransient0Data::encodeStructWithOption, + HobgoblinTransient0Data::decodeStructWithOption + ); + } + + @Test + public void enumWithVariants() throws IOException { + assertRoundTripEncoding( + EnumWithVariants.ZERO, + HobgoblinTransient0Data::encodeEnumWithVariants, + HobgoblinTransient0Data::decodeEnumWithVariants + ); + + assertRoundTripEncoding( + EnumWithVariants.ONE, + HobgoblinTransient0Data::encodeEnumWithVariants, + HobgoblinTransient0Data::decodeEnumWithVariants + ); + + assertRoundTripEncoding( + EnumWithVariants.TWO, + HobgoblinTransient0Data::encodeEnumWithVariants, + HobgoblinTransient0Data::decodeEnumWithVariants + ); + } + + @Test + public void sumWithVariants() throws IOException { + assertRoundTripEncoding( + new VariantOne(10), + HobgoblinTransient0Data::encodeSumWithVariants, + HobgoblinTransient0Data::decodeSumWithVariants + ); + + assertRoundTripEncoding( + new VariantTwo(25), + HobgoblinTransient0Data::encodeSumWithVariants, + HobgoblinTransient0Data::decodeSumWithVariants + ); + } + + private void assertRoundTripEncoding( + T value, + Encoder encoder, + Decoder decoder + ) throws IOException { + var outputStream = new ByteArrayOutputStream(); + encoder.encode(value, outputStream); + var bytes = outputStream.toByteArray(); + + var inputStream = new ByteArrayInputStream(bytes); + var decodedValue = decoder.decode(inputStream); + + Assertions.assertEquals(value, decodedValue); + } + + private interface Encoder { + void encode(T value, OutputStream outputStream) throws IOException; + } + + private interface Decoder { + T decode(InputStream inputStream) throws IOException; + } +} -- cgit v1.2.3