< prev index next >

test/jdk/java/lang/module/ClassFileVersionsTest.java

Print this page
rev 48343 : imported patch JDK-8173382-classfile-version


  37 import static java.lang.module.ModuleDescriptor.Requires.Modifier.*;
  38 
  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         };
  58     }
  59 
  60     // major, minor, modifiers for requires java.base
  61     @DataProvider(name = "unsupported")
  62     public Object[][] unsupported() {
  63         return new Object[][]{
  64                 { 50,   0,  Set.of()},                       // JDK 6
  65                 { 51,   0,  Set.of()},                       // JDK 7
  66                 { 52,   0,  Set.of()},                       // JDK 8
  67 
  68                 { 54,   0,  Set.of(STATIC) },                // JDK 10
  69                 { 54,   0,  Set.of(TRANSITIVE) },
  70                 { 54,   0,  Set.of(STATIC, TRANSITIVE) },
  71 
  72                 { 55,   0,  Set.of()},                       // JDK 11




  73         };
  74     }
  75 
  76     @Test(dataProvider = "supported")
  77     public void testSupported(int major, int minor, Set<Modifier> ms) {
  78         ModuleDescriptor descriptor = ModuleDescriptor.newModule("foo")
  79                 .requires(ms, "java.base")
  80                 .build();
  81         ByteBuffer bb = ModuleInfoWriter.toByteBuffer(descriptor);
  82         classFileVersion(bb, major, minor);
  83         descriptor = ModuleDescriptor.read(bb);
  84         assertEquals(descriptor.name(), "foo");
  85     }
  86 
  87     @Test(dataProvider = "unsupported",
  88           expectedExceptions = InvalidModuleDescriptorException.class)
  89     public void testUnsupported(int major, int minor, Set<Modifier> ms) {
  90         ModuleDescriptor descriptor = ModuleDescriptor.newModule("foo")
  91                 .requires(ms, "java.base")
  92                 .build();


  37 import static java.lang.module.ModuleDescriptor.Requires.Modifier.*;
  38 
  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 
  58                 { 55,   0,  Set.of()},                       // JDK 11
  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()},                       // JDK 12
  79         };
  80     }
  81 
  82     @Test(dataProvider = "supported")
  83     public void testSupported(int major, int minor, Set<Modifier> ms) {
  84         ModuleDescriptor descriptor = ModuleDescriptor.newModule("foo")
  85                 .requires(ms, "java.base")
  86                 .build();
  87         ByteBuffer bb = ModuleInfoWriter.toByteBuffer(descriptor);
  88         classFileVersion(bb, major, minor);
  89         descriptor = ModuleDescriptor.read(bb);
  90         assertEquals(descriptor.name(), "foo");
  91     }
  92 
  93     @Test(dataProvider = "unsupported",
  94           expectedExceptions = InvalidModuleDescriptorException.class)
  95     public void testUnsupported(int major, int minor, Set<Modifier> ms) {
  96         ModuleDescriptor descriptor = ModuleDescriptor.newModule("foo")
  97                 .requires(ms, "java.base")
  98                 .build();
< prev index next >