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 wildcardMatch() {
        artifactFilter.groupId = "com.mahifx";
        artifactFilter.artifactId = "*";
        Assert.assertTrue(artifactFilter.match(getArtifact()));
    }

    @Test
    public void noMatch() {
        artifactFilter.groupId = "com.mahifx";
        artifactFilter.artifactId = "libB";
        Assert.assertFalse(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
    public void emptyArtifactDoesNotMatch() {
        artifactFilter.groupId = "com.mahifx";
        artifactFilter.artifactId = "";
        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());
    }
}

@@ -392,16 +392,10 @@
 oid 
-wildcard
+no
 Matc
@@ -484,17 +484,20 @@
 ctId = %22
-*
+libB
 %22;%0A     
@@ -504,35 +504,36 @@
    Assert.assert
-Tru
+Fals
 e(artifactFilter
@@ -581,34 +581,52 @@
     public void 
-no
+emptyArtifactDoesNot
 Match() %7B%0A      
@@ -695,36 +695,32 @@
 r.artifactId = %22
-libB
 %22;%0A        Asser
@@ -770,32 +770,235 @@
 act()));%0A    %7D%0A%0A
+    @Test%0A    public void wildcardMatch() %7B%0A        artifactFilter.groupId = %22com.mahifx%22;%0A        artifactFilter.artifactId = %22*%22;%0A        Assert.assertTrue(artifactFilter.match(getArtifact()));%0A    %7D%0A%0A
     @Test%0A    pu
@@ -1618,223 +1618,8 @@
  %7D%0A%0A
-    @Test%0A    public void emptyArtifactDoesNotMatch() %7B%0A        artifactFilter.groupId = %22com.mahifx%22;%0A        artifactFilter.artifactId = %22%22;%0A        Assert.assertFalse(artifactFilter.match(getArtifact()));%0A    %7D%0A%0A
     

Move regex/wildcards tests together