Modify JavaVersionTest.testGetJavaVersion() to automatically test all the versions supported

This commit is contained in:
Emmanuel Bourg 2023-07-05 10:46:18 +02:00
parent 1e523283ce
commit 28e54a3536
1 changed files with 7 additions and 27 deletions

View File

@ -19,18 +19,6 @@
package org.apache.commons.lang3; package org.apache.commons.lang3;
import static org.apache.commons.lang3.JavaVersion.JAVA_0_9; import static org.apache.commons.lang3.JavaVersion.JAVA_0_9;
import static org.apache.commons.lang3.JavaVersion.JAVA_10;
import static org.apache.commons.lang3.JavaVersion.JAVA_11;
import static org.apache.commons.lang3.JavaVersion.JAVA_12;
import static org.apache.commons.lang3.JavaVersion.JAVA_13;
import static org.apache.commons.lang3.JavaVersion.JAVA_14;
import static org.apache.commons.lang3.JavaVersion.JAVA_15;
import static org.apache.commons.lang3.JavaVersion.JAVA_16;
import static org.apache.commons.lang3.JavaVersion.JAVA_17;
import static org.apache.commons.lang3.JavaVersion.JAVA_18;
import static org.apache.commons.lang3.JavaVersion.JAVA_19;
import static org.apache.commons.lang3.JavaVersion.JAVA_20;
import static org.apache.commons.lang3.JavaVersion.JAVA_21;
import static org.apache.commons.lang3.JavaVersion.JAVA_1_1; import static org.apache.commons.lang3.JavaVersion.JAVA_1_1;
import static org.apache.commons.lang3.JavaVersion.JAVA_1_2; import static org.apache.commons.lang3.JavaVersion.JAVA_1_2;
import static org.apache.commons.lang3.JavaVersion.JAVA_1_3; import static org.apache.commons.lang3.JavaVersion.JAVA_1_3;
@ -39,7 +27,6 @@ import static org.apache.commons.lang3.JavaVersion.JAVA_1_5;
import static org.apache.commons.lang3.JavaVersion.JAVA_1_6; import static org.apache.commons.lang3.JavaVersion.JAVA_1_6;
import static org.apache.commons.lang3.JavaVersion.JAVA_1_7; import static org.apache.commons.lang3.JavaVersion.JAVA_1_7;
import static org.apache.commons.lang3.JavaVersion.JAVA_1_8; import static org.apache.commons.lang3.JavaVersion.JAVA_1_8;
import static org.apache.commons.lang3.JavaVersion.JAVA_9;
import static org.apache.commons.lang3.JavaVersion.JAVA_RECENT; import static org.apache.commons.lang3.JavaVersion.JAVA_RECENT;
import static org.apache.commons.lang3.JavaVersion.get; import static org.apache.commons.lang3.JavaVersion.get;
import static org.apache.commons.lang3.JavaVersion.getJavaVersion; import static org.apache.commons.lang3.JavaVersion.getJavaVersion;
@ -55,7 +42,7 @@ import org.junit.jupiter.api.Test;
public class JavaVersionTest extends AbstractLangTest { public class JavaVersionTest extends AbstractLangTest {
@Test @Test
public void testGetJavaVersion() { public void testGetJavaVersion() throws Exception {
assertEquals(JAVA_0_9, get("0.9"), "0.9 failed"); assertEquals(JAVA_0_9, get("0.9"), "0.9 failed");
assertEquals(JAVA_1_1, get("1.1"), "1.1 failed"); assertEquals(JAVA_1_1, get("1.1"), "1.1 failed");
assertEquals(JAVA_1_2, get("1.2"), "1.2 failed"); assertEquals(JAVA_1_2, get("1.2"), "1.2 failed");
@ -65,19 +52,12 @@ public class JavaVersionTest extends AbstractLangTest {
assertEquals(JAVA_1_6, get("1.6"), "1.6 failed"); assertEquals(JAVA_1_6, get("1.6"), "1.6 failed");
assertEquals(JAVA_1_7, get("1.7"), "1.7 failed"); assertEquals(JAVA_1_7, get("1.7"), "1.7 failed");
assertEquals(JAVA_1_8, get("1.8"), "1.8 failed"); assertEquals(JAVA_1_8, get("1.8"), "1.8 failed");
assertEquals(JAVA_9, get("9"), "9 failed");
assertEquals(JAVA_10, get("10"), "10 failed"); int lastSupportedVersion = Integer.parseInt(JavaVersion.values()[JavaVersion.values().length - 2].toString());
assertEquals(JAVA_11, get("11"), "11 failed"); for (int i = 9; i <= lastSupportedVersion; i++) {
assertEquals(JAVA_12, get("12"), "12 failed"); assertEquals(JavaVersion.class.getField("JAVA_" + i).get(null), get("" + i), i + " failed");
assertEquals(JAVA_13, get("13"), "13 failed"); }
assertEquals(JAVA_14, get("14"), "14 failed");
assertEquals(JAVA_15, get("15"), "15 failed");
assertEquals(JAVA_16, get("16"), "16 failed");
assertEquals(JAVA_17, get("17"), "17 failed");
assertEquals(JAVA_18, get("18"), "18 failed");
assertEquals(JAVA_19, get("19"), "19 failed");
assertEquals(JAVA_20, get("20"), "20 failed");
assertEquals(JAVA_21, get("21"), "21 failed");
assertEquals(JAVA_RECENT, get("1.10"), "1.10 failed"); assertEquals(JAVA_RECENT, get("1.10"), "1.10 failed");
// assertNull("2.10 unexpectedly worked", get("2.10")); // assertNull("2.10 unexpectedly worked", get("2.10"));
assertEquals(get("1.5"), getJavaVersion("1.5"), "Wrapper method failed"); assertEquals(get("1.5"), getJavaVersion("1.5"), "Wrapper method failed");