summaryrefslogtreecommitdiff
path: root/examples/13-transient-0/output/java
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2026-08-01 09:17:30 +0100
committerMichael Williamson <mike@zwobble.org>2026-08-01 09:17:30 +0100
commit4524a8a16574887bfdb0ee66984709c8158470a6 (patch)
treec7a171667fa76851d7e61e7f2ead607fb0823a6f /examples/13-transient-0/output/java
parentb433dc94a228a89977da9ee6a4739e2f1da69d66 (diff)
Add Box type
Diffstat (limited to 'examples/13-transient-0/output/java')
-rw-r--r--examples/13-transient-0/output/java/.gitignore3
l---------examples/13-transient-0/output/java/pom.xml1
-rw-r--r--examples/13-transient-0/output/java/src/test/java/org/zwobble/example/Transient0Tests.java338
3 files changed, 0 insertions, 342 deletions
diff --git a/examples/13-transient-0/output/java/.gitignore b/examples/13-transient-0/output/java/.gitignore
deleted file mode 100644
index 2fcf0b8..0000000
--- a/examples/13-transient-0/output/java/.gitignore
+++ /dev/null
@@ -1,3 +0,0 @@
-/src/gen/
-/target/
-/transient-0/
diff --git a/examples/13-transient-0/output/java/pom.xml b/examples/13-transient-0/output/java/pom.xml
deleted file mode 120000
index 445fa65..0000000
--- a/examples/13-transient-0/output/java/pom.xml
+++ /dev/null
@@ -1 +0,0 @@
-../../../templates/java-junit/pom.xml \ No newline at end of file
diff --git a/examples/13-transient-0/output/java/src/test/java/org/zwobble/example/Transient0Tests.java b/examples/13-transient-0/output/java/src/test/java/org/zwobble/example/Transient0Tests.java
deleted file mode 100644
index 8161920..0000000
--- a/examples/13-transient-0/output/java/src/test/java/org/zwobble/example/Transient0Tests.java
+++ /dev/null
@@ -1,338 +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.nio.file.Files;
-import java.nio.file.Path;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-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.StructSingleton;
-import org.zwobble.example.types.data.StructWithBool;
-import org.zwobble.example.types.data.StructWithDifferentSharedTypes;
-import org.zwobble.example.types.data.StructWithEnum;
-import org.zwobble.example.types.data.StructWithInt8;
-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.StructWithListOfShared;
-import org.zwobble.example.types.data.StructWithOption;
-import org.zwobble.example.types.data.StructWithSharedSumAndVariant;
-import org.zwobble.example.types.data.StructWithString;
-import org.zwobble.example.types.data.StructWithStruct;
-import org.zwobble.example.types.data.StructWithSum;
-import org.zwobble.example.types.data.VariantOne;
-import org.zwobble.example.types.data.VariantTwo;
-import org.zwobble.example.types.data.transient0.HobgoblinTransient0Data;
-import org.zwobble.example.types.transient0.HobgoblinTransient0TaggedSharedValue;
-
-public class Transient0Tests {
- @Test
- public void structSingleton() throws IOException {
- var value = StructSingleton.INSTANCE;
-
- assertRoundTripEncoding(
- "StructSingleton",
- value,
- HobgoblinTransient0Data::encodeStructSingleton,
- HobgoblinTransient0Data::decodeStructSingleton
- );
- }
-
- @Test
- public void structWithBool() throws IOException {
- var value = new StructWithBool(true, false);
-
- assertRoundTripEncoding(
- "StructWithBool",
- value,
- HobgoblinTransient0Data::encodeStructWithBool,
- HobgoblinTransient0Data::decodeStructWithBool
- );
- }
-
- @Test
- public void structWithInt8() throws IOException {
- var value = new StructWithInt8((byte)10, (byte)25);
-
- assertRoundTripEncoding(
- "StructWithInt8",
- value,
- HobgoblinTransient0Data::encodeStructWithInt8,
- HobgoblinTransient0Data::decodeStructWithInt8
- );
- }
-
- @Test
- public void structWithInt32() throws IOException {
- var value = new StructWithInt32(10, 25);
-
- assertRoundTripEncoding(
- "StructWithInt32",
- value,
- HobgoblinTransient0Data::encodeStructWithInt32,
- HobgoblinTransient0Data::decodeStructWithInt32
- );
- }
-
- @Test
- public void structWithInt64() throws IOException {
- var value = new StructWithInt64(10, 25);
-
- assertRoundTripEncoding(
- "StructWithInt64",
- value,
- HobgoblinTransient0Data::encodeStructWithInt64,
- HobgoblinTransient0Data::decodeStructWithInt64
- );
- }
-
- @Test
- public void structWithString() throws IOException {
- var value = new StructWithString("abc", "def");
-
- assertRoundTripEncoding(
- "StructWithString",
- value,
- HobgoblinTransient0Data::encodeStructWithString,
- HobgoblinTransient0Data::decodeStructWithString
- );
- }
-
- @Test
- public void structWithStruct() throws IOException {
- var value = new StructWithStruct(new StructWithInt32(10, 25), 42);
-
- assertRoundTripEncoding(
- "StructWithStruct",
- value,
- HobgoblinTransient0Data::encodeStructWithStruct,
- HobgoblinTransient0Data::decodeStructWithStruct
- );
- }
-
- @Test
- public void structWithList() throws IOException {
- var value = new StructWithList(
- List.of(10L, 25L),
- List.of(
- new StructWithInt32(42, 47),
- new StructWithInt32(52, 57),
- new StructWithInt32(62, 67)
- )
- );
-
- assertRoundTripEncoding(
- "StructWithList",
- value,
- HobgoblinTransient0Data::encodeStructWithList,
- HobgoblinTransient0Data::decodeStructWithList
- );
- }
-
- @Test
- public void structWithOptionNone() throws IOException {
- var value = new StructWithOption(
- Optional.empty(),
- Optional.empty()
- );
-
- assertRoundTripEncoding(
- "StructWithOption_None",
- value,
- HobgoblinTransient0Data::encodeStructWithOption,
- HobgoblinTransient0Data::decodeStructWithOption
- );
- }
-
- @Test
- public void structWithOptionSome() throws IOException {
- var value = new StructWithOption(
- Optional.of(10L),
- Optional.of(new StructWithInt32(42, 47))
- );
-
- assertRoundTripEncoding(
- "StructWithOption_Some",
- value,
- HobgoblinTransient0Data::encodeStructWithOption,
- HobgoblinTransient0Data::decodeStructWithOption
- );
- }
-
- @Test
- public void enumWithVariants() throws IOException {
- assertRoundTripEncoding(
- "EnumWithVariants_zero",
- EnumWithVariants.ZERO,
- HobgoblinTransient0Data::encodeEnumWithVariants,
- HobgoblinTransient0Data::decodeEnumWithVariants
- );
-
- assertRoundTripEncoding(
- "EnumWithVariants_one",
- EnumWithVariants.ONE,
- HobgoblinTransient0Data::encodeEnumWithVariants,
- HobgoblinTransient0Data::decodeEnumWithVariants
- );
-
- assertRoundTripEncoding(
- "EnumWithVariants_two",
- EnumWithVariants.TWO,
- HobgoblinTransient0Data::encodeEnumWithVariants,
- HobgoblinTransient0Data::decodeEnumWithVariants
- );
- }
-
- @Test
- public void structWithEnum() throws IOException {
- var value = new StructWithEnum(
- EnumWithVariants.ONE,
- 42
- );
-
- assertRoundTripEncoding(
- "StructWithEnum",
- value,
- HobgoblinTransient0Data::encodeStructWithEnum,
- HobgoblinTransient0Data::decodeStructWithEnum
- );
- }
-
- @Test
- public void sumWithVariants() throws IOException {
- assertRoundTripEncoding(
- "SumWithVariants_VariantOne",
- new VariantOne(10),
- HobgoblinTransient0Data::encodeSumWithVariants,
- HobgoblinTransient0Data::decodeSumWithVariants
- );
-
- assertRoundTripEncoding(
- "SumWithVariants_VariantTwo",
- new VariantTwo(25),
- HobgoblinTransient0Data::encodeSumWithVariants,
- HobgoblinTransient0Data::decodeSumWithVariants
- );
- }
-
- @Test
- public void sumWithBoxedVariants() throws IOException {
- assertRoundTripEncoding(
- "SumWithBoxedVariants_VariantOne",
- new VariantOne(10),
- HobgoblinTransient0Data::encodeSumWithBoxedVariants,
- HobgoblinTransient0Data::decodeSumWithBoxedVariants
- );
-
- assertRoundTripEncoding(
- "SumWithBoxedVariants_VariantTwo",
- new VariantTwo(25),
- HobgoblinTransient0Data::encodeSumWithBoxedVariants,
- HobgoblinTransient0Data::decodeSumWithBoxedVariants
- );
- }
-
- @Test
- public void structWithSum() throws IOException {
- var value = new StructWithSum(
- new VariantTwo(25),
- 42
- );
-
- assertRoundTripEncoding(
- "StructWithSum",
- value,
- HobgoblinTransient0Data::encodeStructWithSum,
- HobgoblinTransient0Data::decodeStructWithSum
- );
- }
-
- @Test
- public void structWithListOfShared() throws IOException {
- var a = new StructWithInt32(10, 25);
- var b = new StructWithInt32(42, 47);
-
- var value = new StructWithListOfShared(List.of(a, a, b, a, b));
-
- var decodedValue = assertRoundTripEncoding(
- "StructWithListOfShared",
- value,
- HobgoblinTransient0Data::encodeStructWithListOfShared,
- HobgoblinTransient0Data::decodeStructWithListOfShared
- );
- Assertions.assertSame(decodedValue.inner().get(0), decodedValue.inner().get(1));
- Assertions.assertSame(decodedValue.inner().get(0), decodedValue.inner().get(3));
- Assertions.assertSame(decodedValue.inner().get(2), decodedValue.inner().get(4));
- }
-
- @Test
- public void structWithDifferentSharedTypes() throws IOException {
- var a = new StructWithInt32(10, 25);
- var b = new StructWithInt64(42, 47);
- var c = new StructWithInt32(52, 57);
-
- var value = new StructWithDifferentSharedTypes(a, b, c);
-
- assertRoundTripEncoding(
- "StructWithDifferentSharedTypes",
- value,
- HobgoblinTransient0Data::encodeStructWithDifferentSharedTypes,
- HobgoblinTransient0Data::decodeStructWithDifferentSharedTypes
- );
- }
-
- @Test
- public void structWithSharedSumAndVariant() throws IOException {
- var a = new VariantOne(10);
-
- var value = new StructWithSharedSumAndVariant(a, a);
-
- assertRoundTripEncoding(
- "StructWithSharedSumAndVariant",
- value,
- HobgoblinTransient0Data::encodeStructWithSharedSumAndVariant,
- HobgoblinTransient0Data::decodeStructWithSharedSumAndVariant
- );
- }
-
- private <T> T assertRoundTripEncoding(
- String name,
- T value,
- Encoder<T> encoder,
- Decoder<T> decoder
- ) throws IOException {
- var outputStream = new ByteArrayOutputStream();
- encoder.encode(value, outputStream, new HashMap<>());
- var bytes = outputStream.toByteArray();
-
- var outputDir = System.getenv("HOBGOBLIN_OUTPUT_DIR");
- var transient0OutputDir = Path.of(outputDir).resolve("transient-0");
- Files.createDirectories(transient0OutputDir);
- var transient0OutputPath = transient0OutputDir.resolve(name);
- Files.write(transient0OutputPath, bytes);
-
- var inputStream = new ByteArrayInputStream(bytes);
- var decodedValue = decoder.decode(inputStream, new ArrayList<>());
-
- Assertions.assertEquals(value, decodedValue);
-
- return decodedValue;
- }
-
- private interface Encoder<T> {
- void encode(T value, OutputStream outputStream, Map<HobgoblinTransient0TaggedSharedValue, Long> sharedValues) throws IOException;
- }
-
- private interface Decoder<T> {
- T decode(InputStream inputStream, List<Object> sharedValues) throws IOException;
- }
-}