Skip to content

Commit b48824b

Browse files
committed
Fixed Java test sources so mvn test actually builds
The new CI step runs mvn test for real instead of swallowing its exit code like test_v3.py does, and it exposed two pre-existing bugs: SerializationExample was a public class in a wrongly named file, and its CustomClass collided with the one already in OneTest.java (renamed to Issue60CustomClass). Also skip testSwingObject when there's no display (CI, containers) instead of failing on HeadlessException; its fixture is already committed. Signed-off-by: Thomas Calmant <thomas.calmant@gmail.com>
1 parent 3554b31 commit b48824b

2 files changed

Lines changed: 10 additions & 5 deletions

File tree

‎tests/java/src/test/java/OneTest.java‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import javax.swing.JScrollPane;
2929
import javax.swing.SwingUtilities;
3030

31+
import org.junit.Assume;
3132
import org.junit.Before;
3233
import org.junit.Rule;
3334
import org.junit.Test;
@@ -402,6 +403,10 @@ public void testBoolIntLong() throws Exception {
402403

403404
@Test
404405
public void testSwingObject() throws Exception {
406+
// The fixture this test writes is already committed under tests/:
407+
// skip it where there is no real display to back the JFrame (CI,
408+
// containers) rather than fail the build.
409+
Assume.assumeFalse(java.awt.GraphicsEnvironment.isHeadless());
405410

406411
// Start the frame in the UI thread
407412
SwingUtilities.invokeAndWait(new Runnable() {

tests/java/src/test/java/Issue60CustomReaderEndblock.java renamed to tests/java/src/test/java/SerializationExample.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundE
1818
}
1919
}
2020

21-
class CustomClass extends SuperClass {
21+
class Issue60CustomClass extends SuperClass {
2222
private static final long serialVersionUID = 1L;
2323

2424
private String name;
2525
private List<String> items = null;
2626
private int port = 443;
2727

28-
public CustomClass(String name) {
28+
public Issue60CustomClass(String name) {
2929
this.name = name;
3030
}
3131

@@ -43,15 +43,15 @@ private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundE
4343

4444
@Override
4545
public String toString() {
46-
return "CustomClass{name='" + name + "', items=" + items + "', port=" + port + "}";
46+
return "Issue60CustomClass{name='" + name + "', items=" + items + "', port=" + port + "}";
4747
}
4848
}
4949

5050
public class SerializationExample {
5151
public static void main(String[] args) {
5252
try {
5353
// Create and serialize
54-
CustomClass obj = new CustomClass("test");
54+
Issue60CustomClass obj = new Issue60CustomClass("test");
5555
System.out.println("Original: " + obj);
5656

5757
// Serialize to file
@@ -61,7 +61,7 @@ public static void main(String[] args) {
6161

6262
// Deserialize from file
6363
try (ObjectInputStream ois = new ObjectInputStream(new FileInputStream("issue60_custom_reader_endblock.ser"))) {
64-
CustomClass deserialized = (CustomClass) ois.readObject();
64+
Issue60CustomClass deserialized = (Issue60CustomClass) ois.readObject();
6565
System.out.println("Deserialized: " + deserialized);
6666
}
6767

0 commit comments

Comments
 (0)