|
43 | 43 | import static org.testng.Assert.*;
|
44 | 44 |
|
45 | 45 | public class ClassFileVersionsTest {
|
| 46 | + private static final int FEATURE; |
| 47 | + static { |
| 48 | + FEATURE = Runtime.version().feature(); |
| 49 | + assert FEATURE >= 10; |
| 50 | + } |
46 | 51 |
|
47 | 52 | // major, minor, modifiers for requires java.base
|
48 | 53 | @DataProvider(name = "supported")
|
49 | 54 | public Object[][] supported() {
|
50 |
| - return new Object[][]{ |
51 |
| - { 53, 0, Set.of() }, // JDK 9 |
52 |
| - { 53, 0, Set.of(STATIC) }, |
53 |
| - { 53, 0, Set.of(TRANSITIVE) }, |
54 |
| - { 53, 0, Set.of(STATIC, TRANSITIVE) }, |
55 |
| - |
56 |
| - { 54, 0, Set.of() }, // JDK 10 |
57 |
| - { 55, 0, Set.of() }, // JDK 11 |
58 |
| - { 56, 0, Set.of() }, // JDK 12 |
59 |
| - { 57, 0, Set.of() }, // JDK 13 |
60 |
| - { 58, 0, Set.of() }, // JDK 14 |
61 |
| - { 59, 0, Set.of() }, // JDK 15 |
62 |
| - { 60, 0, Set.of() }, // JDK 16 |
63 |
| - { 61, 0, Set.of() }, // JDK 17 |
64 |
| - { 62, 0, Set.of() }, // JDK 18 |
65 |
| - }; |
| 55 | + /* |
| 56 | + * There are four test cases for JDK 9 and then one test case |
| 57 | + * for each subsequent JDK version from JDK 10 to the current |
| 58 | + * feature release for a total of (4 + (FEATURE - 9) ) => |
| 59 | + * (feature - 5) rows. |
| 60 | + */ |
| 61 | + Object[][] result = new Object[(FEATURE - 5)][]; |
| 62 | + |
| 63 | + // Class file version of JDK 9 is 53.0 |
| 64 | + result[0] = new Object[]{ 53, 0, Set.of()}; |
| 65 | + result[1] = new Object[]{ 53, 0, Set.of(STATIC) }; |
| 66 | + result[2] = new Object[]{ 53, 0, Set.of(TRANSITIVE) }; |
| 67 | + result[3] = new Object[]{ 53, 0, Set.of(STATIC, TRANSITIVE) }; |
| 68 | + |
| 69 | + // Major class file version of JDK N is 44 + n. Create rows |
| 70 | + // for JDK 10 through FEATURE. |
| 71 | + for (int i = 4; i < (FEATURE - 5) ; i++) { |
| 72 | + result[i] = new Object[]{i + 50, 0, Set.of()}; |
| 73 | + } |
| 74 | + |
| 75 | + return result; |
66 | 76 | }
|
67 | 77 |
|
68 | 78 | // major, minor, modifiers for requires java.base
|
69 | 79 | @DataProvider(name = "unsupported")
|
70 | 80 | public Object[][] unsupported() {
|
71 |
| - return new Object[][]{ |
72 |
| - { 50, 0, Set.of()}, // JDK 6 |
73 |
| - { 51, 0, Set.of()}, // JDK 7 |
74 |
| - { 52, 0, Set.of()}, // JDK 8 |
75 |
| - |
76 |
| - { 54, 0, Set.of(STATIC) }, // JDK 10 |
77 |
| - { 54, 0, Set.of(TRANSITIVE) }, |
78 |
| - { 54, 0, Set.of(STATIC, TRANSITIVE) }, |
79 |
| - |
80 |
| - { 55, 0, Set.of(STATIC) }, // JDK 11 |
81 |
| - { 55, 0, Set.of(TRANSITIVE) }, |
82 |
| - { 55, 0, Set.of(STATIC, TRANSITIVE) }, |
83 |
| - |
84 |
| - { 56, 0, Set.of(STATIC) }, // JDK 12 |
85 |
| - { 56, 0, Set.of(TRANSITIVE) }, |
86 |
| - { 56, 0, Set.of(STATIC, TRANSITIVE) }, |
87 |
| - |
88 |
| - { 57, 0, Set.of(STATIC) }, // JDK 13 |
89 |
| - { 57, 0, Set.of(TRANSITIVE) }, |
90 |
| - { 57, 0, Set.of(STATIC, TRANSITIVE) }, |
91 |
| - |
92 |
| - { 58, 0, Set.of(STATIC) }, // JDK 14 |
93 |
| - { 58, 0, Set.of(TRANSITIVE) }, |
94 |
| - { 58, 0, Set.of(STATIC, TRANSITIVE) }, |
95 |
| - |
96 |
| - { 59, 0, Set.of(STATIC) }, // JDK 15 |
97 |
| - { 59, 0, Set.of(TRANSITIVE) }, |
98 |
| - { 59, 0, Set.of(STATIC, TRANSITIVE) }, |
99 |
| - |
100 |
| - { 60, 0, Set.of(STATIC) }, // JDK 16 |
101 |
| - { 60, 0, Set.of(TRANSITIVE) }, |
102 |
| - { 60, 0, Set.of(STATIC, TRANSITIVE) }, |
103 |
| - |
104 |
| - { 61, 0, Set.of(STATIC) }, // JDK 17 |
105 |
| - { 61, 0, Set.of(TRANSITIVE) }, |
106 |
| - { 61, 0, Set.of(STATIC, TRANSITIVE) }, |
107 |
| - |
108 |
| - { 62, 0, Set.of(STATIC) }, // JDK 18 |
109 |
| - { 62, 0, Set.of(TRANSITIVE) }, |
110 |
| - { 62, 0, Set.of(STATIC, TRANSITIVE) }, |
111 |
| - |
112 |
| - { 63, 0, Set.of()}, // JDK 19 |
113 |
| - }; |
| 81 | + /* |
| 82 | + * There are three test cases for releases prior to JDK 9, |
| 83 | + * three test cases for each JDK version from JDK 10 to the |
| 84 | + * current feature release, plus one addition test case for |
| 85 | + * the next release for a total of (3 + (FEATURE - 9) * 3 + 1) |
| 86 | + * rows. |
| 87 | + */ |
| 88 | + int unsupportedCount = 3 + (FEATURE - 9)*3 + 1; |
| 89 | + Object[][] result = new Object[unsupportedCount][]; |
| 90 | + |
| 91 | + result[0] = new Object[]{50, 0, Set.of()}; // JDK 6 |
| 92 | + result[1] = new Object[]{51, 0, Set.of()}; // JDK 7 |
| 93 | + result[2] = new Object[]{52, 0, Set.of()}; // JDK 8 |
| 94 | + |
| 95 | + for (int i = 10; i <= FEATURE ; i++) { |
| 96 | + int base = 3 + (i-10)*3; |
| 97 | + // Major class file version of JDK N is 44+n |
| 98 | + result[base] = new Object[]{i + 44, 0, Set.of(STATIC)}; |
| 99 | + result[base + 1] = new Object[]{i + 44, 0, Set.of(TRANSITIVE)}; |
| 100 | + result[base + 2] = new Object[]{i + 44, 0, Set.of(STATIC, TRANSITIVE)}; |
| 101 | + } |
| 102 | + |
| 103 | + result[unsupportedCount - 1] = new Object[]{FEATURE+1+44, 0, Set.of()}; |
| 104 | + return result; |
114 | 105 | }
|
115 | 106 |
|
116 | 107 | @Test(dataProvider = "supported")
|
|
0 commit comments