1
+ package cc .files ;
2
+
3
+ import org .junit .Test ;
4
+ import org .sonarsource .sonarlint .core .client .api .common .analysis .ClientInputFile ;
5
+
6
+ import java .nio .charset .Charset ;
7
+ import java .nio .file .Paths ;
8
+ import java .util .Arrays ;
9
+ import java .util .List ;
10
+ import java .util .stream .Collectors ;
11
+
12
+ import static org .assertj .core .api .Assertions .assertThat ;
13
+
14
+
15
+ public class FinderTest {
16
+
17
+ @ Test
18
+ public void find_files_in_directory () throws Exception {
19
+ Finder finder = new Finder (Arrays .asList ("src/included/" ), null , Charset .defaultCharset ());
20
+
21
+ List <ClientInputFile > files = finder .collect (Paths .get ("fixtures/multiple_paths" ));
22
+ List <String > paths = files .stream ().map (ClientInputFile ::getPath ).collect (Collectors .toList ());
23
+
24
+ assertThat (paths ).containsOnly (
25
+ "fixtures/multiple_paths/src/included/java/pkg1/HasIssue.java" ,
26
+ "fixtures/multiple_paths/src/included/java/pkg1/HasNoIssue.java"
27
+ );
28
+ }
29
+
30
+ @ Test
31
+ public void find_specified_files () throws Exception {
32
+ Finder finder = new Finder (Arrays .asList ("config.json" , "Main.java" ), null , Charset .defaultCharset ());
33
+
34
+ List <ClientInputFile > files = finder .collect (Paths .get ("fixtures/multiple_paths" ));
35
+ List <String > paths = files .stream ().map (ClientInputFile ::getPath ).collect (Collectors .toList ());
36
+
37
+ assertThat (paths ).containsOnly (
38
+ "fixtures/multiple_paths/Main.java" ,
39
+ "fixtures/multiple_paths/config.json"
40
+ );
41
+ }
42
+
43
+ @ Test
44
+ public void find_from_multiple_locations () throws Exception {
45
+ Finder finder = new Finder (Arrays .asList ("config.json" , "src/included/java/" ), null , Charset .defaultCharset ());
46
+
47
+ List <ClientInputFile > files = finder .collect (Paths .get ("fixtures/multiple_paths" ));
48
+ List <String > paths = files .stream ().map (ClientInputFile ::getPath ).collect (Collectors .toList ());
49
+
50
+ assertThat (paths ).containsOnly (
51
+ "fixtures/multiple_paths/config.json" ,
52
+ "fixtures/multiple_paths/src/included/java/pkg1/HasIssue.java" ,
53
+ "fixtures/multiple_paths/src/included/java/pkg1/HasNoIssue.java"
54
+ );
55
+ }
56
+
57
+ @ Test
58
+ public void differentiate_src_and_test () throws Exception {
59
+ Finder finder = new Finder (Arrays .asList ("src/included/" , "src/test/" ), "{**/test/**}" , Charset .defaultCharset ());
60
+
61
+ List <ClientInputFile > files = finder .collect (Paths .get ("fixtures/multiple_paths" ));
62
+
63
+ assertThat (files .stream ().filter (f -> !f .isTest ()).map (ClientInputFile ::getPath ).collect (Collectors .toList ())).containsOnly (
64
+ "fixtures/multiple_paths/src/included/java/pkg1/HasIssue.java" ,
65
+ "fixtures/multiple_paths/src/included/java/pkg1/HasNoIssue.java"
66
+ );
67
+ assertThat (files .stream ().filter (f -> f .isTest ()).map (ClientInputFile ::getPath ).collect (Collectors .toList ())).containsOnly (
68
+ "fixtures/multiple_paths/src/test/java/Test.java"
69
+ );
70
+ }
71
+ }
0 commit comments