Repository navigation
Expand file tree
/
Copy pathModuleNodeTest.java
More file actions
97 lines (80 loc) · 2.99 KB
/
Copy pathModuleNodeTest.java
File metadata and controls
97 lines (80 loc) · 2.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package edu.hm.hafner.coverage;
import static edu.hm.hafner.coverage.Metric.FILE;
import static edu.hm.hafner.coverage.Metric.MODULE;
import static edu.hm.hafner.coverage.Metric.PACKAGE;
import static edu.hm.hafner.coverage.assertions.Assertions.assertThat;
import org.junit.jupiter.api.Test;
class ModuleNodeTest extends AbstractNodeTest {
@Override
Metric getMetric() {
return MODULE;
}
@Override
Node createNode(final String name) {
var moduleNode = new ModuleNode(name);
moduleNode.addSource("/path/to/sources");
assertThat(moduleNode).hasSourceFolders("/path/to/sources").isAggregation();
return moduleNode;
}
@Test
void shouldSplitPackagesWithoutPackageNodes() {
var root = new ModuleNode("Root");
assertThat(root.getAll(PACKAGE)).isEmpty();
root.splitPackages();
assertThat(root.getAll(PACKAGE)).isEmpty();
root.addChild(new FileNode("file.c", "path"));
root.splitPackages();
assertThat(root.getAll(PACKAGE)).isEmpty();
}
@Test
void shouldSplitPackagesWithoutName() {
var root = new ModuleNode("Root");
assertThat(root.getAll(PACKAGE)).isEmpty();
root.splitPackages();
assertThat(root.getAll(PACKAGE)).isEmpty();
var packageNode = new PackageNode("");
root.addChild(packageNode);
assertThat(root.getAll(PACKAGE)).hasSize(1);
root.splitPackages();
assertThat(root.getAll(PACKAGE)).hasSize(1);
assertThat(root).hasOnlyChildren(packageNode);
}
@Test
void shouldSplitPackagesIntoHierarchy() {
var root = new ModuleNode("Root");
assertThat(root.getAll(PACKAGE)).isEmpty();
root.splitPackages();
assertThat(root.getAll(PACKAGE)).isEmpty();
root.addChild(new PackageNode("edu.hm.hafner"));
assertThat(root.getAll(PACKAGE)).hasSize(1);
root.splitPackages();
assertThat(root.getAll(PACKAGE))
.hasSize(3)
.satisfiesExactly(
s -> assertThat(s).hasName("hafner"),
s -> assertThat(s).hasName("hm"),
s -> assertThat(s).hasName("edu"));
}
@Test
void shouldKeepNodesAfterSplitting() {
var root = new ModuleNode("Root");
var pkg = new PackageNode("edu.hm.hafner");
var file = new FileNode("HelloWorld.java", "path");
root.addChild(pkg);
pkg.addChild(file);
root.splitPackages();
assertThat(root.getAll(PACKAGE)).hasSize(3);
assertThat(root.getAll(FILE)).hasSize(1);
}
@Test
void shouldNotMergeWhenDifferentMetric() {
var root = new ModuleNode("Root");
var pkg = new PackageNode("edu.hm.hafner");
var file = new FileNode("Helicopter.java", "path");
root.addChild(pkg);
root.addChild(file);
root.splitPackages();
assertThat(root.getAll(PACKAGE)).hasSize(3);
assertThat(root.getAll(FILE)).hasSize(1);
}
}