@@ -68,38 +68,37 @@ public void setup() throws IOException {
68
68
deleteFileCallableInstance = new DeleteArtifactsMatchingPatternsAction .DeleteFileCallable (archiveRootDirectory );
69
69
}
70
70
71
- private void assertTempFolderContains (final int expectedNumFiles ) {
71
+ private void assertTempFolderContainsFileCount (final int expectedNumFiles ) {
72
72
final int actualNumFiles = countFiles (tempFolder .getRoot ());
73
73
final String assertMessage = String .format ("Expected %d files, actual found %d files" , expectedNumFiles ,
74
74
actualNumFiles );
75
75
Assert .assertEquals (assertMessage , expectedNumFiles , actualNumFiles );
76
76
}
77
77
78
- // Custom assertFileExists method
79
- public void assertFileExists (final String filePath , final String message ) {
78
+ // Custom assertFileExistsInTempFolder method
79
+ public void assertFileExistsInTempFolder (final String filePath , final String message ) {
80
80
final File file = new File (tempFolder .getRoot (), filePath );
81
81
Assert .assertTrue (message , file .exists ());
82
82
}
83
83
84
- public void assertFileExists (final String filePath ) {
85
- assertFileExists (filePath , null );
84
+ public void assertFileExistsInTempFolder (final String filePath ) {
85
+ assertFileExistsInTempFolder (filePath , null );
86
86
}
87
87
88
- // Custom assertFileNotExists method
89
- public void assertFileNotExists (final String filePath , final String message ) {
88
+ // Custom assertFileNotExistsInTempFolder method
89
+ public void assertFileNotExistsInTempFolder (final String filePath , final String message ) {
90
90
final File file = new File (tempFolder .getRoot (), filePath );
91
91
Assert .assertFalse (message , file .exists ());
92
92
}
93
93
94
- public void assertFileNotExists (final String filePath ) {
95
- assertFileNotExists (filePath , null );
94
+ public void assertFileNotExistsInTempFolder (final String filePath ) {
95
+ assertFileNotExistsInTempFolder (filePath , null );
96
96
}
97
97
98
98
// Count the number of files in the directory
99
99
public static int countFiles (final File directory ) {
100
100
int fileCount = 0 ;
101
101
File [] files = directory .listFiles ();
102
- assert files != null ;
103
102
for (File file : files ) {
104
103
if (file .isFile () && file .exists ()) {
105
104
fileCount ++;
@@ -117,8 +116,8 @@ public void noneProvidedNothingDeleted() throws IOException, InterruptedExceptio
117
116
118
117
action .perform (mockRun );
119
118
120
- assertTempFolderContains (6 );
121
- assertFileExists ("testFolder/test1.xml" );
119
+ assertTempFolderContainsFileCount (6 );
120
+ assertFileExistsInTempFolder ("testFolder/test1.xml" );
122
121
}
123
122
124
123
@ Test // test 2, inc="", exc="**", nothing deleted
@@ -128,7 +127,7 @@ public void excludesOnlyNothingDeleted() throws IOException, InterruptedExceptio
128
127
129
128
action .perform (mockRun );
130
129
131
- assertTempFolderContains (6 );
130
+ assertTempFolderContainsFileCount (6 );
132
131
}
133
132
134
133
@ Test // test 3, inc="**", exc="**", nothing deleted
@@ -138,7 +137,7 @@ public void bothProvidedNothingDeleted() throws IOException, InterruptedExceptio
138
137
139
138
action .perform (mockRun );
140
139
141
- assertTempFolderContains (6 );
140
+ assertTempFolderContainsFileCount (6 );
142
141
}
143
142
144
143
@ Test // test 4, inc="**", exc="", everything deleted
@@ -160,9 +159,9 @@ public void everythingDeletedButExcludePatterns() throws IOException, Interrupte
160
159
161
160
action .perform (mockRun );
162
161
163
- assertTempFolderContains (2 );
164
- assertFileExists ("testLog.log" );
165
- assertFileExists ("testFolder/testLog1.log" , "Log files should have been excluded." );
162
+ assertTempFolderContainsFileCount (2 );
163
+ assertFileExistsInTempFolder ("testLog.log" );
164
+ assertFileExistsInTempFolder ("testFolder/testLog1.log" , "Log files should have been excluded." );
166
165
}
167
166
168
167
@ Test // test 5.1 inc="**", exc="**/*.log, **/*.txt" everything except logs and txt
@@ -173,10 +172,10 @@ public void everythingDeletedButMultipleExcludePatterns() throws IOException, In
173
172
174
173
action .perform (mockRun );
175
174
176
- assertTempFolderContains (4 );
177
- assertFileExists ("testLog.log" );
178
- assertFileNotExists ("test.xml" , "XML files should have been deleted." );
179
- assertFileNotExists ("testFolder/test1.xml" );
175
+ assertTempFolderContainsFileCount (4 );
176
+ assertFileExistsInTempFolder ("testLog.log" );
177
+ assertFileNotExistsInTempFolder ("test.xml" , "XML files should have been deleted." );
178
+ assertFileNotExistsInTempFolder ("testFolder/test1.xml" );
180
179
}
181
180
182
181
@ Test // test 6 inc="*.txt", exc="**/*.log" only text files in the root are deleted
@@ -186,8 +185,8 @@ public void selectiveFileDeletionRootOnly() throws IOException, InterruptedExcep
186
185
187
186
action .perform (mockRun );
188
187
189
- assertTempFolderContains (5 );
190
- assertFileNotExists ("testTxt.txt" );
188
+ assertTempFolderContainsFileCount (5 );
189
+ assertFileNotExistsInTempFolder ("testTxt.txt" );
191
190
}
192
191
193
192
@ Test // test 6.1 inc="*.txt, *.xml", exc="**/*.log" only txt files and xml files in
@@ -198,9 +197,9 @@ public void multipleIncludePatternFilesDeletionRootOnly() throws IOException, In
198
197
199
198
action .perform (mockRun );
200
199
201
- assertTempFolderContains (4 );
202
- assertFileNotExists ("testTxt.txt" );
203
- assertFileNotExists ("test.xml" );
200
+ assertTempFolderContainsFileCount (4 );
201
+ assertFileNotExistsInTempFolder ("testTxt.txt" );
202
+ assertFileNotExistsInTempFolder ("test.xml" );
204
203
}
205
204
206
205
@ Test // test 6.2 inc="*.txt, **/*.xml", exc="**/*.log" only txt files and xml files
@@ -211,9 +210,9 @@ public void multipleIncludePatternsFilesDeletion() throws IOException, Interrupt
211
210
212
211
action .perform (mockRun );
213
212
214
- assertTempFolderContains (3 );
215
- assertFileExists ("testLog.log" );
216
- assertFileNotExists ("test.xml" );
213
+ assertTempFolderContainsFileCount (3 );
214
+ assertFileExistsInTempFolder ("testLog.log" );
215
+ assertFileNotExistsInTempFolder ("test.xml" );
217
216
}
218
217
219
218
@ Test // test 7 inc="**/*.txt", exc="**/*.log", all text files are deleted
@@ -223,9 +222,9 @@ public void deleteIncludeMatchingFilesButExcludePatterns() throws IOException, I
223
222
224
223
action .perform (mockRun );
225
224
226
- assertTempFolderContains (4 );
227
- assertFileExists ("testLog.log" );
228
- assertFileNotExists ("testTxt.txt" );
225
+ assertTempFolderContainsFileCount (4 );
226
+ assertFileExistsInTempFolder ("testLog.log" );
227
+ assertFileNotExistsInTempFolder ("testTxt.txt" );
229
228
}
230
229
231
230
@ Test // test 8 inc="**/*.txt", exc="*.txt", all text files but those in the root are
@@ -236,9 +235,9 @@ public void selectiveFileDeletionExcludeRoot() throws IOException, InterruptedEx
236
235
237
236
action .perform (mockRun );
238
237
239
- assertTempFolderContains (5 );
240
- assertFileExists ("testTxt.txt" );
241
- assertFileNotExists ("testFolder/testTxt1.txt" );
238
+ assertTempFolderContainsFileCount (5 );
239
+ assertFileExistsInTempFolder ("testTxt.txt" );
240
+ assertFileNotExistsInTempFolder ("testFolder/testTxt1.txt" );
242
241
}
243
242
244
243
@ Test // test 9, inc="../**", exc=""
@@ -266,7 +265,7 @@ public void nothingDeletedWhenPointingAboveStartingPoint() throws IOException, I
266
265
Assert .assertTrue (folder .exists ());
267
266
Assert .assertTrue (archiveFolder .exists ());
268
267
Assert .assertTrue (buildXML .exists ());
269
- assertFileExists ("archive/test1.xml" );
268
+ assertFileExistsInTempFolder ("archive/test1.xml" );
270
269
}
271
270
272
271
@ Test // testing getIncludePatterns method for code coverage
0 commit comments