PatternInclusionsDependencyFilter implements DependencyFilter { public boolean accept( final DependencyNode node, List<DependencyNode> parents ) { final Dependency dependency = node.getDependency(); if ( dependency == null ) { return true; } final Artifact artifact = dependency.getArtifact(); for ( final String pattern : patterns ) { final boolean matched = accept( artifact, pattern ); if ( matched ) { return true; } } return false; } PatternInclusionsDependencyFilter( final String... patterns );  PatternInclusionsDependencyFilter( final VersionScheme versionScheme, final String... patterns );  PatternInclusionsDependencyFilter( final Collection<String> patterns );  PatternInclusionsDependencyFilter( final VersionScheme versionScheme, final Collection<String> patterns ); boolean accept( final DependencyNode node, List<DependencyNode> parents ); @Override boolean equals( final Object obj ); @Override int hashCode();  }
@Test public void acceptTestCornerCases() { NodeBuilder builder = new NodeBuilder(); builder.artifactId( "testArtifact" ); DependencyNode node = builder.build(); List<DependencyNode> parents = new LinkedList<DependencyNode>(); assertTrue( accept( node, "" ) ); assertFalse( new PatternInclusionsDependencyFilter( new LinkedList<String>() ).accept( node, parents ) ); assertFalse( new PatternInclusionsDependencyFilter( (String[]) null ).accept( node, parents ) ); assertFalse( new PatternInclusionsDependencyFilter( (VersionScheme) null, "[1,10]" ).accept( node, parents ) ); }
@Test public void acceptTestMatches() { NodeBuilder builder = new NodeBuilder(); builder.groupId( "com.example.test" ).artifactId( "testArtifact" ).ext( "jar" ).version( "1.0.3" ); DependencyNode node = builder.build(); assertEquals( "com.example.test:testArtifact:jar:1.0.3", true, accept( node, "com.example.test:testArtifact:jar:1.0.3" ) ); assertEquals( "*:testArtifact:jar:1.0.3", true, accept( node, "*:testArtifact:jar:1.0.3" ) ); assertEquals( "com.example.test:*:jar:1.0.3", true, accept( node, "com.example.test:*:jar:1.0.3" ) ); assertEquals( "com.example.test:testArtifact:*:1.0.3", true, accept( node, "com.example.test:testArtifact:*:1.0.3" ) ); assertEquals( "com.example.test:testArtifact:*:1.0.3", true, accept( node, "com.example.test:testArtifact:*:1.0.3" ) ); assertEquals( ":testArtifact:jar:1.0.3", true, accept( node, ":testArtifact:jar:1.0.3" ) ); assertEquals( "com.example.test::jar:1.0.3", true, accept( node, "com.example.test::jar:1.0.3" ) ); assertEquals( "com.example.test:testArtifact::1.0.3", true, accept( node, "com.example.test:testArtifact::1.0.3" ) ); assertEquals( "com.example.test:testArtifact:jar:", true, accept( node, "com.example.test:testArtifact:jar:" ) ); assertEquals( "*:*:jar:1.0.3", true, accept( node, "*:*:jar:1.0.3" ) ); assertEquals( "com.example.test:*:*:1.0.3", true, accept( node, "com.example.test:*:*:1.0.3" ) ); assertEquals( "com.example.test:testArtifact:*:*", true, accept( node, "com.example.test:testArtifact:*:*" ) ); assertEquals( "*:testArtifact:jar:*", true, accept( node, "*:testArtifact:jar:*" ) ); assertEquals( "*:*:jar:*", true, accept( node, "*:*:jar:*" ) ); assertEquals( ":*:jar:", true, accept( node, ":*:jar:" ) ); assertEquals( "*.example.test:testArtifact:jar:1.0.3", true, accept( node, "*.example.test:testArtifact:jar:1.0.3" ) ); assertEquals( "com.example.test:testArtifact:*ar:1.0.*", true, accept( node, "com.example.test:testArtifact:*ar:1.0.*" ) ); assertEquals( "com.example.test:testArtifact:jar:1.0.*", true, accept( node, "com.example.test:testArtifact:jar:1.0.*" ) ); assertEquals( "*.example.*:testArtifact:jar:1.0.3", true, accept( node, "*.example.*:testArtifact:jar:1.0.3" ) ); assertEquals( "com.example.test*:testArtifact:jar:1.0.3", true, accept( node, "com.example.test*:testArtifact:jar:1.0.3" ) ); }
@Test public void acceptTestLessToken() { NodeBuilder builder = new NodeBuilder(); builder.groupId( "com.example.test" ).artifactId( "testArtifact" ).ext( "jar" ).version( "1.0.3" ); DependencyNode node = builder.build(); assertEquals( "com.example.test:testArtifact:jar", true, accept( node, "com.example.test:testArtifact:jar" ) ); assertEquals( "com.example.test:testArtifact", true, accept( node, "com.example.test:testArtifact" ) ); assertEquals( "com.example.test", true, accept( node, "com.example.test" ) ); assertEquals( "com.example.foo", false, accept( node, "com.example.foo" ) ); }
@Test public void acceptTestMissmatch() { NodeBuilder builder = new NodeBuilder(); builder.groupId( "com.example.test" ).artifactId( "testArtifact" ).ext( "jar" ).version( "1.0.3" ); DependencyNode node = builder.build(); assertEquals( "OTHER.GROUP.ID:testArtifact:jar:1.0.3", false, accept( node, "OTHER.GROUP.ID:testArtifact:jar:1.0.3" ) ); assertEquals( "com.example.test:OTHER_ARTIFACT:jar:1.0.3", false, accept( node, "com.example.test:OTHER_ARTIFACT:jar:1.0.3" ) ); assertEquals( "com.example.test:OTHER_ARTIFACT:jar:1.0.3", false, accept( node, "com.example.test:OTHER_ARTIFACT:jar:1.0.3" ) ); assertEquals( "com.example.test:testArtifact:WAR:1.0.3", false, accept( node, "com.example.test:testArtifact:WAR:1.0.3" ) ); assertEquals( "com.example.test:testArtifact:jar:SNAPSHOT", false, accept( node, "com.example.test:testArtifact:jar:SNAPSHOT" ) ); assertEquals( "*:*:war:*", false, accept( node, "*:*:war:*" ) ); assertEquals( "OTHER.GROUP.ID", false, accept( node, "OTHER.GROUP.ID" ) ); }
@Test public void acceptTestMoreToken() { NodeBuilder builder = new NodeBuilder(); builder.groupId( "com.example.test" ).artifactId( "testArtifact" ).ext( "jar" ).version( "1.0.3" ); DependencyNode node = builder.build(); assertEquals( "com.example.test:testArtifact:jar:1.0.3:foo", false, accept( node, "com.example.test:testArtifact:jar:1.0.3:foo" ) ); }