diff options
Diffstat (limited to 'examples/10-transient-0/output/java/src/test')
| -rw-r--r-- | examples/10-transient-0/output/java/src/test/java/org/zwobble/example/Transient0Tests.java | 214 |
1 files changed, 0 insertions, 214 deletions
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 deleted file mode 100644 index 6369f93..0000000 --- a/examples/10-transient-0/output/java/src/test/java/org/zwobble/example/Transient0Tests.java +++ /dev/null @@ -1,214 +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.StructWithBool; -import org.zwobble.example.types.data.StructWithEnum; -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.StructWithStruct; -import org.zwobble.example.types.data.StructWithSum; -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 structWithStruct() throws IOException { - var value = new StructWithStruct(new StructWithInt32(10, 25), 42); - - assertRoundTripEncoding( - 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( - 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 StructWithInt32(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 structWithEnum() throws IOException { - var value = new StructWithEnum( - EnumWithVariants.ONE, - 42 - ); - - assertRoundTripEncoding( - value, - HobgoblinTransient0Data::encodeStructWithEnum, - HobgoblinTransient0Data::decodeStructWithEnum - ); - } - - @Test - public void sumWithVariants() throws IOException { - assertRoundTripEncoding( - new VariantOne(10), - HobgoblinTransient0Data::encodeSumWithVariants, - HobgoblinTransient0Data::decodeSumWithVariants - ); - - assertRoundTripEncoding( - new VariantTwo(25), - HobgoblinTransient0Data::encodeSumWithVariants, - HobgoblinTransient0Data::decodeSumWithVariants - ); - } - - @Test - public void structWithSum() throws IOException { - var value = new StructWithSum( - new VariantTwo(25), - 42 - ); - - assertRoundTripEncoding( - value, - HobgoblinTransient0Data::encodeStructWithSum, - HobgoblinTransient0Data::decodeStructWithSum - ); - } - - 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; - } -} |
