MavenUrlResolver extends DefaultUrlResolver { @Override public ResolvedFile resolve( String url ) throws IOException { ResolvedFile resolvedFile; if( url.toLowerCase().startsWith( "mvn:" )) { if( this.mavenResolver == null ) throw new IOException( "No Maven resolver was available." ); this.logger.fine( "Resolving a Maven URL: " + url ); File f = this.mavenResolver.resolve( url ); resolvedFile = new ResolvedFile( f, false ); } else { resolvedFile = super.resolve( url ); } return resolvedFile; } MavenUrlResolver( MavenResolver mavenResolver ); @Override ResolvedFile resolve( String url );  }
@Test public void testResolve_fileUrl() throws Exception { MavenUrlResolver mavenUrlResolver = new MavenUrlResolver( null ); File f = this.folder.newFile(); ResolvedFile resolvedFile = mavenUrlResolver.resolve( f.toURI().toURL().toString()); Assert.assertEquals( f, resolvedFile.getFile()); Assert.assertTrue( resolvedFile.existedBefore()); }
@Test public void testResolve_mavenUrl() throws Exception { MavenResolver mavenResolver = Mockito.mock( MavenResolver.class ); MavenUrlResolver mavenUrlResolver = new MavenUrlResolver( mavenResolver ); File f = new File( "test" ); Mockito.when( mavenResolver.resolve( Mockito.anyString())).thenReturn( f ); String url = "mvn:net.roboconf/my-app/1.0"; ResolvedFile resolvedFile = mavenUrlResolver.resolve( url ); Assert.assertEquals( f, resolvedFile.getFile()); Assert.assertFalse( resolvedFile.existedBefore()); Mockito.verify( mavenResolver ).resolve( url ); }
@Test( expected = IOException.class ) public void testResolve_noMavenResolver() throws Exception { MavenUrlResolver mavenUrlResolver = new MavenUrlResolver( null ); mavenUrlResolver.resolve( "mvn:net.roboconf/my-app/1.0" ); }