33
33
import org .codehaus .plexus .languages .java .jpms .JavaModuleDescriptor .JavaProvides ;
34
34
import org .codehaus .plexus .languages .java .jpms .JavaModuleDescriptor .JavaRequires ;
35
35
import org .codehaus .plexus .languages .java .version .JavaVersion ;
36
- import org .junit .Test ;
36
+ import org .junit .jupiter . api . Test ;
37
37
38
- import static org .hamcrest .MatcherAssert .assertThat ;
39
- import static org .hamcrest .Matchers .is ;
40
- import static org .junit .Assert .assertArrayEquals ;
41
- import static org .junit .Assert .assertEquals ;
42
- import static org .junit .Assert .assertNotNull ;
43
- import static org .junit .Assert .assertNull ;
38
+ import static org .assertj .core .api .Assertions .assertThat ;
39
+ import static org .junit .jupiter .api .Assertions .assertArrayEquals ;
40
+ import static org .junit .jupiter .api .Assertions .assertEquals ;
41
+ import static org .junit .jupiter .api .Assertions .assertFalse ;
42
+ import static org .junit .jupiter .api .Assertions .assertNotNull ;
43
+ import static org .junit .jupiter .api .Assertions .assertNull ;
44
+ import static org .junit .jupiter .api .Assertions .assertThrows ;
44
45
45
- public class BinaryModuleInfoParserTest {
46
- private BinaryModuleInfoParser parser = new BinaryModuleInfoParser ();
46
+ class BinaryModuleInfoParserTest {
47
+ private final BinaryModuleInfoParser parser = new BinaryModuleInfoParser ();
47
48
48
49
@ Test
49
- public void testJarDescriptor () throws Exception {
50
+ void testJarDescriptor () throws Exception {
50
51
JavaModuleDescriptor descriptor =
51
52
parser .getModuleDescriptor (Paths .get ("src/test/resources/jar.descriptor/asm-6.0_BETA.jar" ));
52
53
53
54
assertNotNull (descriptor );
54
- assertEquals ( "org.objectweb.asm" , descriptor . name () );
55
- assertEquals ( false , descriptor .isAutomatic ());
55
+ assertThat ( descriptor . name ()). isEqualTo ( "org.objectweb.asm" );
56
+ assertFalse ( descriptor .isAutomatic ());
56
57
57
- assertEquals ( 1 , descriptor .requires (). size () );
58
+ assertThat ( descriptor .requires ()). hasSize ( 1 );
58
59
assertEquals ("java.base" , descriptor .requires ().iterator ().next ().name ());
59
60
60
61
Set <JavaExports > expectedExports = JavaModuleDescriptor .newAutomaticModule ("_" )
@@ -66,17 +67,17 @@ public void testJarDescriptor() throws Exception {
66
67
}
67
68
68
69
@ Test
69
- public void testMultiReleaseJarDescriptor () throws Exception {
70
+ void testMultiReleaseJarDescriptor () throws Exception {
70
71
JavaModuleDescriptor descriptor = parser .getModuleDescriptor (
71
72
Paths .get ("src/test/resources/jar.mr.descriptor/jloadr-1.0-SNAPSHOT.jar" ), JavaVersion .parse ("17" ));
72
73
73
74
assertNotNull (descriptor );
74
75
assertEquals ("de.adito.jloadr" , descriptor .name ());
75
- assertEquals ( false , descriptor .isAutomatic ());
76
+ assertFalse ( descriptor .isAutomatic ());
76
77
}
77
78
78
79
@ Test
79
- public void testIncompleteMultiReleaseJarDescriptor () throws Exception {
80
+ void testIncompleteMultiReleaseJarDescriptor () throws Exception {
80
81
// this jar is missing the Multi-Release: true entry in the Manifest
81
82
JavaModuleDescriptor descriptor = parser .getModuleDescriptor (
82
83
Paths .get ("src/test/resources/jar.mr.incomplete.descriptor/jloadr-1.0-SNAPSHOT.jar" ));
@@ -85,23 +86,23 @@ public void testIncompleteMultiReleaseJarDescriptor() throws Exception {
85
86
}
86
87
87
88
@ Test
88
- public void testClassicJar () throws Exception {
89
+ void testClassicJar () throws Exception {
89
90
JavaModuleDescriptor descriptor =
90
91
parser .getModuleDescriptor (Paths .get ("src/test/resources/jar.empty/plexus-java-1.0.0-SNAPSHOT.jar" ));
91
92
92
93
assertNull (descriptor );
93
94
}
94
95
95
96
@ Test
96
- public void testOutputDirectoryDescriptor () throws Exception {
97
+ void testOutputDirectoryDescriptor () throws Exception {
97
98
JavaModuleDescriptor descriptor =
98
99
parser .getModuleDescriptor (Paths .get ("src/test/resources/dir.descriptor/out" ));
99
100
100
101
assertNotNull (descriptor );
101
102
assertEquals ("org.codehaus.plexus.languages.java.demo" , descriptor .name ());
102
- assertEquals ( false , descriptor .isAutomatic ());
103
+ assertFalse ( descriptor .isAutomatic ());
103
104
104
- assertEquals ( 3 , descriptor .requires (). size () );
105
+ assertThat ( descriptor .requires ()). hasSize ( 3 );
105
106
106
107
Set <JavaRequires > expectedRequires = JavaModuleDescriptor .newAutomaticModule ("_" )
107
108
.requires ("java.base" )
@@ -113,19 +114,21 @@ public void testOutputDirectoryDescriptor() throws Exception {
113
114
assertEquals (expectedRequires , descriptor .requires ());
114
115
}
115
116
116
- @ Test (expected = NoSuchFileException .class )
117
- public void testClassicOutputDirectory () throws Exception {
118
- parser .getModuleDescriptor (Paths .get ("src/test/resources/dir.empty/out" ));
117
+ @ Test
118
+ void testClassicOutputDirectory () {
119
+ assertThrows (
120
+ NoSuchFileException .class ,
121
+ () -> parser .getModuleDescriptor (Paths .get ("src/test/resources/dir.empty/out" )));
119
122
}
120
123
121
124
@ Test
122
- public void testJModDescriptor () throws Exception {
125
+ void testJModDescriptor () throws Exception {
123
126
JavaModuleDescriptor descriptor = parser .getModuleDescriptor (
124
127
Paths .get ("src/test/resources/jmod.descriptor/first-jmod-1.0-SNAPSHOT.jmod" ));
125
128
126
129
assertNotNull (descriptor );
127
130
assertEquals ("com.corporate.project" , descriptor .name ());
128
- assertEquals ( false , descriptor .isAutomatic ());
131
+ assertFalse ( descriptor .isAutomatic ());
129
132
130
133
assertEquals (1 , descriptor .requires ().size ());
131
134
assertEquals ("java.base" , descriptor .requires ().iterator ().next ().name ());
@@ -135,13 +138,14 @@ public void testJModDescriptor() throws Exception {
135
138
"com.corporate.project" , descriptor .exports ().iterator ().next ().source ());
136
139
}
137
140
138
- @ Test (expected = IOException .class )
139
- public void testInvalidFile () throws Exception {
140
- parser .getModuleDescriptor (Paths .get ("src/test/resources/nonjar/pom.xml" ));
141
+ @ Test
142
+ void testInvalidFile () {
143
+ assertThrows (
144
+ IOException .class , () -> parser .getModuleDescriptor (Paths .get ("src/test/resources/nonjar/pom.xml" )));
141
145
}
142
146
143
147
@ Test
144
- public void testUses () throws Exception {
148
+ void testUses () throws Exception {
145
149
try (InputStream is =
146
150
Files .newInputStream (Paths .get ("src/test/resources/dir.descriptor.uses/out/module-info.class" ))) {
147
151
JavaModuleDescriptor descriptor = parser .parse (is );
@@ -157,7 +161,7 @@ public void testUses() throws Exception {
157
161
}
158
162
159
163
@ Test
160
- public void testProvides () throws Exception {
164
+ void testProvides () throws Exception {
161
165
JavaModuleDescriptor descriptor =
162
166
parser .getModuleDescriptor (Paths .get ("src/test/resources/jar.service/threeten-extra-1.4.jar" ));
163
167
@@ -182,21 +186,21 @@ public void testProvides() throws Exception {
182
186
}
183
187
184
188
@ Test
185
- public void testRequires () throws Exception {
189
+ void testRequires () throws Exception {
186
190
try (InputStream is =
187
191
Files .newInputStream (Paths .get ("src/test/resources/dir.descriptor.requires/out/module-info.class" ))) {
188
192
JavaModuleDescriptor descriptor = parser .parse (is );
189
193
190
194
assertNotNull (descriptor );
191
- assertThat (descriptor .requires (). size (), is ( 5 ) );
195
+ assertThat (descriptor .requires ()). hasSize ( 5 );
192
196
193
197
Set <JavaRequires > expectedRequires = JavaModuleDescriptor .newAutomaticModule ("_" )
194
198
.requires ("java.base" )
195
199
.requires ("mod_r" )
196
200
.requires (Collections .singleton (JavaRequires .JavaModifier .STATIC ), "mod_r_s" )
197
201
.requires (Collections .singleton (JavaRequires .JavaModifier .TRANSITIVE ), "mod_r_t" )
198
202
.requires (
199
- new HashSet <JavaRequires . JavaModifier >(Arrays .asList (
203
+ new HashSet <>(Arrays .asList (
200
204
JavaRequires .JavaModifier .STATIC , JavaRequires .JavaModifier .TRANSITIVE )),
201
205
"mod_r_s_t" )
202
206
.build ()
0 commit comments