15
15
import java .io .IOException ;
16
16
import java .io .PrintStream ;
17
17
import java .net .URL ;
18
- import java .nio .file .*;
19
- import java .nio .file .attribute .BasicFileAttributes ;
18
+ import java .nio .file .Files ;
19
+ import java .nio .file .Path ;
20
+ import java .nio .file .Paths ;
20
21
import java .util .ArrayList ;
22
+ import java .util .Comparator ;
21
23
import java .util .List ;
22
24
import java .util .Map ;
23
25
import java .util .stream .Collectors ;
@@ -63,7 +65,7 @@ public void cleanUpStreams() {
63
65
}
64
66
65
67
@ After
66
- public void deleteTempDir () throws IOException {
68
+ public void deleteTempDir () throws Exception {
67
69
deleteDir (tempDirectory );
68
70
}
69
71
@@ -72,52 +74,51 @@ public void shouldExitWithExitStatus1IfConfigHasNoUrls() throws Exception {
72
74
exit .expectSystemExitWithStatus (1 );
73
75
exit .checkAssertionAfterwards (() -> assertThat (systemErrCaptor .toString (), containsString ("No URLs configured." )));
74
76
75
- Main .main (new String []{"--working-dir" ,tempDirectory .toString (),"--config" ,"src/test/resources/acceptance/acceptance_no_urls.lineup.json" });
77
+ Main .main (new String []{"--working-dir" , tempDirectory .toString (), "--config" , "src/test/resources/acceptance/acceptance_no_urls.lineup.json" });
76
78
}
77
79
78
80
@ Test
79
81
public void shouldExitWithExitStatus1IfThereIsAJSException () throws Exception {
80
82
exit .expectSystemExitWithStatus (1 );
81
83
exit .checkAssertionAfterwards (() -> assertThat (combinedOutput (), containsString ("doesnotexist" )));
82
84
83
- Main .main (new String []{"--working-dir" ,tempDirectory .toString (),"--config" ,"src/test/resources/acceptance/acceptance_wrong_js.lineup.json" ,"--replace-in-url###CWD###=" + CWD });
85
+ Main .main (new String []{"--working-dir" , tempDirectory .toString (), "--config" , "src/test/resources/acceptance/acceptance_wrong_js.lineup.json" , "--replace-in-url###CWD###=" + CWD });
84
86
}
85
87
86
88
@ Test
87
89
public void shouldExitWithExitStatus1IfThereIsAMalformedUrlInFirefox () throws Exception {
88
90
exit .expectSystemExitWithStatus (1 );
89
91
exit .checkAssertionAfterwards (() -> assertThat (combinedOutput (), containsString ("Reached error page" )));
90
92
91
- Main .main (new String []{"--working-dir" ,tempDirectory .toString (),"--config" ,"src/test/resources/acceptance/acceptance_wrong_url_firefox.lineup.json" });
93
+ Main .main (new String []{"--working-dir" , tempDirectory .toString (), "--config" , "src/test/resources/acceptance/acceptance_wrong_url_firefox.lineup.json" });
92
94
}
93
95
94
96
@ Test
95
97
public void shouldExitWithExitStatus1IfThereIsAMalformedUrlInChrome () throws Exception {
96
98
exit .expectSystemExitWithStatus (1 );
97
99
exit .checkAssertionAfterwards (() -> assertThat (combinedOutput (), CoreMatchers .anyOf (containsString ("ERR_NAME_RESOLUTION_FAILED" ), containsString ("ERR_NAME_NOT_RESOLVED" ))));
98
100
99
- Main .main (new String []{"--working-dir" ,tempDirectory .toString (),"--config" ,"src/test/resources/acceptance/acceptance_wrong_url_chrome.lineup.json" });
101
+ Main .main (new String []{"--working-dir" , tempDirectory .toString (), "--config" , "src/test/resources/acceptance/acceptance_wrong_url_chrome.lineup.json" });
100
102
}
101
103
102
104
@ Test
103
105
public void shouldExitWithExitStatus1IfThereIsAGlobalTimeout () throws Exception {
104
106
exit .expectSystemExitWithStatus (1 );
105
107
exit .checkAssertionAfterwards (() -> assertThat (combinedOutput (), containsString ("Timeout" )));
106
108
107
- Main .main (new String []{"--working-dir" ,tempDirectory .toString (),"--config" ,"src/test/resources/acceptance/acceptance_timeout.lineup.json" });
109
+ Main .main (new String []{"--working-dir" , tempDirectory .toString (), "--config" , "src/test/resources/acceptance/acceptance_timeout.lineup.json" });
108
110
}
109
111
110
112
@ Test
111
113
public void shouldOpenTestPage () throws Exception {
112
- Main .main (new String []{"--working-dir" ,tempDirectory .toString (),"--url" ,"file://" + CWD +"/src/test/resources/acceptance/webpage/test.html" });
114
+ Main .main (new String []{"--working-dir" , tempDirectory .toString (), "--url" , "file://" + CWD + "/src/test/resources/acceptance/webpage/test.html" });
113
115
}
114
116
115
117
116
-
117
118
@ Test
118
119
public void shouldRunJLineupWithTestPageThatDoesntChange_WithChrome () throws Exception {
119
- Main .main (new String []{"--working-dir" ,tempDirectory .toString (),"--config" ,"src/test/resources/acceptance/acceptance_chrome.lineup.json" ,"--replace-in-url###CWD###=" + CWD , "--step" ,"before" });
120
- Main .main (new String []{"--working-dir" ,tempDirectory .toString (),"--config" ,"src/test/resources/acceptance/acceptance_chrome.lineup.json" ,"--replace-in-url###CWD###=" + CWD , "--step" ,"after" });
120
+ Main .main (new String []{"--working-dir" , tempDirectory .toString (), "--config" , "src/test/resources/acceptance/acceptance_chrome.lineup.json" , "--replace-in-url###CWD###=" + CWD , "--step" , "before" });
121
+ Main .main (new String []{"--working-dir" , tempDirectory .toString (), "--config" , "src/test/resources/acceptance/acceptance_chrome.lineup.json" , "--replace-in-url###CWD###=" + CWD , "--step" , "after" });
121
122
122
123
final Path reportJson = Paths .get (tempDirectory .toString (), "report" , "report.json" );
123
124
assertThat ("Report JSON exists" , Files .exists (reportJson ));
@@ -134,14 +135,14 @@ public void shouldRunJLineupWithTestPageThatDoesntChange_WithChrome() throws Exc
134
135
135
136
@ Test
136
137
public void shouldPassCommandLineParametersToChrome () throws Exception {
137
- Main .main (new String []{"--working-dir" ,tempDirectory .toString (),"--config" ,"src/test/resources/acceptance/acceptance_chrome.lineup.json" ,"--replace-in-url###CWD###=" + CWD ,"--step" ,"before" ,"--chrome-parameter" ,"--user-agent=\" fakeuseragent\" " });
138
+ Main .main (new String []{"--working-dir" , tempDirectory .toString (), "--config" , "src/test/resources/acceptance/acceptance_chrome.lineup.json" , "--replace-in-url###CWD###=" + CWD , "--step" , "before" , "--chrome-parameter" , "--user-agent=\" fakeuseragent\" " });
138
139
assertThat (systemOutCaptor .toString (), containsString ("User agent: \" fakeuseragent\" " ));
139
140
}
140
141
141
142
@ Test
142
143
public void shouldRenderLogoTheSame_WithChrome () throws Exception {
143
- Main .main (new String []{"--working-dir" ,tempDirectory .toString (),"--config" ,"src/test/resources/acceptance/acceptance_chrome_svg.lineup.json" ,"--replace-in-url###CWD###=" + CWD , "--step" ,"before" });
144
- Main .main (new String []{"--working-dir" ,tempDirectory .toString (),"--config" ,"src/test/resources/acceptance/acceptance_chrome_svg.lineup.json" ,"--replace-in-url###CWD###=" + CWD , "--step" ,"after" });
144
+ Main .main (new String []{"--working-dir" , tempDirectory .toString (), "--config" , "src/test/resources/acceptance/acceptance_chrome_svg.lineup.json" , "--replace-in-url###CWD###=" + CWD , "--step" , "before" });
145
+ Main .main (new String []{"--working-dir" , tempDirectory .toString (), "--config" , "src/test/resources/acceptance/acceptance_chrome_svg.lineup.json" , "--replace-in-url###CWD###=" + CWD , "--step" , "after" });
145
146
146
147
final Path reportJson = Paths .get (tempDirectory .toString (), "report" , "report.json" );
147
148
assertThat ("Report JSON exists" , Files .exists (reportJson ));
@@ -158,8 +159,8 @@ public void shouldRenderLogoTheSame_WithChrome() throws Exception {
158
159
159
160
@ Test
160
161
public void shouldRunJLineupWithTestPageThatDoesntChange_WithChromeHeadless () throws Exception {
161
- Main .main (new String []{"--working-dir" ,tempDirectory .toString (),"--config" ,"src/test/resources/acceptance/acceptance_chrome-headless.lineup.json" ,"--replace-in-url###CWD###=" + CWD ," --step" ,"before" });
162
- Main .main (new String []{"--working-dir" ,tempDirectory .toString (),"--config" ,"src/test/resources/acceptance/acceptance_chrome-headless.lineup.json" ,"--replace-in-url###CWD###=" + CWD , "--step" ,"after" });
162
+ Main .main (new String []{"--working-dir" , tempDirectory .toString (), "--config" , "src/test/resources/acceptance/acceptance_chrome-headless.lineup.json" , "--replace-in-url###CWD###=" + CWD , " --step" , "before" });
163
+ Main .main (new String []{"--working-dir" , tempDirectory .toString (), "--config" , "src/test/resources/acceptance/acceptance_chrome-headless.lineup.json" , "--replace-in-url###CWD###=" + CWD , "--step" , "after" });
163
164
164
165
final Path reportJson = Paths .get (tempDirectory .toString (), "report" , "report.json" );
165
166
assertThat ("Report JSON exists" , Files .exists (reportJson ));
@@ -176,8 +177,8 @@ public void shouldRunJLineupWithTestPageThatDoesntChange_WithChromeHeadless() th
176
177
177
178
@ Test
178
179
public void shouldRunJLineupWithTestPageThatDoesntChange_WithFirefox () throws Exception {
179
- Main .main (new String []{"--working-dir" ,tempDirectory .toString (),"--config" ,"src/test/resources/acceptance/acceptance_firefox.lineup.json" ,"--replace-in-url###CWD###=" + CWD ," --step" ,"before" });
180
- Main .main (new String []{"--working-dir" ,tempDirectory .toString (),"--config" ,"src/test/resources/acceptance/acceptance_firefox.lineup.json" ,"--replace-in-url###CWD###=" + CWD , "--step" ,"after" });
180
+ Main .main (new String []{"--working-dir" , tempDirectory .toString (), "--config" , "src/test/resources/acceptance/acceptance_firefox.lineup.json" , "--replace-in-url###CWD###=" + CWD , " --step" , "before" });
181
+ Main .main (new String []{"--working-dir" , tempDirectory .toString (), "--config" , "src/test/resources/acceptance/acceptance_firefox.lineup.json" , "--replace-in-url###CWD###=" + CWD , "--step" , "after" });
181
182
182
183
final Path reportJson = Paths .get (tempDirectory .toString (), "report" , "report.json" );
183
184
assertThat ("Report JSON exists" , Files .exists (reportJson ));
@@ -194,8 +195,8 @@ public void shouldRunJLineupWithTestPageThatDoesntChange_WithFirefox() throws Ex
194
195
195
196
@ Test
196
197
public void shouldRunJLineupWithTestPageThatDoesntChange_ReportFormat2 () throws Exception {
197
- Main .main (new String []{"--working-dir" ,tempDirectory .toString (),"--config" ,"src/test/resources/acceptance/acceptance_reportv2.lineup.json" ,"--replace-in-url###CWD###=" + CWD ," --step" ,"before" });
198
- Main .main (new String []{"--working-dir" ,tempDirectory .toString (),"--config" ,"src/test/resources/acceptance/acceptance_reportv2.lineup.json" ,"--replace-in-url###CWD###=" + CWD , "--step" ,"after" });
198
+ Main .main (new String []{"--working-dir" , tempDirectory .toString (), "--config" , "src/test/resources/acceptance/acceptance_reportv2.lineup.json" , "--replace-in-url###CWD###=" + CWD , " --step" , "before" });
199
+ Main .main (new String []{"--working-dir" , tempDirectory .toString (), "--config" , "src/test/resources/acceptance/acceptance_reportv2.lineup.json" , "--replace-in-url###CWD###=" + CWD , "--step" , "after" });
199
200
200
201
final Path reportJson = Paths .get (tempDirectory .toString (), "report" , "report.json" );
201
202
assertThat ("Report JSON exists" , Files .exists (reportJson ));
@@ -212,8 +213,8 @@ public void shouldRunJLineupWithTestPageThatDoesntChange_ReportFormat2() throws
212
213
213
214
@ Test
214
215
public void shouldRunJLineupWithTestPageThatDoesntChange_LegacyReportFormat () throws Exception {
215
- Main .main (new String []{"--working-dir" ,tempDirectory .toString (),"--config" ,"src/test/resources/acceptance/acceptance_legacy.lineup.json" ,"--replace-in-url###CWD###=" + CWD , "--step" ,"before" });
216
- Main .main (new String []{"--working-dir" ,tempDirectory .toString (),"--config" ,"src/test/resources/acceptance/acceptance_legacy.lineup.json" ,"--replace-in-url###CWD###=" + CWD , "--step" ,"after" });
216
+ Main .main (new String []{"--working-dir" , tempDirectory .toString (), "--config" , "src/test/resources/acceptance/acceptance_legacy.lineup.json" , "--replace-in-url###CWD###=" + CWD , "--step" , "before" });
217
+ Main .main (new String []{"--working-dir" , tempDirectory .toString (), "--config" , "src/test/resources/acceptance/acceptance_legacy.lineup.json" , "--replace-in-url###CWD###=" + CWD , "--step" , "after" });
217
218
218
219
final Path reportJson = Paths .get (tempDirectory .toString (), "report" , "report.json" );
219
220
assertThat ("Report JSON exists" , Files .exists (reportJson ));
@@ -230,8 +231,8 @@ public void shouldRunJLineupWithTestPageThatDoesntChange_LegacyReportFormat() th
230
231
231
232
@ Test
232
233
public void shouldRunJLineupWithTestPageThatDoesntChange_DefaultReportFormat () throws Exception {
233
- Main .main (new String []{"--working-dir" ,tempDirectory .toString (),"--config" ,"src/test/resources/acceptance/acceptance.lineup.json" ,"--replace-in-url###CWD###=" + CWD , "--step" ,"before" });
234
- Main .main (new String []{"--working-dir" ,tempDirectory .toString (),"--config" ,"src/test/resources/acceptance/acceptance.lineup.json" ,"--replace-in-url###CWD###=" + CWD , "--step" ,"after" });
234
+ Main .main (new String []{"--working-dir" , tempDirectory .toString (), "--config" , "src/test/resources/acceptance/acceptance.lineup.json" , "--replace-in-url###CWD###=" + CWD , "--step" , "before" });
235
+ Main .main (new String []{"--working-dir" , tempDirectory .toString (), "--config" , "src/test/resources/acceptance/acceptance.lineup.json" , "--replace-in-url###CWD###=" + CWD , "--step" , "after" });
235
236
236
237
final Path reportJson = Paths .get (tempDirectory .toString (), "report" , "report.json" );
237
238
assertThat ("Report JSON exists" , Files .exists (reportJson ));
@@ -258,45 +259,33 @@ public void shouldRunJLineupWithTestPageThatHasAVeryLongPath() throws Exception
258
259
259
260
@ Test
260
261
public void shouldNotCrashPhantomjsFontsNotLoaded () throws Exception {
261
- Main .main (new String []{"--working-dir" ,tempDirectory .toString (),"--config" ,"src/test/resources/acceptance/acceptance_phantom_fonts.lineup.json" ,"--replace-in-url###CWD###=" + CWD , "--step" ,"before" });
262
- Main .main (new String []{"--working-dir" ,tempDirectory .toString (),"--config" ,"src/test/resources/acceptance/acceptance_phantom_fonts.lineup.json" ,"--replace-in-url###CWD###=" + CWD , "--step" ,"after" });
262
+ Main .main (new String []{"--working-dir" , tempDirectory .toString (), "--config" , "src/test/resources/acceptance/acceptance_phantom_fonts.lineup.json" , "--replace-in-url###CWD###=" + CWD , "--step" , "before" });
263
+ Main .main (new String []{"--working-dir" , tempDirectory .toString (), "--config" , "src/test/resources/acceptance/acceptance_phantom_fonts.lineup.json" , "--replace-in-url###CWD###=" + CWD , "--step" , "after" });
263
264
assertThat (systemOutCaptor .toString (), containsString ("WARNING: 'wait-for-fonts-time' is ignored because PhantomJS doesn't support this feature." ));
264
265
}
265
266
266
267
@ Test
267
268
public void shouldPrintConfig () throws Exception {
268
269
exit .checkAssertionAfterwards (() -> assertThat (systemOutCaptor .toString (), containsString ("http://www.example.com" )));
269
270
exit .expectSystemExitWithStatus (0 );
270
- Main .main (new String []{"--working-dir" ,tempDirectory .toString (),"--print-config" });
271
+ Main .main (new String []{"--working-dir" , tempDirectory .toString (), "--print-config" });
271
272
}
272
273
273
274
private String getTextFileContentAsString (Path reportJson ) throws IOException {
274
275
final List <String > reportJsonLines = Files .readAllLines (reportJson );
275
276
return reportJsonLines .stream ().collect (Collectors .joining ());
276
277
}
277
278
278
- private void deleteDir (Path path ) throws IOException {
279
- Files .walkFileTree (path , new SimpleFileVisitor <Path >() {
280
- @ Override
281
- public FileVisitResult visitFile (Path file , BasicFileAttributes attrs )
282
- throws IOException
283
- {
284
- Files .delete (file );
285
- return FileVisitResult .CONTINUE ;
286
- }
287
- @ Override
288
- public FileVisitResult postVisitDirectory (Path dir , IOException e )
289
- throws IOException
290
- {
291
- if (e == null ) {
292
- Files .delete (dir );
293
- return FileVisitResult .CONTINUE ;
294
- } else {
295
- // directory iteration failed
296
- throw e ;
297
- }
298
- }
299
- });
279
+ private void deleteDir (Path path ) throws Exception {
280
+ Files
281
+ .walk (path )
282
+ .sorted (Comparator .reverseOrder ())
283
+ .map (Path ::toFile )
284
+ .forEach (file -> {
285
+ if (!file .delete ()) {
286
+ throw new RuntimeException ("Couldn't delete file " + file .getAbsolutePath ());
287
+ }
288
+ });
300
289
}
301
290
302
291
private String combinedOutput () {
0 commit comments