15
15
import java .nio .file .Path ;
16
16
import java .nio .file .Paths ;
17
17
import java .util .*;
18
+ import java .util .function .Function ;
18
19
import java .util .regex .Matcher ;
19
20
import java .util .regex .Pattern ;
20
21
import java .util .stream .Stream ;
@@ -29,61 +30,18 @@ public class Util {
29
30
public static final Path BOTH_MODIFIED_DIRPATH = CLEAN_MERGE_DIRPATH .resolve ("both_modified" );
30
31
public static final Path LEFT_MODIFIED_DIRPATH = CLEAN_MERGE_DIRPATH .resolve ("left_modified" );
31
32
public static final Path CONFLICT_DIRPATH = Paths .get ("src/test/resources/conflict" );
33
+ public static final Path UNHANDLED_INCONSISTENCY_PATH = Paths .get ("src/test/resources/unhandled_inconsistency" );
32
34
33
- /**
34
- * Provides test sources for scenarios where both left and right revisions are modified.
35
- */
36
- public static class BothModifiedSourceProvider implements ArgumentsProvider {
37
- @ Override
38
- public Stream <? extends Arguments > provideArguments (ExtensionContext extensionContext ) {
39
- return getArgumentSourcesStream (BOTH_MODIFIED_DIRPATH .toFile ());
40
- }
41
- }
42
-
43
- /**
44
- * Provides test sources for scenarios where left is modified.
45
- */
46
- public static class LeftModifiedSourceProvider implements ArgumentsProvider {
47
- @ Override
48
- public Stream <? extends Arguments > provideArguments (ExtensionContext extensionContext ) {
49
- return getArgumentSourcesStream (LEFT_MODIFIED_DIRPATH .toFile ());
50
- }
51
- }
52
-
53
- /**
54
- * Provides test sources for scenarios where right is modified.
55
- */
56
- public static class RightModifiedSourceProvider implements ArgumentsProvider {
57
- @ Override
58
- public Stream <? extends Arguments > provideArguments (ExtensionContext extensionContext ) {
59
- return getArgumentSourcesStream (LEFT_MODIFIED_DIRPATH .toFile ()).map (
60
- arg -> {
61
- TestSources sources = (TestSources ) arg .get ()[0 ];
62
- // swap left and right around to make this a "right modified" test case
63
- Path left = sources .left ;
64
- sources .left = sources .right ;
65
- sources .right = left ;
66
- return Arguments .of (sources );
67
- }
68
- );
69
- }
70
- }
71
35
72
- /**
73
- * Provides test sources for scenarios where there are conflicts.
74
- */
75
- public static class ConflictSourceProvider implements ArgumentsProvider {
76
- @ Override
77
- public Stream <? extends Arguments > provideArguments (ExtensionContext extensionContext ) {
78
- return getArgumentSourcesStream (CONFLICT_DIRPATH .toFile ());
79
- }
36
+ private static Stream <? extends Arguments > getArgumentSourcesStream (File testDir ) {
37
+ return getArgumentSourcesStream (testDir , TestSources ::fromTestDirectory );
80
38
}
81
39
82
- private static Stream <? extends Arguments > getArgumentSourcesStream (File testDir ) {
40
+ private static Stream <? extends Arguments > getArgumentSourcesStream (File testDir , Function < File , TestSources > sourceGetter ) {
83
41
return Arrays .stream (testDir .listFiles ())
84
42
.filter (File ::isDirectory )
85
43
.filter (f -> !f .getName ().startsWith ("IGNORE" ))
86
- .map (TestSources :: fromTestDirectory )
44
+ .map (sourceGetter )
87
45
.map (Arguments ::of );
88
46
}
89
47
@@ -142,6 +100,62 @@ public static String keepLeftConflict(String string) {
142
100
return leftMarkerMatcher .replaceAll ("" );
143
101
}
144
102
103
+ /**
104
+ * Provides test sources for scenarios where both left and right revisions are modified.
105
+ */
106
+ public static class BothModifiedSourceProvider implements ArgumentsProvider {
107
+ @ Override
108
+ public Stream <? extends Arguments > provideArguments (ExtensionContext extensionContext ) {
109
+ return getArgumentSourcesStream (BOTH_MODIFIED_DIRPATH .toFile ());
110
+ }
111
+ }
112
+
113
+ /**
114
+ * Provides test sources for scenarios where left is modified.
115
+ */
116
+ public static class LeftModifiedSourceProvider implements ArgumentsProvider {
117
+ @ Override
118
+ public Stream <? extends Arguments > provideArguments (ExtensionContext extensionContext ) {
119
+ return getArgumentSourcesStream (LEFT_MODIFIED_DIRPATH .toFile ());
120
+ }
121
+ }
122
+
123
+ /**
124
+ * Provides test sources for scenarios where right is modified.
125
+ */
126
+ public static class RightModifiedSourceProvider implements ArgumentsProvider {
127
+ @ Override
128
+ public Stream <? extends Arguments > provideArguments (ExtensionContext extensionContext ) {
129
+ return getArgumentSourcesStream (LEFT_MODIFIED_DIRPATH .toFile ()).map (
130
+ arg -> {
131
+ TestSources sources = (TestSources ) arg .get ()[0 ];
132
+ // swap left and right around to make this a "right modified" test case
133
+ Path left = sources .left ;
134
+ sources .left = sources .right ;
135
+ sources .right = left ;
136
+ return Arguments .of (sources );
137
+ }
138
+ );
139
+ }
140
+ }
141
+
142
+ public static class UnhandledInconsistencyProvider implements ArgumentsProvider {
143
+ @ Override
144
+ public Stream <? extends Arguments > provideArguments (ExtensionContext extensionContext ) throws Exception {
145
+ return getArgumentSourcesStream (UNHANDLED_INCONSISTENCY_PATH .toFile (), TestSources ::fromTestDirectoryWithoutExpected );
146
+ }
147
+ }
148
+
149
+ /**
150
+ * Provides test sources for scenarios where there are conflicts.
151
+ */
152
+ public static class ConflictSourceProvider implements ArgumentsProvider {
153
+ @ Override
154
+ public Stream <? extends Arguments > provideArguments (ExtensionContext extensionContext ) {
155
+ return getArgumentSourcesStream (CONFLICT_DIRPATH .toFile ());
156
+ }
157
+ }
158
+
145
159
public static class Conflict {
146
160
String left ;
147
161
String right ;
@@ -169,7 +183,6 @@ public int hashCode() {
169
183
}
170
184
}
171
185
172
-
173
186
public static class TestSources {
174
187
public Path base ;
175
188
public Path left ;
@@ -194,9 +207,20 @@ public static TestSources fromTestDirectory(File testDir) {
194
207
);
195
208
}
196
209
210
+ public static TestSources fromTestDirectoryWithoutExpected (File testDir ) {
211
+ Path path = testDir .toPath ();
212
+ return new TestSources (
213
+ path .resolve ("Base.java" ),
214
+ path .resolve ("Left.java" ),
215
+ path .resolve ("Right.java" ),
216
+ null
217
+ );
218
+ }
219
+
197
220
@ Override
198
221
public String toString () {
199
222
return base .getParent ().getFileName ().toString ();
200
223
}
201
224
}
225
+
202
226
}
0 commit comments