From 4133ac73119f00c3ba8b75266d58389f442fb572 Mon Sep 17 00:00:00 2001 From: Curtis Rueden Date: Sat, 4 Nov 2023 09:36:52 -0500 Subject: [PATCH] ObjectIndexTest: make tests pass with OpenJDK 12 Closes #474. --- .../org/scijava/object/ObjectIndexTest.java | 25 +++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/src/test/java/org/scijava/object/ObjectIndexTest.java b/src/test/java/org/scijava/object/ObjectIndexTest.java index 00be93314..dfd4978f1 100644 --- a/src/test/java/org/scijava/object/ObjectIndexTest.java +++ b/src/test/java/org/scijava/object/ObjectIndexTest.java @@ -36,6 +36,7 @@ import static org.junit.Assert.assertTrue; import java.util.ArrayList; +import java.util.Arrays; import java.util.Iterator; import java.util.List; @@ -209,15 +210,25 @@ public void testToString() { objectIndex.add(new Integer(5)); objectIndex.add(new Float(2.5f)); objectIndex.add(new Integer(3)); - final String[] expected = - { "java.io.Serializable: {5, 2.5, 3}", - "java.lang.Comparable: {5, 2.5, 3}", "java.lang.Float: {2.5}", - "java.lang.Integer: {5, 3}", "java.lang.Number: {5, 2.5, 3}", - "java.lang.Object: {5, 2.5, 3}", - "org.scijava.object.ObjectIndex$All: {5, 2.5, 3}" }; + + final List expected = new ArrayList<>(); + expected.addAll(Arrays.asList( + "java.io.Serializable: {5, 2.5, 3}", + "java.lang.Comparable: {5, 2.5, 3}", "java.lang.Float: {2.5}", + "java.lang.Integer: {5, 3}", "java.lang.Number: {5, 2.5, 3}", + "java.lang.Object: {5, 2.5, 3}" + )); + final String[] javaVersion = System.getProperty("java.version").split("\\."); + final int majorVersion = Integer.parseInt(javaVersion[0]); + if (majorVersion >= 12) { + expected.add("java.lang.constant.Constable: {5, 2.5, 3}"); + expected.add("java.lang.constant.ConstantDesc: {5, 2.5, 3}"); + } + expected.add("org.scijava.object.ObjectIndex$All: {5, 2.5, 3}"); + final String[] actual = objectIndex.toString().split(System.getProperty("line.separator")); - assertArrayEquals(expected, actual); + assertArrayEquals(expected.toArray(), actual); } }