42 import org.testng.annotations.Test;
43 import static org.testng.Assert.*;
44
45 public class ClassFileVersionsTest {
46
47 // major, minor, modifiers for requires java.base
48 @DataProvider(name = "supported")
49 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 };
63 }
64
65 // major, minor, modifiers for requires java.base
66 @DataProvider(name = "unsupported")
67 public Object[][] unsupported() {
68 return new Object[][]{
69 { 50, 0, Set.of()}, // JDK 6
70 { 51, 0, Set.of()}, // JDK 7
71 { 52, 0, Set.of()}, // JDK 8
72
73 { 54, 0, Set.of(STATIC) }, // JDK 10
74 { 54, 0, Set.of(TRANSITIVE) },
75 { 54, 0, Set.of(STATIC, TRANSITIVE) },
76
77 { 55, 0, Set.of(STATIC) }, // JDK 11
78 { 55, 0, Set.of(TRANSITIVE) },
79 { 55, 0, Set.of(STATIC, TRANSITIVE) },
80
81 { 56, 0, Set.of(STATIC) }, // JDK 12
82 { 56, 0, Set.of(TRANSITIVE) },
83 { 56, 0, Set.of(STATIC, TRANSITIVE) },
84
85 { 57, 0, Set.of(STATIC) }, // JDK 13
86 { 57, 0, Set.of(TRANSITIVE) },
87 { 57, 0, Set.of(STATIC, TRANSITIVE) },
88
89 { 58, 0, Set.of(STATIC) }, // JDK 14
90 { 58, 0, Set.of(TRANSITIVE) },
91 { 58, 0, Set.of(STATIC, TRANSITIVE) },
92
93 { 59, 0, Set.of(STATIC) }, // JDK 15
94 { 59, 0, Set.of(TRANSITIVE) },
95 { 59, 0, Set.of(STATIC, TRANSITIVE) },
96
97 { 60, 0, Set.of()}, // JDK 16
98 };
99 }
100
101 @Test(dataProvider = "supported")
102 public void testSupported(int major, int minor, Set<Modifier> ms) {
103 ModuleDescriptor descriptor = ModuleDescriptor.newModule("foo")
104 .requires(ms, "java.base")
105 .build();
106 ByteBuffer bb = ModuleInfoWriter.toByteBuffer(descriptor);
107 classFileVersion(bb, major, minor);
108 descriptor = ModuleDescriptor.read(bb);
109 assertEquals(descriptor.name(), "foo");
110 }
111
112 @Test(dataProvider = "unsupported",
113 expectedExceptions = InvalidModuleDescriptorException.class)
114 public void testUnsupported(int major, int minor, Set<Modifier> ms) {
115 ModuleDescriptor descriptor = ModuleDescriptor.newModule("foo")
116 .requires(ms, "java.base")
117 .build();
|
42 import org.testng.annotations.Test;
43 import static org.testng.Assert.*;
44
45 public class ClassFileVersionsTest {
46
47 // major, minor, modifiers for requires java.base
48 @DataProvider(name = "supported")
49 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 };
64 }
65
66 // major, minor, modifiers for requires java.base
67 @DataProvider(name = "unsupported")
68 public Object[][] unsupported() {
69 return new Object[][]{
70 { 50, 0, Set.of()}, // JDK 6
71 { 51, 0, Set.of()}, // JDK 7
72 { 52, 0, Set.of()}, // JDK 8
73
74 { 54, 0, Set.of(STATIC) }, // JDK 10
75 { 54, 0, Set.of(TRANSITIVE) },
76 { 54, 0, Set.of(STATIC, TRANSITIVE) },
77
78 { 55, 0, Set.of(STATIC) }, // JDK 11
79 { 55, 0, Set.of(TRANSITIVE) },
80 { 55, 0, Set.of(STATIC, TRANSITIVE) },
81
82 { 56, 0, Set.of(STATIC) }, // JDK 12
83 { 56, 0, Set.of(TRANSITIVE) },
84 { 56, 0, Set.of(STATIC, TRANSITIVE) },
85
86 { 57, 0, Set.of(STATIC) }, // JDK 13
87 { 57, 0, Set.of(TRANSITIVE) },
88 { 57, 0, Set.of(STATIC, TRANSITIVE) },
89
90 { 58, 0, Set.of(STATIC) }, // JDK 14
91 { 58, 0, Set.of(TRANSITIVE) },
92 { 58, 0, Set.of(STATIC, TRANSITIVE) },
93
94 { 59, 0, Set.of(STATIC) }, // JDK 15
95 { 59, 0, Set.of(TRANSITIVE) },
96 { 59, 0, Set.of(STATIC, TRANSITIVE) },
97
98 { 60, 0, Set.of(STATIC) }, // JDK 16
99 { 60, 0, Set.of(TRANSITIVE) },
100 { 60, 0, Set.of(STATIC, TRANSITIVE) },
101
102 { 61, 0, Set.of()}, // JDK 17
103 };
104 }
105
106 @Test(dataProvider = "supported")
107 public void testSupported(int major, int minor, Set<Modifier> ms) {
108 ModuleDescriptor descriptor = ModuleDescriptor.newModule("foo")
109 .requires(ms, "java.base")
110 .build();
111 ByteBuffer bb = ModuleInfoWriter.toByteBuffer(descriptor);
112 classFileVersion(bb, major, minor);
113 descriptor = ModuleDescriptor.read(bb);
114 assertEquals(descriptor.name(), "foo");
115 }
116
117 @Test(dataProvider = "unsupported",
118 expectedExceptions = InvalidModuleDescriptorException.class)
119 public void testUnsupported(int major, int minor, Set<Modifier> ms) {
120 ModuleDescriptor descriptor = ModuleDescriptor.newModule("foo")
121 .requires(ms, "java.base")
122 .build();
|