diff options
| author | Michael Williamson <mike@zwobble.org> | 2026-07-14 18:41:17 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2026-07-14 18:41:17 +0100 |
| commit | 6194d284f5559acc5f23a402f577bac655878f92 (patch) | |
| tree | ad3a47c59e5d8179911cb2bd0b88ecd520af2842 /examples/10-transient-0/output/java-junit | |
| parent | 717cef4b3c757ceefb2a16cdf6c3892cde28b53f (diff) | |
Rename java-junit to java
Diffstat (limited to 'examples/10-transient-0/output/java-junit')
3 files changed, 0 insertions, 188 deletions
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 <T> void assertRoundTripEncoding( - T value, - Encoder<T> encoder, - Decoder<T> 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<T> { - void encode(T value, OutputStream outputStream) throws IOException; - } - - private interface Decoder<T> { - T decode(InputStream inputStream) throws IOException; - } -} |
