|
14 | 14 |
|
15 | 15 |
|
16 | 16 | public class MavenModuleTest { |
| 17 | + |
17 | 18 | @Test |
18 | 19 | void legend_engine(@TempDir Path temp) throws XmlPullParserException, IOException { |
19 | | - // arrange |
20 | | - MavenModule module = Utility.createMavenModuleGraph(Path.of("src/test/resources/legend-engine/legend-engine"), null, new HashMap<>()); |
21 | | - Path expectedPlainText = Path.of("src/test/resources/legend-engine/output.txt"); |
22 | | - Path actualPlainText = temp.resolve("legend-engine.txt"); |
23 | | - |
24 | | - Path expectedJson = Path.of("src/test/resources/legend-engine/output.json"); |
25 | | - Path actualJson = temp.resolve("legend-engine.json"); |
26 | | - |
27 | | - // act |
28 | | - Utility.printToFile(module, actualPlainText, 2); |
29 | | - Utility.printToJson(module, actualJson, 2); |
30 | | - |
31 | | - // assert |
32 | | - assertThat(Files.readString(expectedPlainText), equalTo(Files.readString(actualPlainText))); |
33 | | - assertThat(Files.readString(expectedJson), equalTo(Files.readString(actualJson))); |
| 20 | + runTest( |
| 21 | + "src/test/resources/legend-engine/legend-engine", |
| 22 | + "src/test/resources/legend-engine/output.txt", |
| 23 | + "src/test/resources/legend-engine/output.json", |
| 24 | + temp.resolve("legend-engine.txt"), |
| 25 | + temp.resolve("legend-engine.json"), |
| 26 | + 2, 2 |
| 27 | + ); |
34 | 28 | } |
35 | 29 |
|
36 | 30 | @Test |
37 | 31 | void neo4j_profileModules(@TempDir Path temp) throws XmlPullParserException, IOException { |
38 | | - // arrange |
39 | | - MavenModule module = Utility.createMavenModuleGraph(Path.of("src/test/resources/neo4j/neo4j"), null, new HashMap<>()); |
40 | | - Path expectedPlainText = Path.of("src/test/resources/neo4j/output.txt"); |
41 | | - Path actualPlainText = temp.resolve("neo4j.txt"); |
42 | | - |
43 | | - Path expectedJson = Path.of("src/test/resources/neo4j/output.json"); |
44 | | - Path actualJson = temp.resolve("neo4j.json"); |
45 | | - |
46 | | - // act |
47 | | - Utility.printToFile(module, actualPlainText, 2); |
48 | | - Utility.printToJson(module, actualJson, 0); |
49 | | - |
50 | | - // assert |
51 | | - assertThat(Files.readAllLines(expectedPlainText).size(), equalTo(125)); |
52 | | - assertThat(Files.readString(expectedPlainText), equalTo(Files.readString(actualPlainText))); |
53 | | - assertThat(Files.readString(expectedJson), equalTo(Files.readString(actualJson))); |
| 32 | + runTestWithLineCountCheck( |
| 33 | + "src/test/resources/neo4j/neo4j", |
| 34 | + "src/test/resources/neo4j/output.txt", |
| 35 | + "src/test/resources/neo4j/output.json", |
| 36 | + temp.resolve("neo4j.txt"), |
| 37 | + temp.resolve("neo4j.json"), |
| 38 | + 2, 0, |
| 39 | + 125 |
| 40 | + ); |
54 | 41 | } |
55 | 42 |
|
56 | 43 | @Test |
57 | 44 | void arthas_mavenProperties(@TempDir Path temp) throws XmlPullParserException, IOException { |
58 | | - // arrange |
59 | | - MavenModule module = Utility.createMavenModuleGraph(Path.of("src/test/resources/arthas/arthas"), null, new HashMap<>()); |
60 | | - Path expectedPlainText = Path.of("src/test/resources/arthas/output.txt"); |
61 | | - Path actualPlainText = temp.resolve("arthas.txt"); |
| 45 | + runTest( |
| 46 | + "src/test/resources/arthas/arthas", |
| 47 | + "src/test/resources/arthas/output.txt", |
| 48 | + "src/test/resources/arthas/output.json", |
| 49 | + temp.resolve("arthas.txt"), |
| 50 | + temp.resolve("arthas.json"), |
| 51 | + 2, 0 |
| 52 | + ); |
| 53 | + } |
| 54 | + |
| 55 | + @Test |
| 56 | + void persistence_differentProjectRoot(@TempDir Path temp) throws XmlPullParserException, IOException { |
| 57 | + runTest( |
| 58 | + "src/test/resources/persistence/persistence/api", |
| 59 | + "src/test/resources/persistence/output.txt", |
| 60 | + "src/test/resources/persistence/output.json", |
| 61 | + temp.resolve("persistence.txt"), |
| 62 | + temp.resolve("persistence.json"), |
| 63 | + 0, 2 |
| 64 | + ); |
| 65 | + } |
62 | 66 |
|
63 | | - Path expectedJson = Path.of("src/test/resources/arthas/output.json"); |
64 | | - Path actualJson = temp.resolve("arthas.json"); |
| 67 | + private void runTest( |
| 68 | + String modulePath, |
| 69 | + String expectedTextPath, |
| 70 | + String expectedJsonPath, |
| 71 | + Path actualTextPath, |
| 72 | + Path actualJsonPath, |
| 73 | + int textIndent, |
| 74 | + int jsonIndent |
| 75 | + ) throws XmlPullParserException, IOException { |
| 76 | + // arrange |
| 77 | + MavenModule module = Utility.createMavenModuleGraph(Path.of(modulePath), null, new HashMap<>()); |
| 78 | + Path expectedPlainText = Path.of(expectedTextPath); |
| 79 | + Path expectedJson = Path.of(expectedJsonPath); |
65 | 80 |
|
66 | 81 | // act |
67 | | - Utility.printToFile(module, actualPlainText, 2); |
68 | | - Utility.printToJson(module, actualJson, 0); |
| 82 | + Utility.printToFile(module, actualTextPath, textIndent); |
| 83 | + Utility.printToJson(module, actualJsonPath, jsonIndent); |
69 | 84 |
|
70 | 85 | // assert |
71 | | - assertThat(Files.readString(expectedPlainText), equalTo(Files.readString(actualPlainText))); |
72 | | - assertThat(Files.readString(expectedJson), equalTo(Files.readString(actualJson))); |
| 86 | + assertThat(Files.readString(expectedPlainText), equalTo(Files.readString(actualTextPath))); |
| 87 | + assertThat(Files.readString(expectedJson), equalTo(Files.readString(actualJsonPath))); |
73 | 88 | } |
74 | 89 |
|
75 | | - @Test |
76 | | - void persistence_differentProjectRoot(@TempDir Path temp) throws XmlPullParserException, IOException { |
| 90 | + private void runTestWithLineCountCheck( |
| 91 | + String modulePath, |
| 92 | + String expectedTextPath, |
| 93 | + String expectedJsonPath, |
| 94 | + Path actualTextPath, |
| 95 | + Path actualJsonPath, |
| 96 | + int textIndent, |
| 97 | + int jsonIndent, |
| 98 | + int expectedLineCount |
| 99 | + ) throws XmlPullParserException, IOException { |
77 | 100 | // arrange |
78 | | - MavenModule module = Utility.createMavenModuleGraph(Path.of("src/test/resources/persistence/persistence/api"), null, new HashMap<>()); |
79 | | - Path expectedPlainText = Path.of("src/test/resources/persistence/output.txt"); |
80 | | - Path actualPlainText = temp.resolve("arthas.txt"); |
81 | | - |
82 | | - Path expectedJson = Path.of("src/test/resources/persistence/output.json"); |
83 | | - Path actualJson = temp.resolve("arthas.json"); |
| 101 | + MavenModule module = Utility.createMavenModuleGraph(Path.of(modulePath), null, new HashMap<>()); |
| 102 | + Path expectedPlainText = Path.of(expectedTextPath); |
| 103 | + Path expectedJson = Path.of(expectedJsonPath); |
84 | 104 |
|
85 | 105 | // act |
86 | | - Utility.printToFile(module, actualPlainText, 0); |
87 | | - Utility.printToJson(module, actualJson, 2); |
| 106 | + Utility.printToFile(module, actualTextPath, textIndent); |
| 107 | + Utility.printToJson(module, actualJsonPath, jsonIndent); |
88 | 108 |
|
89 | 109 | // assert |
90 | | - assertThat(Files.readString(expectedPlainText), equalTo(Files.readString(actualPlainText))); |
91 | | - assertThat(Files.readString(expectedJson), equalTo(Files.readString(actualJson))); |
| 110 | + assertThat(Files.readAllLines(expectedPlainText).size(), equalTo(expectedLineCount)); |
| 111 | + assertThat(Files.readString(expectedPlainText), equalTo(Files.readString(actualTextPath))); |
| 112 | + assertThat(Files.readString(expectedJson), equalTo(Files.readString(actualJsonPath))); |
92 | 113 | } |
93 | | - |
94 | 114 | } |
0 commit comments