Skip to content

Commit 972fe6e

Browse files
author
Nurgul Amat
committed
Refactor: Rename the method names for asserting a file exists or not
1 parent 6bd3c90 commit 972fe6e

File tree

1 file changed

+35
-36
lines changed

1 file changed

+35
-36
lines changed

src/test/java/pl/damianszczepanik/jenkins/buildhistorymanager/model/actions/DeleteArtifactsMatchingPatternsActionTest.java

+35-36
Original file line numberDiff line numberDiff line change
@@ -68,38 +68,37 @@ public void setup() throws IOException {
6868
deleteFileCallableInstance = new DeleteArtifactsMatchingPatternsAction.DeleteFileCallable(archiveRootDirectory);
6969
}
7070

71-
private void assertTempFolderContains(final int expectedNumFiles) {
71+
private void assertTempFolderContainsFileCount(final int expectedNumFiles) {
7272
final int actualNumFiles = countFiles(tempFolder.getRoot());
7373
final String assertMessage = String.format("Expected %d files, actual found %d files", expectedNumFiles,
7474
actualNumFiles);
7575
Assert.assertEquals(assertMessage, expectedNumFiles, actualNumFiles);
7676
}
7777

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) {
8080
final File file = new File(tempFolder.getRoot(), filePath);
8181
Assert.assertTrue(message, file.exists());
8282
}
8383

84-
public void assertFileExists(final String filePath) {
85-
assertFileExists(filePath, null);
84+
public void assertFileExistsInTempFolder(final String filePath) {
85+
assertFileExistsInTempFolder(filePath, null);
8686
}
8787

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) {
9090
final File file = new File(tempFolder.getRoot(), filePath);
9191
Assert.assertFalse(message, file.exists());
9292
}
9393

94-
public void assertFileNotExists(final String filePath) {
95-
assertFileNotExists(filePath, null);
94+
public void assertFileNotExistsInTempFolder(final String filePath) {
95+
assertFileNotExistsInTempFolder(filePath, null);
9696
}
9797

9898
// Count the number of files in the directory
9999
public static int countFiles(final File directory) {
100100
int fileCount = 0;
101101
File[] files = directory.listFiles();
102-
assert files != null;
103102
for (File file : files) {
104103
if (file.isFile() && file.exists()) {
105104
fileCount++;
@@ -117,8 +116,8 @@ public void noneProvidedNothingDeleted() throws IOException, InterruptedExceptio
117116

118117
action.perform(mockRun);
119118

120-
assertTempFolderContains(6);
121-
assertFileExists("testFolder/test1.xml");
119+
assertTempFolderContainsFileCount(6);
120+
assertFileExistsInTempFolder("testFolder/test1.xml");
122121
}
123122

124123
@Test // test 2, inc="", exc="**", nothing deleted
@@ -128,7 +127,7 @@ public void excludesOnlyNothingDeleted() throws IOException, InterruptedExceptio
128127

129128
action.perform(mockRun);
130129

131-
assertTempFolderContains(6);
130+
assertTempFolderContainsFileCount(6);
132131
}
133132

134133
@Test // test 3, inc="**", exc="**", nothing deleted
@@ -138,7 +137,7 @@ public void bothProvidedNothingDeleted() throws IOException, InterruptedExceptio
138137

139138
action.perform(mockRun);
140139

141-
assertTempFolderContains(6);
140+
assertTempFolderContainsFileCount(6);
142141
}
143142

144143
@Test // test 4, inc="**", exc="", everything deleted
@@ -160,9 +159,9 @@ public void everythingDeletedButExcludePatterns() throws IOException, Interrupte
160159

161160
action.perform(mockRun);
162161

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.");
166165
}
167166

168167
@Test // test 5.1 inc="**", exc="**/*.log, **/*.txt" everything except logs and txt
@@ -173,10 +172,10 @@ public void everythingDeletedButMultipleExcludePatterns() throws IOException, In
173172

174173
action.perform(mockRun);
175174

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");
180179
}
181180

182181
@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
186185

187186
action.perform(mockRun);
188187

189-
assertTempFolderContains(5);
190-
assertFileNotExists("testTxt.txt");
188+
assertTempFolderContainsFileCount(5);
189+
assertFileNotExistsInTempFolder("testTxt.txt");
191190
}
192191

193192
@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
198197

199198
action.perform(mockRun);
200199

201-
assertTempFolderContains(4);
202-
assertFileNotExists("testTxt.txt");
203-
assertFileNotExists("test.xml");
200+
assertTempFolderContainsFileCount(4);
201+
assertFileNotExistsInTempFolder("testTxt.txt");
202+
assertFileNotExistsInTempFolder("test.xml");
204203
}
205204

206205
@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
211210

212211
action.perform(mockRun);
213212

214-
assertTempFolderContains(3);
215-
assertFileExists("testLog.log");
216-
assertFileNotExists("test.xml");
213+
assertTempFolderContainsFileCount(3);
214+
assertFileExistsInTempFolder("testLog.log");
215+
assertFileNotExistsInTempFolder("test.xml");
217216
}
218217

219218
@Test // test 7 inc="**/*.txt", exc="**/*.log", all text files are deleted
@@ -223,9 +222,9 @@ public void deleteIncludeMatchingFilesButExcludePatterns() throws IOException, I
223222

224223
action.perform(mockRun);
225224

226-
assertTempFolderContains(4);
227-
assertFileExists("testLog.log");
228-
assertFileNotExists("testTxt.txt");
225+
assertTempFolderContainsFileCount(4);
226+
assertFileExistsInTempFolder("testLog.log");
227+
assertFileNotExistsInTempFolder("testTxt.txt");
229228
}
230229

231230
@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
236235

237236
action.perform(mockRun);
238237

239-
assertTempFolderContains(5);
240-
assertFileExists("testTxt.txt");
241-
assertFileNotExists("testFolder/testTxt1.txt");
238+
assertTempFolderContainsFileCount(5);
239+
assertFileExistsInTempFolder("testTxt.txt");
240+
assertFileNotExistsInTempFolder("testFolder/testTxt1.txt");
242241
}
243242

244243
@Test // test 9, inc="../**", exc=""
@@ -266,7 +265,7 @@ public void nothingDeletedWhenPointingAboveStartingPoint() throws IOException, I
266265
Assert.assertTrue(folder.exists());
267266
Assert.assertTrue(archiveFolder.exists());
268267
Assert.assertTrue(buildXML.exists());
269-
assertFileExists("archive/test1.xml");
268+
assertFileExistsInTempFolder("archive/test1.xml");
270269
}
271270

272271
@Test // testing getIncludePatterns method for code coverage

0 commit comments

Comments
 (0)