Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
import org.apache.maven.model.Dependency;
import org.apache.maven.model.DependencyManagement;
import org.apache.maven.model.Exclusion;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.dependency.testUtils.DependencyArtifactStubFactory;
import org.apache.maven.plugins.dependency.testUtils.stubs.DependencyProjectStub;
import org.apache.maven.project.MavenProject;
Expand Down Expand Up @@ -192,60 +194,30 @@ public void testGetMismatch()
}

public void testMojo()
throws IOException
throws IOException, MojoExecutionException, MojoFailureException
{
mojo.setIgnoreDirect( false );
try
{
// test with nothing in depMgt
mojo.execute();
}
catch ( Exception e )
{
e.printStackTrace();
fail( "Caught Unexpected Exception:" + e.getLocalizedMessage() );
}
// test with nothing in depMgt
mojo.execute();

try
{
DependencyProjectStub project = (DependencyProjectStub) mojo.getProject();
project.setDependencyManagement( depMgt );
// test with exclusion
mojo.execute();
}
catch ( Exception e )
{
e.printStackTrace();
fail( "Caught Unexpected Exception:" + e.getLocalizedMessage() );
}
DependencyProjectStub project = (DependencyProjectStub) mojo.getProject();
project.setDependencyManagement( depMgt );
// test with exclusion
mojo.execute();

try
{
DependencyProjectStub project = (DependencyProjectStub) mojo.getProject();
project.setDependencyManagement( depMgt );
// test with exclusion
mojo.setFailBuild( true );
mojo.execute();
fail( "Expected exception to fail the build." );
}
catch ( Exception e )
catch ( MojoExecutionException e )
{
System.out.println( "Caught Expected Exception:" + e.getLocalizedMessage() );
}

try
{
DependencyProjectStub project = (DependencyProjectStub) mojo.getProject();
project.setDependencyManagement( depMgt );
// test with exclusion
mojo.setFailBuild( true );
mojo.setIgnoreDirect( true );
mojo.execute();
}
catch ( Exception e )
{
e.printStackTrace();
fail( "Caught Unexpected Exception:" + e.getLocalizedMessage() );
}
mojo.setFailBuild( true );
mojo.setIgnoreDirect( true );
mojo.execute();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ public void testRepositoryLayout()

File outputDirectory = mojo.outputDirectory;
ArtifactRepository targetRepository =
new MavenArtifactRepository( "local", outputDirectory.toURL().toExternalForm(),
new MavenArtifactRepository( "local", outputDirectory.toURI().toString(),
new DefaultRepositoryLayout(), new ArtifactRepositoryPolicy(),
new ArtifactRepositoryPolicy() );

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,15 @@
import org.apache.maven.plugins.dependency.AbstractDependencyMojoTestCase;
import org.apache.maven.project.MavenProject;
import org.apache.maven.shared.artifact.filter.resolve.Node;
import org.hamcrest.MatcherAssert;
import org.mockito.ArgumentCaptor;

import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

import static java.util.Collections.singletonList;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.containsString;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
Expand Down Expand Up @@ -79,9 +78,7 @@ public Dependency getDependency() {
}
};

final boolean result = filter.accept( node , Collections.<Node>emptyList() );

assertThat( result, is( false ));
assertFalse( filter.accept( node , Collections.<Node>emptyList() ) );
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a bad practice, here again.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you be more specific?

}

public void testRejectWithLogging()
Expand Down Expand Up @@ -124,7 +121,7 @@ public Dependency getDependency() {

ArgumentCaptor<String> captor = ArgumentCaptor.forClass( String.class );
verify( log ).debug( captor.capture() );
assertThat( captor.getValue(), containsString( "Skipped dependency" ) );
MatcherAssert.assertThat( captor.getValue(), containsString( "Skipped dependency" ) );
Copy link

@Tibor17 Tibor17 Mar 8, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

static import

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

}

public void testAccept()
Expand Down Expand Up @@ -163,8 +160,6 @@ public Dependency getDependency() {
}
};

final boolean result = filter.accept( node , Collections.<Node>emptyList() );

assertThat( result, is( true ));
assertTrue( filter.accept( node , Collections.<Node>emptyList() ) );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,6 @@ public class DependencyProjectStub

private List<ArtifactRepository> pluginArtifactRepositories;

// private ArtifactRepository releaseArtifactRepository;

// private ArtifactRepository snapshotArtifactRepository;

private List<Profile> activeProfiles;

private Set<Artifact> dependencyArtifacts;
Expand All @@ -108,20 +104,8 @@ public class DependencyProjectStub

private Artifact artifact;

// private Map artifactMap;

private Model originalModel;

// private Map pluginArtifactMap;

// private Map reportArtifactMap;

// private Map extensionArtifactMap;

// private Map projectReferences;

// private Build buildOverlay;

private boolean executionRoot;

private List<Artifact> compileArtifacts;
Expand Down Expand Up @@ -422,36 +406,6 @@ public void setScriptSourceRoots( List<String> scriptSourceRoots )
this.scriptSourceRoots = scriptSourceRoots;
}

public void setArtifactMap( Map artifactMap )
{
// this.artifactMap = artifactMap;
}

public void setPluginArtifactMap( Map pluginArtifactMap )
{
// this.pluginArtifactMap = pluginArtifactMap;
}

public void setReportArtifactMap( Map reportArtifactMap )
{
// this.reportArtifactMap = reportArtifactMap;
}

public void setExtensionArtifactMap( Map extensionArtifactMap )
{
// this.extensionArtifactMap = extensionArtifactMap;
}

public void setProjectReferences( Map projectReferences )
{
// this.projectReferences = projectReferences;
}

public void setBuildOverlay( Build buildOverlay )
{
// this.buildOverlay = buildOverlay;
}

public void setCompileDependencies( List<Dependency> compileDependencies )
{
this.compileDependencies = compileDependencies;
Expand Down Expand Up @@ -657,6 +611,7 @@ public Scm getScm()
return null;
}

@Override
public void setMailingLists( List list )
{

Expand All @@ -672,6 +627,7 @@ public void addMailingList( MailingList mailingList )

}

@Override
public void setDevelopers( List list )
{

Expand Down Expand Up @@ -993,6 +949,7 @@ public List<Extension> getBuildExtensions()
return Collections.emptyList();
}

@Override
public Set<Artifact> createArtifacts( ArtifactFactory artifactFactory, String string, ArtifactFilter artifactFilter )
throws InvalidDependencyVersionException
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,7 @@
import org.apache.maven.plugin.testing.stubs.StubArtifactRepository;
import org.apache.maven.plugins.dependency.AbstractDependencyMojoTestCase;
import org.apache.maven.plugins.dependency.testUtils.DependencyArtifactStubFactory;
import org.apache.maven.project.ProjectBuildingRequest;
import org.apache.maven.shared.transfer.artifact.ArtifactCoordinate;
import org.apache.maven.shared.transfer.repository.RepositoryManager;
import org.sonatype.aether.impl.internal.SimpleLocalRepositoryManager;
import org.sonatype.aether.util.DefaultRepositorySystemSession;

Expand All @@ -57,10 +55,6 @@ public class TestClassifierTypeTranslator

Log log = new SilentLog();

private RepositoryManager repoManager;

private ProjectBuildingRequest buildingRequest;

private ArtifactHandlerManager artifactHandlerManager;

protected void setUp()
Expand All @@ -79,10 +73,7 @@ protected void setUp()
DependencyArtifactStubFactory factory = new DependencyArtifactStubFactory( null, false );
artifacts = factory.getMixedArtifacts();

repoManager = lookup( RepositoryManager.class );

MavenSession session = newMavenSession( new MavenProjectStub() );
buildingRequest = session.getProjectBuildingRequest();

DefaultRepositorySystemSession repoSession = (DefaultRepositorySystemSession) session.getRepositorySession();
repoSession.setLocalRepositoryManager( new SimpleLocalRepositoryManager( stubFactory.getWorkingDir() ) );
Expand Down