protected void setUp() throws Exception { super.setUp("unpack", true); File testPom = new File(getBasedir(), "target/test-classes/unit/unpack-test/plugin-config.xml"); mojo = (UnpackMojo) lookupMojo("unpack", testPom); mojo.setOutputDirectory(new File(this.testDir, "outputDirectory")); mojo.setMarkersDirectory(new File(this.testDir, "markers")); setSilent(mojo, true); assertNotNull(mojo); assertNotNull(mojo.getProject()); // MavenProject project = mojo.getProject(); // init classifier things // it needs to get the archivermanager stubFactory.setUnpackableFile(mojo.getArchiverManager()); // i'm using one file repeatedly to archive so I can test the name // programmatically. stubFactory.setSrcFile( new File( getBasedir() + File.separatorChar + "target/test-classes/unit/unpack-dependencies-test/test.txt")); mojo.setFactory(DependencyTestUtils.getArtifactFactory()); mojo.setResolver(new StubArtifactResolver(stubFactory, false, false)); mojo.setLocal(new StubArtifactRepository(this.testDir.getAbsolutePath())); mojo.setArtifactCollector(new StubArtifactCollector()); mojo.setUseJvmChmod(true); }
public void dotestArtifactExceptions(boolean are, boolean anfe) throws Exception { ArtifactItem item = new ArtifactItem(); item.setArtifactId("artifactId"); item.setClassifier(""); item.setGroupId("groupId"); item.setType("type"); item.setVersion("1.0"); List<ArtifactItem> list = new ArrayList<ArtifactItem>(); list.add(item); mojo.setArtifactItems(list); // init classifier things mojo.setFactory(DependencyTestUtils.getArtifactFactory()); mojo.setResolver(new StubArtifactResolver(null, are, anfe)); mojo.setLocal(new StubArtifactRepository(this.testDir.getAbsolutePath())); try { mojo.execute(); fail("ExpectedException"); } catch (MojoExecutionException e) { if (are) { assertEquals("Unable to resolve artifact.", e.getMessage()); } else { assertEquals("Unable to find artifact.", e.getMessage()); } } }