package loc;

import loc.filter.Filter;
import loc.statistics.Statistics;
import loc.statistics.StatisticsCollector;
import org.junit.Test;

import java.nio.file.Files;
import java.nio.file.Paths;

import static org.junit.Assert.*;

public class StatisticsCollectorTest {
    @Test (expected = StatisticsCollector.NoFilterException.class)
    public void noFilter() throws Exception {
        new StatisticsCollector(new Statistics(), new Filter[0]);
    }

    @Test
    public void custom() throws Exception {
        Statistics statistics = new Statistics();
        Filter[] filters = ConfigFileReader.readFilters(Paths.get("input/filters"));
        StatisticsCollector collector = new StatisticsCollector(statistics, filters);
        Files.walkFileTree(Paths.get("input/dir"), collector);
        assertEquals(4, statistics.totalFiles());
        assertEquals(10, statistics.getTotalLines());

        assertEquals(1, statistics.getFilterFileStatisticsMap().get(filters[0]).fileCount); // .cpp
        assertEquals(3, statistics.getFilterFileStatisticsMap().get(filters[0]).lineCount);
        assertEquals(1, statistics.getFilterFileStatisticsMap().get(filters[1]).fileCount); // .java
        assertEquals(4, statistics.getFilterFileStatisticsMap().get(filters[1]).lineCount);
        assertEquals(2, statistics.getFilterFileStatisticsMap().get(filters[2]).fileCount); // Or(.cpp, .java)
        assertEquals(7, statistics.getFilterFileStatisticsMap().get(filters[2]).lineCount);
        assertEquals(0, statistics.getFilterFileStatisticsMap().get(filters[3]).fileCount); // And(.cpp, .java)
        assertEquals(0, statistics.getFilterFileStatisticsMap().get(filters[3]).lineCount);
        assertEquals(10, statistics.getFilterFileStatisticsMap().get(filters[4]).fileCount); // >1287311235
        assertEquals(10, statistics.getFilterFileStatisticsMap().get(filters[4]).lineCount);
        assertEquals(0, statistics.getFilterFileStatisticsMap().get(filters[5]).fileCount); // <1287311235
        assertEquals(0, statistics.getFilterFileStatisticsMap().get(filters[5]).lineCount);
    }
}
@@ -265,20 +265,17 @@
 rTest %7B%0A
-    
+%09
 @Test (e
@@ -329,20 +329,17 @@
 .class)%0A
-    
+%09
 public v
@@ -372,24 +372,18 @@
 ption %7B%0A
-        
+%09%09
 new Stat
@@ -436,29 +436,20 @@
 %5D);%0A
-    %7D%0A%0A    
+%09%7D%0A%0A%09
 @Test%0A
-    
+%09
 publ
@@ -484,24 +484,18 @@
 ption %7B%0A
-        
+%09%09
 Statisti
@@ -528,24 +528,18 @@
 tics();%0A
-        
+%09%09
 Filter%5B%5D
@@ -607,24 +607,18 @@
 ers%22));%0A
-        
+%09%09
 Statisti
@@ -687,24 +687,18 @@
 lters);%0A
-        
+%09%09
 Files.wa
@@ -744,24 +744,18 @@
 ector);%0A
-        
+%09%09
 assertEq
@@ -788,24 +788,18 @@
 les());%0A
-        
+%09%09
 assertEq
@@ -837,24 +837,18 @@
 es());%0A%0A
-        
+%09%09
 assertEq
@@ -931,24 +931,18 @@
 // .cpp%0A
-        
+%09%09
 assertEq
@@ -1013,32 +1013,26 @@
 lineCount);%0A
-        
+%09%09
 assertEquals
@@ -1112,24 +1112,18 @@
 / .java%0A
-        
+%09%09
 assertEq
@@ -1194,32 +1194,26 @@
 lineCount);%0A
-        
+%09%09
 assertEquals
@@ -1291,24 +1291,22 @@
  // 
-Or
+%7C
 (.cpp
-,
  .java)%0A
     
@@ -1297,32 +1297,26 @@
 .cpp .java)%0A
-        
+%09%09
 assertEquals
@@ -1383,32 +1383,26 @@
 lineCount);%0A
-        
+%09%09
 assertEquals
@@ -1480,25 +1480,22 @@
  // 
-And
+&
 (.cpp
-,
  .java)%0A
     
@@ -1490,24 +1490,18 @@
  .java)%0A
-        
+%09%09
 assertEq
@@ -1572,32 +1572,26 @@
 lineCount);%0A
-        
+%09%09
 assertEquals
@@ -1662,17 +1662,16 @@
 eCount);
- 
 // %3E1287
@@ -1673,32 +1673,26 @@
 %3E1287311235%0A
-        
+%09%09
 assertEquals
@@ -1764,24 +1764,18 @@
 Count);%0A
-        
+%09%09
 assertEq
@@ -1869,16 +1869,10 @@
 235%0A
-        
+%09%09
 asse
@@ -1955,11 +1955,8 @@
 t);%0A
-    
+%09
 %7D%0A%7D

Fix indents