Skip to content

Commit

Permalink
Formatting the test code
Browse files Browse the repository at this point in the history
  • Loading branch information
Nurgul Amat committed Aug 4, 2023
1 parent 7755f8b commit 437eb7b
Showing 1 changed file with 23 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ public class DeleteArtifactsWithPatternActionTest {

@BeforeClass
public static void beforeClass() {
System.setProperty("java.util.logging.config.file", ClassLoader.getSystemResource("logging.properties").getPath());
System.setProperty("java.util.logging.config.file",
ClassLoader.getSystemResource("logging.properties").getPath());
}

@Rule
Expand All @@ -46,7 +47,7 @@ public void setup() throws IOException {
VirtualFile root = VirtualFile.forFile(tempFolder.getRoot());
Mockito.when(mockArtifactManager.root()).thenReturn(root);

//Create the tempFolder and its contents
// Create the tempFolder and its contents
tempFolder.newFile("test.xml");
tempFolder.newFile("testLog.log");
tempFolder.newFile("testTxt.txt");
Expand All @@ -58,14 +59,14 @@ public void setup() throws IOException {

private void assertTempFolderContains(final int expectedNumFiles) {
final int actualNumFiles = countFiles(tempFolder.getRoot());
final String assertMessage = String.format("Expected %d files, actual found %d files", expectedNumFiles, actualNumFiles);
final String assertMessage = String.format("Expected %d files, actual found %d files", expectedNumFiles,
actualNumFiles);
Assert.assertEquals(assertMessage, expectedNumFiles, actualNumFiles);

}

// Custom assertFileExists method
public void assertFileExists(final String filePath, final String message) {
final File file = new File(tempFolder.getRoot(), filePath);
final File file = new File(tempFolder.getRoot(), filePath);
Assert.assertTrue(message, file.exists());
}

Expand All @@ -86,7 +87,7 @@ public void assertFileNotExists(final String filePath) {
// Count the number of files in the directory
public static int countFiles(final File directory) {
int fileCount = 0;
File[] files = directory.listFiles();
File[] files = directory.listFiles();
for (File file : files) {
if (file.isFile() && file.exists()) {
fileCount++;
Expand All @@ -108,7 +109,7 @@ public void noneProvidedNothingDeleted() throws IOException, InterruptedExceptio
assertFileExists("testFolder/test1.xml");
}

@Test //test 2, inc="", exc="**", nothing deleted
@Test // test 2, inc="", exc="**", nothing deleted
public void excludesOnlyNothingDeleted() throws IOException, InterruptedException {
action.setInclude("");
action.setExclude("**");
Expand Down Expand Up @@ -152,7 +153,8 @@ public void everythingDeletedButExcludePatterns() throws IOException, Interrupte
assertFileExists("testFolder/testLog1.log", "Log files should have been excluded.");
}

@Test // test 5.1 inc="**", exc="**/*.log, **/*.txt" everything except logs and txt files are deleted
@Test // test 5.1 inc="**", exc="**/*.log, **/*.txt" everything except logs and txt
// files are deleted
public void everythingDeletedButMultipleExcludePatterns() throws IOException, InterruptedException {
action.setInclude("**");
action.setExclude("**/*.log, **/*.txt");
Expand All @@ -165,7 +167,7 @@ public void everythingDeletedButMultipleExcludePatterns() throws IOException, In
assertFileNotExists("testFolder/test1.xml");
}

@Test //test 6 inc="*.txt", exc="**/*.log" only text files in the root are deleted
@Test // test 6 inc="*.txt", exc="**/*.log" only text files in the root are deleted
public void selectiveFileDeletionRootOnly() throws IOException, InterruptedException {
action.setInclude("*.txt");
action.setExclude("**/*.log");
Expand All @@ -176,7 +178,8 @@ public void selectiveFileDeletionRootOnly() throws IOException, InterruptedExcep
assertFileNotExists("testTxt.txt");
}

@Test //test 6.1 inc="*.txt, *.xml", exc="**/*.log" only txt files and xml files in the root are deleted
@Test // test 6.1 inc="*.txt, *.xml", exc="**/*.log" only txt files and xml files in
// the root are deleted
public void multipleIncludePatternFilesDeletionRootOnly() throws IOException, InterruptedException {
action.setInclude("*.txt, *.xml");
action.setExclude("**/*.log");
Expand All @@ -188,7 +191,8 @@ public void multipleIncludePatternFilesDeletionRootOnly() throws IOException, In
assertFileNotExists("test.xml");
}

@Test //test 6.2 inc="*.txt, **/*.xml", exc="**/*.log" only txt files and xml files are deleted
@Test // test 6.2 inc="*.txt, **/*.xml", exc="**/*.log" only txt files and xml files
// are deleted
public void multipleIncludePatternFilesDeletion() throws IOException, InterruptedException {
action.setInclude("*.txt, **/*.xml");
action.setExclude("**/*.log");
Expand All @@ -212,7 +216,8 @@ public void deleteIncludeMatchingFilesButExcludePatterns() throws IOException, I
assertFileNotExists("testTxt.txt");
}

@Test // test 8 inc="**/*.txt", exc="*.txt", all text files but those in the root are deleted
@Test // test 8 inc="**/*.txt", exc="*.txt", all text files but those in the root are
// deleted
public void selectiveFileDeletionExcludeRoot() throws IOException, InterruptedException {
action.setInclude("**/*.txt");
action.setExclude("*.txt");
Expand Down Expand Up @@ -312,7 +317,8 @@ public void testIsDirEmptyNonExistentDirectory() throws IOException {

@Test // testing checkRoles method for code coverage
public void testCheckRolesNoException() throws IOException, InterruptedException {
DeleteArtifactsWithPatternAction.Delete actionDelete = new DeleteArtifactsWithPatternAction.Delete("archiveRootPath/");
DeleteArtifactsWithPatternAction.Delete actionDelete = new DeleteArtifactsWithPatternAction.Delete(
"archiveRootPath/");
RoleChecker mockRoleChecker = Mockito.mock(RoleChecker.class);

actionDelete.checkRoles(mockRoleChecker);
Expand All @@ -330,12 +336,14 @@ public void testDeleteParentDirectories() throws IOException, InterruptedExcepti

// Set up Delete instance with the archiveRootPath
String archiveRootPath = archiveRootDir.getAbsolutePath();
DeleteArtifactsWithPatternAction.Delete deleteInstance = new DeleteArtifactsWithPatternAction.Delete(archiveRootPath);
DeleteArtifactsWithPatternAction.Delete deleteInstance = new DeleteArtifactsWithPatternAction.Delete(
archiveRootPath);

// Call the method
deleteInstance.deleteParentDirectories(childDir);

// Verify that child, parent and grandparent directories are deleted, but the archive root directory remains
// Verify that child, parent and grandparent directories are deleted, but the
// archive root directory remains
Assert.assertFalse(childDir.exists());
Assert.assertFalse(parentDir.exists());
Assert.assertFalse(grandparentDir.exists());
Expand Down

0 comments on commit 437eb7b

Please sign in to comment.