package com.github.wvengen.maven.proguard;


import org.apache.maven.artifact.DefaultArtifact;
import org.apache.maven.artifact.handler.DefaultArtifactHandler;
import org.apache.maven.artifact.versioning.VersionRange;
import org.junit.Assert;
import org.junit.Test;

public class ArtifactFilterTest {

    private ArtifactFilter artifactFilter = new ArtifactFilter();

    @Test
    public void noMatch() {
        artifactFilter.groupId = "com.mahifx";
        artifactFilter.artifactId = "libB";
        Assert.assertFalse(artifactFilter.match(getArtifact()));
    }

    @Test
    public void emptyArtifactDoesNotMatch() {
        artifactFilter.groupId = "com.mahifx";
        artifactFilter.artifactId = "";
        Assert.assertFalse(artifactFilter.match(getArtifact()));
    }

    @Test
    public void wildcardMatch() {
        artifactFilter.groupId = "com.mahifx";
        artifactFilter.artifactId = "*";
        Assert.assertTrue(artifactFilter.match(getArtifact()));
    }

    @Test
    public void noMatchWithRegexTokens() {
        artifactFilter.groupId = "com.mahifx";
        artifactFilter.artifactId = "libB-utils";
        Assert.assertFalse(artifactFilter.match(getArtifact()));
    }

    @Test
    public void regexMatch() {
        artifactFilter.groupId = "com.mahifx";
        artifactFilter.artifactId = "lib.*";
        Assert.assertTrue(artifactFilter.match(getArtifact()));
    }

    @Test
    public void regexNoMatch() {
        artifactFilter.groupId = "com.mahifx";
        artifactFilter.artifactId = "foo.+";
        Assert.assertFalse(artifactFilter.match(getArtifact()));
    }

    @Test(expected = IllegalArgumentException.class)
    public void invalidRegex() {
        artifactFilter.groupId = "com.mahifx";
        artifactFilter.artifactId = "+";
        artifactFilter.match(getArtifact());
    }


    private DefaultArtifact getArtifact() {
        return new DefaultArtifact("com.mahifx", "libA", VersionRange.createFromVersion("1.0.0"), "compile", "jar", null, new DefaultArtifactHandler());
    }
}

@@ -38,16 +38,59 @@
 uard;%0A%0A%0A
+import org.apache.maven.artifact.Artifact;%0A
 import o
@@ -856,24 +856,36 @@
 ildcardMatch
+_allArtifact
 () %7B%0A       
@@ -1066,30 +1066,36 @@
 oid 
-noMatchWithRegexTokens
+wildcardMatch_partOfArtifact
 () %7B
@@ -1186,15 +1186,9 @@
 %22lib
-B-utils
+*
 %22;%0A 
@@ -1199,36 +1199,35 @@
    Assert.assert
-Fals
+Tru
 e(artifactFilter
@@ -1287,18 +1287,40 @@
 oid 
-regexMatch
+wildcardMatch_escapeArtifactDots
 () %7B
@@ -1406,17 +1406,16 @@
 Id = %22li
-b
 .*%22;%0A   
@@ -1424,158 +1424,40 @@
    A
-ssert.assertTrue(artifactFilter.match(getArtifact()));%0A    %7D%0A%0A    @Test%0A    public void regexNoMatch() %7B%0A        artifactFilter.groupId = %22com.mahifx%22
+rtifact artifact = getArtifact()
 ;%0A  
@@ -1466,32 +1466,29 @@
     artifact
-Filter.a
+.setA
 rtifactId = 
@@ -1488,18 +1488,16 @@
 ctId
- = %22foo.+%22
+(%22li.b%22)
 ;%0A  
@@ -1507,36 +1507,35 @@
    Assert.assert
-Fals
+Tru
 e(artifactFilter
@@ -1537,37 +1537,32 @@
 ilter.match(
-getA
+a
 rtifact
-()
 ));%0A    %7D%0A%0A 
@@ -1573,80 +1573,47 @@
 Test
-(expected = IllegalArgumentException.class)%0A    public void invalidRegex
+%0A    public void noMatchWithRegexTokens
 () %7B
@@ -1701,9 +1701,18 @@
  = %22
-+
+libB-utils
 %22;%0A 
@@ -1710,32 +1710,51 @@
 utils%22;%0A        
+Assert.assertFalse(
 artifactFilter.m
@@ -1772,16 +1772,17 @@
 ifact())
+)
 ;%0A    %7D%0A
@@ -1782,17 +1782,16 @@
 %0A    %7D%0A%0A
-%0A
     priv

Update tests