LocalRepositoryCollector { public String findLocalRepository( String filePath ) { String localRepositoryPathFound = null; for ( String localRepositoryPath : localRepositoryPaths ) { if ( filePath.startsWith( localRepositoryPath ) ) { localRepositoryPathFound = localRepositoryPath; break; } } return localRepositoryPathFound; } LocalRepositoryCollector( MavenProject project, //
                                     ArtifactRepository localRepository, File[] additionalFolderBases ); String findLocalRepository( String filePath ); void addLocalRepositoryPath( String path );  }
@Test public void testNoParentProject() { File wwwZipBase = mock( File.class ); File wwwZipFile = mock( File.class ); when( project.getParent() ).thenReturn( null ); when( wwwZipBase.listFiles() ).thenReturn( new File[] { wwwZipFile } ); when( wwwZipFile.isDirectory() ).thenReturn( true ); when( wwwZipFile.getAbsolutePath() ).thenReturn( "d/e/f" ); LocalRepositoryCollector collector = new LocalRepositoryCollector( project, localRepository, new File[] { wwwZipBase } ); verify( project, times( 1 ) ).getArtifactId(); verify( project, times( 1 ) ).getParent(); String localRepositoryFound = collector.findLocalRepository( "a/b/c/d" ); assertEquals( localRepositoryBaseDir, localRepositoryFound ); localRepositoryFound = collector.findLocalRepository( "d/e/f/z" ); assertEquals( "d/e/f", localRepositoryFound ); localRepositoryFound = collector.findLocalRepository( "a/b/d/d" ); assertNull( localRepositoryFound ); }
@Test public void testWithParentProject() { MavenProject parentProject = mock( MavenProject.class ); when( project.getParent() ).thenReturn( parentProject ); List<String> modules = new ArrayList<String>( 1 ); modules.add( artifactId ); when( parentProject.getModules() ).thenReturn( modules ); when( parentProject.getArtifactId() ).thenReturn( "anotherArtifactId" ); String parentLocalRepositoryBaseDir = "x/y/z"; File parentLocalRepositoryBaseDirFile = mock( File.class ); when( parentLocalRepositoryBaseDirFile.getAbsolutePath() ).thenReturn( parentLocalRepositoryBaseDir ); when( parentProject.getBasedir() ).thenReturn( parentLocalRepositoryBaseDirFile ); when( parentProject.getParent() ).thenReturn( null ); LocalRepositoryCollector collector = new LocalRepositoryCollector( project, localRepository, new File[] {} ); verify( parentProject, times( 1 ) ).getModules(); verify( parentProject, times( 1 ) ).getArtifactId(); verify( parentProject, times( 1 ) ).getBasedir(); verify( parentProject, times( 1 ) ).getParent(); verify( parentLocalRepositoryBaseDirFile, times( 1 ) ).getAbsolutePath(); String localRepositoryFound = collector.findLocalRepository( "x/y/z/d" ); assertEquals( parentLocalRepositoryBaseDir, localRepositoryFound ); }