package japicmp.test;

import japicmp.cmp.JarArchiveComparator;
import japicmp.cmp.JarArchiveComparatorOptions;
import japicmp.filter.AnnotationFilter;
import japicmp.model.JApiChangeStatus;
import japicmp.model.JApiClass;
import japicmp.test.annotation.filter.AnnotatedClass;
import org.junit.Assert;
import org.junit.Test;

import java.util.List;

import static japicmp.test.util.Helper.getArchive;
import static japicmp.test.util.Helper.getJApiClass;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;

/**
 * Test to ensure that annotation-based includes and excludes are working.
 */
public class AnnotationFilterTest {

    @Test
    public void testFilterSelection() {
        JarArchiveComparatorOptions options = new JarArchiveComparatorOptions();
        options.getFilters().getIncludes().add(new AnnotationFilter("@japicmp.test.annotation.filter.PublicAPI"));
        JarArchiveComparator jarArchiveComparator = new JarArchiveComparator(options);
        List<JApiClass> jApiClasses = jarArchiveComparator.compare(getArchive("japicmp-test-v1.jar"), getArchive("japicmp-test-v2.jar"));
        getJApiClass(jApiClasses, AnnotatedClass.class.getName());
        assertThat(jApiClasses.size(), is(1));
    }


    @Test
    public void detectChangeOnAnnotatedClass() {
        JarArchiveComparatorOptions options = new JarArchiveComparatorOptions();
        options.getFilters().getIncludes().add(new AnnotationFilter("@japicmp.test.annotation.filter.PublicAPI"));
        JarArchiveComparator jarArchiveComparator = new JarArchiveComparator(options);
        final List<JApiClass> jApiClasses = jarArchiveComparator.compare(getArchive("japicmp-test-v1.jar"), getArchive("japicmp-test-v2.jar"));
		Assert.assertEquals(1, jApiClasses.size());
		Assert.assertEquals(JApiChangeStatus.MODIFIED, jApiClasses.get(0).getChangeStatus());
    }


    private interface Callback {
        void callback();
    }

    private void assertThatExceptionIsThrown(Callback callback) {
        boolean exception = false;
        try {
            callback.callback();
        } catch (Exception e) {
            exception = true;
        }
        assertThat(exception, is(true));
    }
}

@@ -655,30 +655,24 @@
 Test %7B%0A%0A
-    
+%09
 @Test%0A
-    
+%09
 public v
@@ -695,32 +695,26 @@
 lection() %7B%0A
-        
+%09%09
 JarArchiveCo
@@ -770,32 +770,26 @@
 rOptions();%0A
-        
+%09%09
 options.getF
@@ -879,32 +879,26 @@
 blicAPI%22));%0A
-        
+%09%09
 JarArchiveCo
@@ -964,24 +964,18 @@
 tions);%0A
-        
+%09%09
 List%3CJAp
@@ -1096,24 +1096,18 @@
 jar%22));%0A
-        
+%09%09
 getJApiC
@@ -1157,24 +1157,18 @@
 ame());%0A
-        
+%09%09
 assertTh
@@ -1202,30 +1202,21 @@
 ));%0A
-    %7D%0A%0A%0A    
+%09%7D%0A%0A%0A%09
 @Test%0A
-    
+%09
 publ
@@ -1256,24 +1256,18 @@
 ass() %7B%0A
-        
+%09%09
 JarArchi
@@ -1331,24 +1331,18 @@
 ions();%0A
-        
+%09%09
 options.
@@ -1440,24 +1440,18 @@
 API%22));%0A
-        
+%09%09
 JarArchi
@@ -1521,24 +1521,18 @@
 tions);%0A
-        
+%09%09
 final Li
@@ -1797,20 +1797,14 @@
 ));%0A
-    %7D%0A%0A%0A    
+%09%7D%0A%0A%0A%09
 priv
@@ -1828,24 +1828,18 @@
 lback %7B%0A
-        
+%09%09
 void cal
@@ -1851,19 +1851,13 @@
 ();%0A
-    %7D%0A%0A    
+%09%7D%0A%0A%09
 priv
@@ -1914,24 +1914,18 @@
 back) %7B%0A
-        
+%09%09
 boolean 
@@ -1947,34 +1947,19 @@
 se;%0A
-        try %7B%0A            
+%09%09try %7B%0A%09%09%09
 call
@@ -1975,24 +1975,18 @@
 back();%0A
-        
+%09%09
 %7D catch 
@@ -2005,20 +2005,11 @@
 ) %7B%0A
-            
+%09%09%09
 exce
@@ -2026,26 +2026,14 @@
 ue;%0A
-        %7D%0A        
+%09%09%7D%0A%09%09
 asse
@@ -2065,12 +2065,9 @@
 ));%0A
-    
+%09
 %7D%0A%7D%0A

use tabs instead of spaces