@@ -161,6 +161,36 @@ void testIdenticalModuleNames() throws Exception {
161161 ResolvePathsRequest <Path > request =
162162 ResolvePathsRequest .ofPaths (Arrays .asList (pj1 , pj2 )).setMainModuleDescriptor (mockModuleInfoJava );
163163
164+ when (asmParser .getModuleDescriptor (pj1 ))
165+ .thenReturn (JavaModuleDescriptor .newModule ("plexus.java" ).build ());
166+ when (asmParser .getModuleDescriptor (pj2 ))
167+ .thenReturn (JavaModuleDescriptor .newModule ("plexus.java" ).build ());
168+
169+ ResolvePathsResult <Path > result = locationManager .resolvePaths (request );
170+
171+ assertThat (result .getMainModuleDescriptor ()).isEqualTo (descriptor );
172+ assertThat (result .getPathElements ()).hasSize (2 );
173+ assertThat (result .getModulepathElements ()).hasSize (1 );
174+ assertThat (result .getModulepathElements ()).containsKey (pj1 );
175+ assertThat (result .getModulepathElements ()).doesNotContainKey (pj2 );
176+ assertThat (result .getClasspathElements ()).isEmpty ();
177+ // duplicate is flagged as an error
178+ assertThat (result .getPathExceptions ()).containsOnlyKeys (pj2 );
179+ assertThat (result .getPathExceptions ().get (pj2 ))
180+ .isInstanceOf (IllegalStateException .class )
181+ .hasMessageContaining ("Module 'plexus.java' is already on the module path!" );
182+ }
183+
184+ @ Test
185+ public void testIdenticalAutomaticModuleNames () throws Exception {
186+ Path pj1 = Paths .get ("src/test/resources/jar.empty/plexus-java-1.0.0-SNAPSHOT.jar" );
187+ Path pj2 = Paths .get ("src/test/resources/jar.empty.2/plexus-java-2.0.0-SNAPSHOT.jar" );
188+ JavaModuleDescriptor descriptor =
189+ JavaModuleDescriptor .newModule ("base" ).requires ("plexus.java" ).build ();
190+ when (qdoxParser .fromSourcePath (any (Path .class ))).thenReturn (descriptor );
191+ ResolvePathsRequest <Path > request =
192+ ResolvePathsRequest .ofPaths (Arrays .asList (pj1 , pj2 )).setMainModuleDescriptor (mockModuleInfoJava );
193+
164194 when (asmParser .getModuleDescriptor (pj1 ))
165195 .thenReturn (
166196 JavaModuleDescriptor .newAutomaticModule ("plexus.java" ).build ());
@@ -173,8 +203,42 @@ void testIdenticalModuleNames() throws Exception {
173203 assertThat (result .getPathElements ()).hasSize (2 );
174204 assertThat (result .getModulepathElements ()).containsOnlyKeys (pj1 );
175205 assertThat (result .getModulepathElements ()).doesNotContainKey (pj2 );
176- assertThat (result .getClasspathElements ()).hasSize (0 );
177- assertThat (result .getPathExceptions ()).hasSize (0 );
206+ assertThat (result .getClasspathElements ()).isEmpty ();
207+ // duplicate is flagged as an error
208+ assertThat (result .getPathExceptions ()).containsOnlyKeys (pj2 );
209+ assertThat (result .getPathExceptions ().get (pj2 ))
210+ .isInstanceOf (IllegalStateException .class )
211+ .hasMessageContaining ("Module 'plexus.java' is already on the module path!" );
212+ }
213+
214+ @ Test
215+ public void testMainJarModuleAndTestJarAutomatic () throws Exception {
216+ Path pj1 = Paths .get ("src/test/resources/jar.tests/plexus-java-1.0.0-SNAPSHOT.jar" );
217+ Path pj2 = Paths .get ("src/test/resources/jar.tests/plexus-java-1.0.0-SNAPSHOT-tests.jar" );
218+ JavaModuleDescriptor descriptor =
219+ JavaModuleDescriptor .newModule ("base" ).requires ("plexus.java" ).build ();
220+ when (qdoxParser .fromSourcePath (any (Path .class ))).thenReturn (descriptor );
221+ ResolvePathsRequest <Path > request =
222+ ResolvePathsRequest .ofPaths (Arrays .asList (pj1 , pj2 )).setMainModuleDescriptor (mockModuleInfoJava );
223+
224+ when (asmParser .getModuleDescriptor (pj1 ))
225+ .thenReturn (JavaModuleDescriptor .newModule ("plexus.java" ).build ());
226+ when (asmParser .getModuleDescriptor (pj2 )).thenReturn (null );
227+
228+ ResolvePathsResult <Path > result = locationManager .resolvePaths (request );
229+
230+ assertThat (result .getMainModuleDescriptor ()).isEqualTo (descriptor );
231+ assertThat (result .getPathElements ()).hasSize (2 );
232+ assertThat (result .getModulepathElements ()).hasSize (1 );
233+ assertThat (result .getModulepathElements ()).containsKey (pj1 );
234+ assertThat (result .getModulepathElements ()).doesNotContainKey (pj2 );
235+ assertThat (result .getClasspathElements ()).isEmpty ();
236+
237+ // duplicate is flagged as an error
238+ assertThat (result .getPathExceptions ()).containsOnlyKeys (pj2 );
239+ assertThat (result .getPathExceptions ().get (pj2 ))
240+ .isInstanceOf (IllegalStateException .class )
241+ .hasMessageContaining ("Module 'plexus.java' is already on the module path!" );
178242 }
179243
180244 @ Test
@@ -473,9 +537,13 @@ void testDuplicateModule() throws Exception {
473537 ResolvePathsResult <Path > result = locationManager .resolvePaths (request );
474538 assertThat (result .getPathElements ()).hasSize (2 );
475539 assertThat (result .getModulepathElements ()).containsOnlyKeys (moduleB );
476- // with current default the duplicate will be ignored
477540 assertThat (result .getClasspathElements ()).hasSize (0 );
478- assertThat (result .getPathExceptions ()).hasSize (0 );
541+ assertThat (result .getPathExceptions ()).hasSize (1 );
542+ // duplicate (module B / module C) is flagged as an error
543+ assertThat (result .getPathExceptions ()).containsOnlyKeys (moduleC );
544+ assertThat (result .getPathExceptions ().get (moduleC ))
545+ .isInstanceOf (IllegalStateException .class )
546+ .hasMessageContaining ("Module 'anonymous' is already on the module path!" );
479547 }
480548
481549 @ Test
0 commit comments