33import org .jetbrains .annotations .NotNull ;
44import org .junit .jupiter .api .BeforeEach ;
55import org .junit .jupiter .api .Test ;
6- import org .junit .jupiter .api .extension .ExtendWith ;
76import org .junit .jupiter .api .io .TempDir ;
8- import uk .org .webcompere .systemstubs .jupiter .SystemStub ;
9- import uk .org .webcompere .systemstubs .jupiter .SystemStubsExtension ;
10- import uk .org .webcompere .systemstubs .stream .SystemOut ;
117
128import java .nio .file .Files ;
139import java .nio .file .Path ;
1410import java .nio .file .attribute .PosixFilePermission ;
11+ import java .util .ArrayList ;
1512import java .util .Set ;
1613import java .util .concurrent .atomic .AtomicReference ;
1714
2017import static java .nio .file .attribute .PosixFilePermission .OWNER_WRITE ;
2118import static org .assertj .core .api .Assertions .assertThat ;
2219
23- @ ExtendWith (SystemStubsExtension .class )
2420class TestSplitTest {
2521
2622 private static final @ NotNull Set <PosixFilePermission > PERMISSIONS = Set .of (OWNER_READ , OWNER_WRITE );
2723
28- @ SystemStub
29- private @ NotNull SystemOut systemOut ;
30-
3124 @ TempDir
3225 private @ NotNull Path tmp ;
3326
@@ -84,15 +77,15 @@ void run_withoutJUnit_withOneSplit() throws Exception {
8477 tmp ,
8578 true ,
8679 exitCode ::set );
87- split .run ();
8880
89- assertThat (systemOut . getLines ()).singleElement (). isEqualTo ( //
81+ assertThat (split . run ()).isEqualTo (
9082 "de.donnerbart.example.FastTest de.donnerbart.example.NoTimingOneTest de.donnerbart.example.NoTimingTwoTest de.donnerbart.example.SlowTest de.donnerbart.example.SlowestTest" );
9183 assertThat (exitCode ).hasNullValue ();
9284 }
9385
9486 @ Test
9587 void run_withoutJUnit_withTwoSplits () throws Exception {
88+ final var splits = new ArrayList <String >();
9689 for (int index = 0 ; index <= 1 ; index ++) {
9790 final var split = new TestSplit (index ,
9891 2 ,
@@ -102,19 +95,18 @@ void run_withoutJUnit_withTwoSplits() throws Exception {
10295 tmp ,
10396 true ,
10497 exitCode ::set );
105- split .run ();
106- // add a new line to separate the captured output
107- System .out .println ();
98+ splits .add (split .run ());
10899 }
109100
110- assertThat (systemOut . getLines ()) .hasSize (2 ).containsSequence ( //
101+ assertThat (splits ) .hasSize (2 ).containsExactly ( //
111102 "de.donnerbart.example.FastTest de.donnerbart.example.NoTimingTwoTest de.donnerbart.example.SlowestTest" ,
112103 "de.donnerbart.example.NoTimingOneTest de.donnerbart.example.SlowTest" );
113104 assertThat (exitCode ).hasNullValue ();
114105 }
115106
116107 @ Test
117108 void run_withoutJUnit_withThreeSplits () throws Exception {
109+ final var splits = new ArrayList <String >();
118110 for (int index = 0 ; index <= 2 ; index ++) {
119111 final var split = new TestSplit (index ,
120112 3 ,
@@ -124,12 +116,10 @@ void run_withoutJUnit_withThreeSplits() throws Exception {
124116 tmp ,
125117 true ,
126118 exitCode ::set );
127- split .run ();
128- // add a new line to separate the captured output
129- System .out .println ();
119+ splits .add (split .run ());
130120 }
131121
132- assertThat (systemOut . getLines ()) .hasSize (3 ).containsSequence ( //
122+ assertThat (splits ) .hasSize (3 ).containsExactly ( //
133123 "de.donnerbart.example.FastTest de.donnerbart.example.SlowTest" ,
134124 "de.donnerbart.example.NoTimingOneTest de.donnerbart.example.SlowestTest" ,
135125 "de.donnerbart.example.NoTimingTwoTest" );
@@ -146,15 +136,15 @@ void run_withJUnit_withOneSplit() throws Exception {
146136 tmp ,
147137 true ,
148138 exitCode ::set );
149- split .run ();
150139
151- assertThat (systemOut . getLines ()).singleElement (). isEqualTo ( //
140+ assertThat (split . run ()).isEqualTo (
152141 "de.donnerbart.example.SlowestTest de.donnerbart.example.SlowTest de.donnerbart.example.FastTest de.donnerbart.example.NoTimingOneTest de.donnerbart.example.NoTimingTwoTest" );
153142 assertThat (exitCode ).hasNullValue ();
154143 }
155144
156145 @ Test
157146 void run_withJUnit_withTwoSplits () throws Exception {
147+ final var splits = new ArrayList <String >();
158148 for (int index = 0 ; index <= 1 ; index ++) {
159149 final var split = new TestSplit (index ,
160150 2 ,
@@ -164,19 +154,18 @@ void run_withJUnit_withTwoSplits() throws Exception {
164154 tmp ,
165155 true ,
166156 exitCode ::set );
167- split .run ();
168- // add a new line to separate the captured output
169- System .out .println ();
157+ splits .add (split .run ());
170158 }
171159
172- assertThat (systemOut . getLines ()) .hasSize (2 ).containsSequence ( //
160+ assertThat (splits ) .hasSize (2 ).containsExactly ( //
173161 "de.donnerbart.example.SlowestTest" ,
174162 "de.donnerbart.example.SlowTest de.donnerbart.example.FastTest de.donnerbart.example.NoTimingOneTest de.donnerbart.example.NoTimingTwoTest" );
175163 assertThat (exitCode ).hasNullValue ();
176164 }
177165
178166 @ Test
179167 void run_withJUnit_withThreeSplits () throws Exception {
168+ final var splits = new ArrayList <String >();
180169 for (int index = 0 ; index <= 2 ; index ++) {
181170 final var split = new TestSplit (index ,
182171 3 ,
@@ -186,12 +175,10 @@ void run_withJUnit_withThreeSplits() throws Exception {
186175 tmp ,
187176 true ,
188177 exitCode ::set );
189- split .run ();
190- // add a new line to separate the captured output
191- System .out .println ();
178+ splits .add (split .run ());
192179 }
193180
194- assertThat (systemOut . getLines ()) .hasSize (3 ).containsSequence ( //
181+ assertThat (splits ) .hasSize (3 ).containsExactly ( //
195182 "de.donnerbart.example.SlowestTest" ,
196183 "de.donnerbart.example.SlowTest" ,
197184 "de.donnerbart.example.FastTest de.donnerbart.example.NoTimingOneTest de.donnerbart.example.NoTimingTwoTest" );
@@ -200,6 +187,7 @@ void run_withJUnit_withThreeSplits() throws Exception {
200187
201188 @ Test
202189 void run_withJUnit_withFourSplits () throws Exception {
190+ final var splits = new ArrayList <String >();
203191 for (int index = 0 ; index <= 3 ; index ++) {
204192 final var split = new TestSplit (index ,
205193 4 ,
@@ -209,12 +197,10 @@ void run_withJUnit_withFourSplits() throws Exception {
209197 tmp ,
210198 true ,
211199 exitCode ::set );
212- split .run ();
213- // add a new line to separate the captured output
214- System .out .println ();
200+ splits .add (split .run ());
215201 }
216202
217- assertThat (systemOut . getLines ()) .hasSize (4 ).containsSequence ( //
203+ assertThat (splits ) .hasSize (4 ).containsExactly ( //
218204 "de.donnerbart.example.SlowestTest" ,
219205 "de.donnerbart.example.SlowTest" ,
220206 "de.donnerbart.example.FastTest" ,
@@ -231,18 +217,16 @@ void run_whitespaceClassDefinition() throws Exception {
231217 "WhitespaceClassDefinitionTest.java" ,
232218 PERMISSIONS );
233219
234- final var testSplit = new TestSplit (0 ,
220+ final var split = new TestSplit (0 ,
235221 1 ,
236222 "**/multiline-class-definition-project/**/*Test.java" ,
237223 null ,
238224 null ,
239225 projectFolder ,
240226 true ,
241227 exitCode ::set );
242- testSplit .run ();
243228
244- assertThat (systemOut .getLines ()).singleElement ()
245- .isEqualTo ("de.donnerbart.example.WhitespaceClassDefinitionTest" );
229+ assertThat (split .run ()).isEqualTo ("de.donnerbart.example.WhitespaceClassDefinitionTest" );
246230 assertThat (exitCode ).hasNullValue ();
247231 }
248232
@@ -255,17 +239,16 @@ void run_thirdPartyLibrary() throws Exception {
255239 "ThirdPartyLibraryTest.java" ,
256240 PERMISSIONS );
257241
258- final var testSplit = new TestSplit (0 ,
242+ final var split = new TestSplit (0 ,
259243 1 ,
260244 "**/third-party-library-project/**/*Test.java" ,
261245 null ,
262246 null ,
263247 projectFolder ,
264248 true ,
265249 exitCode ::set );
266- testSplit .run ();
267250
268- assertThat (systemOut . getLines ()). singleElement ( ).isEqualTo ("de.donnerbart.example.ThirdPartyLibraryTest" );
251+ assertThat (split . run () ).isEqualTo ("de.donnerbart.example.ThirdPartyLibraryTest" );
269252 assertThat (exitCode ).hasNullValue ();
270253 }
271254
@@ -274,35 +257,33 @@ void run_noPackage() throws Exception {
274257 final var projectFolder = tmp .resolve ("no-package-project" ).resolve ("src" ).resolve ("main" ).resolve ("java" );
275258 copyResourceToTarget (projectFolder , "tests/NoPackageTest.java" , "NoPackageTest.java" , PERMISSIONS );
276259
277- final var testSplit = new TestSplit (0 ,
260+ final var split = new TestSplit (0 ,
278261 1 ,
279262 "**/no-package-project/**/*Test.java" ,
280263 null ,
281264 null ,
282265 projectFolder ,
283266 true ,
284267 exitCode ::set );
285- testSplit .run ();
286268
287- assertThat (systemOut . getLines ()). singleElement ( ).isEqualTo ("NoPackageTest" );
269+ assertThat (split . run () ).isEqualTo ("NoPackageTest" );
288270 assertThat (exitCode ).hasNullValue ();
289271 }
290272
291273 @ Test
292274 void run_noTests () throws Exception {
293275 final var projectFolder = tmp .resolve ("no-tests-project" ).resolve ("src" ).resolve ("main" ).resolve ("java" );
294276
295- final var testSplit = new TestSplit (0 ,
277+ final var split = new TestSplit (0 ,
296278 1 ,
297279 "**/no-tests-project/**/*Test.java" ,
298280 null ,
299281 null ,
300282 projectFolder ,
301283 true ,
302284 exitCode ::set );
303- testSplit .run ();
304285
305- assertThat (systemOut . getLinesNormalized ()).isEmpty ();
286+ assertThat (split . run ()).isEmpty ();
306287 assertThat (exitCode ).hasValue (1 );
307288 }
308289
@@ -311,17 +292,16 @@ void run_noClassName() throws Exception {
311292 final var projectFolder = tmp .resolve ("no-classname-project" ).resolve ("src" ).resolve ("main" ).resolve ("java" );
312293 copyResourceToTarget (projectFolder , "tests/NoClassNameTest.java" , "NoClassNameTest.java" , PERMISSIONS );
313294
314- final var testSplit = new TestSplit (0 ,
295+ final var split = new TestSplit (0 ,
315296 1 ,
316297 "**/no-classname-project/**/*Test.java" ,
317298 null ,
318299 null ,
319300 projectFolder ,
320301 true ,
321302 exitCode ::set );
322- testSplit .run ();
323303
324- assertThat (systemOut . getLinesNormalized ()).isEmpty ();
304+ assertThat (split . run ()).isEmpty ();
325305 assertThat (exitCode ).hasValue (1 );
326306 }
327307}
0 commit comments