summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2026-07-05 10:56:48 +0100
committerMichael Williamson <mike@zwobble.org>2026-07-05 10:58:53 +0100
commit727b09bf8fe6c0b9085d2b61d1f8ed5c81b2fdce (patch)
treefea6b1f5ed8d79b71227714d4f93c1b22511c818
parentddc251ace30b4ca694a006e3cca2375bb2255aed (diff)
Use JUnit in Java transient-0 example
-rw-r--r--examples/10-transient-0/hobgoblin.json54
-rw-r--r--examples/10-transient-0/output/java-junit/.gitignore (renamed from examples/10-transient-0/output/java/.gitignore)0
-rw-r--r--examples/10-transient-0/output/java-junit/pom.xml (renamed from examples/10-transient-0/output/java/pom.xml)18
-rw-r--r--examples/10-transient-0/output/java-junit/src/test/java/org/zwobble/example/Transient0Tests.java (renamed from examples/10-transient-0/output/java/src/main/java/org/zwobble/example/Main.java)16
-rw-r--r--src/test/java/org/zwobble/hobgoblin/compiler/ExampleTests.java6
5 files changed, 32 insertions, 12 deletions
diff --git a/examples/10-transient-0/hobgoblin.json5 b/examples/10-transient-0/hobgoblin.json5
index f3e455d..ee08699 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/src/gen/java",
+ path: "output/java-junit/src/gen/java",
},
{
generator: "java-transient-0",
- path: "output/java/src/gen/java",
+ path: "output/java-junit/src/gen/java",
},
],
}
diff --git a/examples/10-transient-0/output/java/.gitignore b/examples/10-transient-0/output/java-junit/.gitignore
index ff511d4..ff511d4 100644
--- a/examples/10-transient-0/output/java/.gitignore
+++ b/examples/10-transient-0/output/java-junit/.gitignore
diff --git a/examples/10-transient-0/output/java/pom.xml b/examples/10-transient-0/output/java-junit/pom.xml
index 7f892e1..88ef3e5 100644
--- a/examples/10-transient-0/output/java/pom.xml
+++ b/examples/10-transient-0/output/java-junit/pom.xml
@@ -11,15 +11,31 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>25</maven.compiler.source>
<maven.compiler.target>25</maven.compiler.target>
- <exec.mainClass>org.zwobble.example.Main</exec.mainClass>
</properties>
+ <dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>org.junit</groupId>
+ <artifactId>junit-bom</artifactId>
+ <version>5.9.3</version>
+ <type>pom</type>
+ <scope>import</scope>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+
<dependencies>
<dependency>
<groupId>org.zwobble.precisely</groupId>
<artifactId>precisely</artifactId>
<version>0.1.5</version>
</dependency>
+ <dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<build>
diff --git a/examples/10-transient-0/output/java/src/main/java/org/zwobble/example/Main.java b/examples/10-transient-0/output/java-junit/src/test/java/org/zwobble/example/Transient0Tests.java
index 155b2a0..4959a5c 100644
--- a/examples/10-transient-0/output/java/src/main/java/org/zwobble/example/Main.java
+++ b/examples/10-transient-0/output/java-junit/src/test/java/org/zwobble/example/Transient0Tests.java
@@ -2,11 +2,15 @@ package org.zwobble.example;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
import org.zwobble.example.types.point.Point;
import org.zwobble.example.types.point.HobgoblinTransient0Point;
-public class Main {
- public static void main() throws java.io.IOException {
+public class Transient0Tests {
+ @Test
+ public void structWithInt32() throws IOException {
var point = new Point(10, 25);
var outputStream = new ByteArrayOutputStream();
@@ -16,12 +20,6 @@ public class Main {
var inputStream = new ByteArrayInputStream(bytes);
var decodedPoint = HobgoblinTransient0Point.decode(inputStream);
- if (!point.equals(decodedPoint)) {
- throw new RuntimeException(String.format(
- "encode-decode did not produce identical data\nexpected: %s\nbut was: %s",
- point,
- decodedPoint
- ));
- }
+ Assertions.assertEquals(point, decodedPoint);
}
}
diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/ExampleTests.java b/src/test/java/org/zwobble/hobgoblin/compiler/ExampleTests.java
index 80c2fbd..46b35e4 100644
--- a/src/test/java/org/zwobble/hobgoblin/compiler/ExampleTests.java
+++ b/src/test/java/org/zwobble/hobgoblin/compiler/ExampleTests.java
@@ -27,6 +27,7 @@ public class ExampleTests {
HobgoblinCompiler.compile(exampleSet.path());
verifyJavaOutput(exampleSet);
+ verifyJavaJunitOutput(exampleSet);
verifyRustOutput(exampleSet);
}
@@ -34,6 +35,11 @@ public class ExampleTests {
verifyOutput(exampleSet, "java", List.of("mvn", "compile", "exec:java"));
}
+ private void verifyJavaJunitOutput(ExampleSet exampleSet) throws NoSuchAlgorithmException, IOException, InterruptedException {
+ // TODO: allow example to declare its structure
+ verifyOutput(exampleSet, "java-junit", List.of("mvn", "test"));
+ }
+
private void verifyRustOutput(ExampleSet exampleSet) throws NoSuchAlgorithmException, IOException, InterruptedException {
verifyOutput(exampleSet, "rust", List.of("cargo", "run"));
}