39 import jdk.internal.module.ModuleInfoWriter;
40
41 import org.testng.annotations.DataProvider;
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 };
60 }
61
62 // major, minor, modifiers for requires java.base
63 @DataProvider(name = "unsupported")
64 public Object[][] unsupported() {
65 return new Object[][]{
66 { 50, 0, Set.of()}, // JDK 6
67 { 51, 0, Set.of()}, // JDK 7
68 { 52, 0, Set.of()}, // JDK 8
69
70 { 54, 0, Set.of(STATIC) }, // JDK 10
71 { 54, 0, Set.of(TRANSITIVE) },
72 { 54, 0, Set.of(STATIC, TRANSITIVE) },
73
74 { 55, 0, Set.of(STATIC) }, // JDK 11
75 { 55, 0, Set.of(TRANSITIVE) },
76 { 55, 0, Set.of(STATIC, TRANSITIVE) },
77
78 { 56, 0, Set.of(STATIC) }, // JDK 12
79 { 56, 0, Set.of(TRANSITIVE) },
80 { 56, 0, Set.of(STATIC, TRANSITIVE) },
81
82 { 57, 0, Set.of()}, // JDK 13
83 };
84 }
85
86 @Test(dataProvider = "supported")
87 public void testSupported(int major, int minor, Set<Modifier> ms) {
88 ModuleDescriptor descriptor = ModuleDescriptor.newModule("foo")
89 .requires(ms, "java.base")
90 .build();
91 ByteBuffer bb = ModuleInfoWriter.toByteBuffer(descriptor);
92 classFileVersion(bb, major, minor);
93 descriptor = ModuleDescriptor.read(bb);
94 assertEquals(descriptor.name(), "foo");
95 }
96
97 @Test(dataProvider = "unsupported",
98 expectedExceptions = InvalidModuleDescriptorException.class)
99 public void testUnsupported(int major, int minor, Set<Modifier> ms) {
100 ModuleDescriptor descriptor = ModuleDescriptor.newModule("foo")
101 .requires(ms, "java.base")
102 .build();
|
39 import jdk.internal.module.ModuleInfoWriter;
40
41 import org.testng.annotations.DataProvider;
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 };
61 }
62
63 // major, minor, modifiers for requires java.base
64 @DataProvider(name = "unsupported")
65 public Object[][] unsupported() {
66 return new Object[][]{
67 { 50, 0, Set.of()}, // JDK 6
68 { 51, 0, Set.of()}, // JDK 7
69 { 52, 0, Set.of()}, // JDK 8
70
71 { 54, 0, Set.of(STATIC) }, // JDK 10
72 { 54, 0, Set.of(TRANSITIVE) },
73 { 54, 0, Set.of(STATIC, TRANSITIVE) },
74
75 { 55, 0, Set.of(STATIC) }, // JDK 11
76 { 55, 0, Set.of(TRANSITIVE) },
77 { 55, 0, Set.of(STATIC, TRANSITIVE) },
78
79 { 56, 0, Set.of(STATIC) }, // JDK 12
80 { 56, 0, Set.of(TRANSITIVE) },
81 { 56, 0, Set.of(STATIC, TRANSITIVE) },
82
83 { 57, 0, Set.of(STATIC) }, // JDK 13
84 { 57, 0, Set.of(TRANSITIVE) },
85 { 57, 0, Set.of(STATIC, TRANSITIVE) },
86
87 { 58, 0, Set.of()}, // JDK 14
88 };
89 }
90
91 @Test(dataProvider = "supported")
92 public void testSupported(int major, int minor, Set<Modifier> ms) {
93 ModuleDescriptor descriptor = ModuleDescriptor.newModule("foo")
94 .requires(ms, "java.base")
95 .build();
96 ByteBuffer bb = ModuleInfoWriter.toByteBuffer(descriptor);
97 classFileVersion(bb, major, minor);
98 descriptor = ModuleDescriptor.read(bb);
99 assertEquals(descriptor.name(), "foo");
100 }
101
102 @Test(dataProvider = "unsupported",
103 expectedExceptions = InvalidModuleDescriptorException.class)
104 public void testUnsupported(int major, int minor, Set<Modifier> ms) {
105 ModuleDescriptor descriptor = ModuleDescriptor.newModule("foo")
106 .requires(ms, "java.base")
107 .build();
|