Skip to content

Commit

Permalink
Refactor tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael5601 committed Aug 16, 2024
1 parent da18d3b commit 7021245
Show file tree
Hide file tree
Showing 13 changed files with 464 additions and 686 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@

package org.eclipse.core.tests.filesystem.zip;

import static org.eclipse.core.tests.filesystem.zip.ZipFileSystemTestUtil.ensureExists;
import static org.junit.Assert.assertTrue;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.ZipFileTransformer;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.params.ParameterizedTest;
Expand All @@ -26,7 +26,7 @@ public class CloseTest {

@BeforeEach
public void setup() throws Exception {
ZipFileSystemTestSetup.defaultSetup();
ZipFileSystemTestSetup.setup();
}

@AfterEach
Expand All @@ -35,19 +35,19 @@ public void teardown() throws Exception {
}

@ParameterizedTest
@MethodSource("org.eclipse.core.tests.filesystem.zip.ZipFileSystemTestUtil#zipFileNames")
@MethodSource("org.eclipse.core.tests.filesystem.zip.ZipFileSystemTestSetup#zipFileNames")
public void testCloseZipFile(String zipFileName) throws Exception {
IFolder openedZipFile = ZipFileSystemTestSetup.firstProject
IFolder openedZipFile = ZipFileSystemTestSetup.projects.get(0)
.getFolder(zipFileName);
ensureExists(openedZipFile);
ZipFileSystemTestUtil.closeZipFile(openedZipFile);
IFile zipFile = ZipFileSystemTestSetup.firstProject
ZipFileSystemTestSetup.ensureExists(openedZipFile);
ZipFileTransformer.closeZipFile(openedZipFile);
IFile zipFile = ZipFileSystemTestSetup.projects.get(0)
.getFile(zipFileName);
// Don't use Utility method ensureDoesNotExist because the fileStore is still
// available after closing. The fileStore is the File itself in the local file
// system that still exists after closing.
assertTrue("folder was not properly deleted: " + openedZipFile, !openedZipFile.exists());
ensureExists(zipFile);
ZipFileSystemTestSetup.ensureExists(zipFile);
}

/*
Expand All @@ -56,26 +56,23 @@ public void testCloseZipFile(String zipFileName) throws Exception {
* file in the project is deleted so the linked file has no target.
*/
@ParameterizedTest
@MethodSource("org.eclipse.core.tests.filesystem.zip.ZipFileSystemTestUtil#zipFileNames")
@MethodSource("org.eclipse.core.tests.filesystem.zip.ZipFileSystemTestSetup#zipFileNames")
public void testCloseZipFileWithZipFileUnderneath(String zipFileName) throws Exception {
IFolder firstOpenedZipFile = ZipFileSystemTestSetup.firstProject
IFolder firstZipFile = ZipFileSystemTestSetup.projects.get(0)
.getFolder(zipFileName);
ensureExists(firstOpenedZipFile);
String secondZipFileName = zipFileName.replace(".", "New.");
ZipFileSystemTestSetup.copyZipFileIntoProject(ZipFileSystemTestSetup.firstProject, secondZipFileName);
IFile secondZipFile = ZipFileSystemTestSetup.firstProject.getFile(secondZipFileName);
ZipFileSystemTestUtil.openZipFile(secondZipFile);
IFolder secondOpenedZipFile = ZipFileSystemTestSetup.firstProject.getFolder(secondZipFileName);
ensureExists(secondOpenedZipFile);
String secondZipFileName = zipFileName.replace(".", "2.");
ZipFileSystemTestSetup.copyZipFileIntoProject(ZipFileSystemTestSetup.projects.get(0), secondZipFileName);
ZipFileTransformer.openZipFile(ZipFileSystemTestSetup.projects.get(0).getFile(secondZipFileName), true);
IFolder secondZipFile = ZipFileSystemTestSetup.projects.get(0).getFolder(secondZipFileName);

ZipFileSystemTestUtil.closeZipFile(firstOpenedZipFile);
IFile zipFile = ZipFileSystemTestSetup.firstProject
ZipFileTransformer.closeZipFile(firstZipFile);
IFile closedZipFile = ZipFileSystemTestSetup.projects.get(0)
.getFile(zipFileName);
// Don't use Utility method ensureDoesNotExist because the fileStore is still
// available after closing. The fileStore is the File itself in the local file
// system that still exists after closing.
assertTrue("folder was not properly deleted: " + firstOpenedZipFile, !firstOpenedZipFile.exists());
ensureExists(zipFile);
ensureExists(secondOpenedZipFile);
assertTrue("folder was not properly deleted: " + firstZipFile, !firstZipFile.exists());
ZipFileSystemTestSetup.ensureExists(closedZipFile);
ZipFileSystemTestSetup.ensureExists(secondZipFile);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,10 @@

package org.eclipse.core.tests.filesystem.zip;

import static org.eclipse.core.tests.filesystem.zip.ZipFileSystemTestUtil.assertTextFileContent;
import static org.eclipse.core.tests.filesystem.zip.ZipFileSystemTestUtil.ensureDoesNotExist;
import static org.eclipse.core.tests.filesystem.zip.ZipFileSystemTestUtil.ensureExists;
import static org.eclipse.core.tests.filesystem.zip.ZipFileSystemTestUtil.getMonitor;

import java.io.ByteArrayInputStream;
import java.io.InputStream;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.params.ParameterizedTest;
Expand All @@ -33,7 +28,7 @@ public class CopyTest {

@BeforeEach
public void setup() throws Exception {
ZipFileSystemTestSetup.defaultSetup();
ZipFileSystemTestSetup.setup();
}

@AfterEach
Expand All @@ -42,175 +37,151 @@ public void teardown() throws Exception {
}

@ParameterizedTest
@MethodSource("org.eclipse.core.tests.filesystem.zip.ZipFileSystemTestUtil#zipFileNames")
@MethodSource("org.eclipse.core.tests.filesystem.zip.ZipFileSystemTestSetup#zipFileNames")
public void testCopyZipFile(String zipFileName) throws Exception {
IFolder openedZipFile = ZipFileSystemTestSetup.firstProject
IFolder openedZipFile = ZipFileSystemTestSetup.projects.get(0)
.getFolder(zipFileName);
ensureExists(openedZipFile);
IFolder destinationFolder = ZipFileSystemTestSetup.firstProject.getFolder("Folder");
destinationFolder.create(true, true, getMonitor());
ensureExists(destinationFolder);
IFolder copyDestination = ZipFileSystemTestSetup.firstProject
ZipFileSystemTestSetup.ensureExists(openedZipFile);
IFolder destinationFolder = ZipFileSystemTestSetup.projects.get(0).getFolder("Folder");
destinationFolder.create(true, true, new NullProgressMonitor());
ZipFileSystemTestSetup.ensureExists(destinationFolder);
IFolder copyDestination = ZipFileSystemTestSetup.projects.get(0)
.getFolder("Folder" + "/" + zipFileName);
openedZipFile.copy(copyDestination.getFullPath(), true, getMonitor());
ensureExists(copyDestination);
ensureExists(openedZipFile);
openedZipFile.copy(copyDestination.getFullPath(), true, new NullProgressMonitor());
ZipFileSystemTestSetup.ensureExists(copyDestination);
ZipFileSystemTestSetup.ensureExists(openedZipFile);
}

@ParameterizedTest
@MethodSource("org.eclipse.core.tests.filesystem.zip.ZipFileSystemTestUtil#zipFileNames")
@MethodSource("org.eclipse.core.tests.filesystem.zip.ZipFileSystemTestSetup#zipFileNames")
public void testCopyFileInsideOfZipFile(String zipFileName) throws Exception {
IFile textFile = ZipFileSystemTestSetup.firstProject.getFile(
IFile textFile = ZipFileSystemTestSetup.projects.get(0).getFile(
zipFileName + "/" + ZipFileSystemTestSetup.TEXT_FILE_NAME);
ensureExists(textFile);
IFolder destinationFolder = ZipFileSystemTestSetup.firstProject.getFolder("Folder");
destinationFolder.create(true, true, getMonitor());
ensureExists(destinationFolder);
IFile copyDestination = ZipFileSystemTestSetup.firstProject
ZipFileSystemTestSetup.ensureExists(textFile);
IFolder destinationFolder = ZipFileSystemTestSetup.projects.get(0).getFolder("Folder");
destinationFolder.create(true, true, new NullProgressMonitor());
ZipFileSystemTestSetup.ensureExists(destinationFolder);
IFile copyDestination = ZipFileSystemTestSetup.projects.get(0)
.getFile("Folder" + "/" + ZipFileSystemTestSetup.TEXT_FILE_NAME);
textFile.copy(copyDestination.getFullPath(), true, getMonitor());
ensureExists(copyDestination);
ensureExists(textFile);
textFile.copy(copyDestination.getFullPath(), true, new NullProgressMonitor());
ZipFileSystemTestSetup.ensureExists(copyDestination);
ZipFileSystemTestSetup.ensureExists(textFile);
}

@ParameterizedTest
@MethodSource("org.eclipse.core.tests.filesystem.zip.ZipFileSystemTestUtil#zipFileNames")
@MethodSource("org.eclipse.core.tests.filesystem.zip.ZipFileSystemTestSetup#zipFileNames")
public void testCopyFolderInsideOfZipFile(String zipFileName) throws Exception {
IFolder openedZipFile = ZipFileSystemTestSetup.firstProject
IFolder openedZipFile = ZipFileSystemTestSetup.projects.get(0)
.getFolder(zipFileName);
ensureExists(openedZipFile);
IFolder newFolder = ZipFileSystemTestSetup.firstProject.getFolder("NewFolder");
ensureDoesNotExist(newFolder);
newFolder.create(false, true, getMonitor());
ensureExists(newFolder);
ZipFileSystemTestSetup.ensureExists(openedZipFile);
IFolder newFolder = ZipFileSystemTestSetup.projects.get(0).getFolder("NewFolder");
ZipFileSystemTestSetup.ensureDoesNotExist(newFolder);
newFolder.create(false, true, new NullProgressMonitor());
ZipFileSystemTestSetup.ensureExists(newFolder);
IFile textFile = newFolder.getFile("NewFile.txt");
ensureDoesNotExist(textFile);
String text = "Foo";
InputStream stream = new ByteArrayInputStream(text.getBytes());
textFile.create(stream, true, getMonitor());
stream.close();
ensureExists(textFile);
ZipFileSystemTestSetup.ensureDoesNotExist(textFile);
textFile.create(new ByteArrayInputStream(new byte[0]), true, new NullProgressMonitor());
ZipFileSystemTestSetup.ensureExists(textFile);
IFolder copyDestination = openedZipFile.getFolder("NewFolder");
ensureDoesNotExist(copyDestination);
newFolder.copy(copyDestination.getFullPath(), true, getMonitor());
ensureExists(copyDestination);
ensureExists(newFolder);
assertTextFileContent(textFile, "Foo");
ZipFileSystemTestSetup.ensureDoesNotExist(copyDestination);
newFolder.copy(copyDestination.getFullPath(), true, new NullProgressMonitor());
ZipFileSystemTestSetup.ensureExists(copyDestination);
ZipFileSystemTestSetup.ensureExists(newFolder);
}

@ParameterizedTest
@MethodSource("org.eclipse.core.tests.filesystem.zip.ZipFileSystemTestUtil#zipFileNames")
@MethodSource("org.eclipse.core.tests.filesystem.zip.ZipFileSystemTestSetup#zipFileNames")
public void testCopyFileIntoZipFile(String zipFileName) throws Exception {
IFile textFile = ZipFileSystemTestSetup.firstProject.getFile("NewFile.txt");
ensureDoesNotExist(textFile);
String text = "Foo";
InputStream stream = new ByteArrayInputStream(text.getBytes());
textFile.create(stream, true, getMonitor());
stream.close();
ensureExists(textFile);
IFile copyDestination = ZipFileSystemTestSetup.firstProject
IFile textFile = ZipFileSystemTestSetup.projects.get(0).getFile("NewFile.txt");
ZipFileSystemTestSetup.ensureDoesNotExist(textFile);
textFile.create(new ByteArrayInputStream(new byte[0]), true, new NullProgressMonitor());
ZipFileSystemTestSetup.ensureExists(textFile);
IFile copyDestination = ZipFileSystemTestSetup.projects.get(0)
.getFile(zipFileName + "/" + "NewFile.txt");
textFile.copy(copyDestination.getFullPath(), true, getMonitor());
ensureExists(copyDestination);
ensureExists(textFile);
assertTextFileContent(textFile, "Foo");
textFile.copy(copyDestination.getFullPath(), true, new NullProgressMonitor());
ZipFileSystemTestSetup.ensureExists(copyDestination);
ZipFileSystemTestSetup.ensureExists(textFile);
}

@ParameterizedTest
@MethodSource("org.eclipse.core.tests.filesystem.zip.ZipFileSystemTestUtil#zipFileNames")
@MethodSource("org.eclipse.core.tests.filesystem.zip.ZipFileSystemTestSetup#zipFileNames")
public void testCopyFolderIntoZipFile(String zipFileName) throws Exception {
IFile textFile = ZipFileSystemTestSetup.firstProject.getFile("NewFile.txt");
ensureDoesNotExist(textFile);
String text = "Foo";
InputStream stream = new ByteArrayInputStream(text.getBytes());
textFile.create(stream, true, getMonitor());
stream.close();
ensureExists(textFile);
IFile copyDestination = ZipFileSystemTestSetup.firstProject
IFile textFile = ZipFileSystemTestSetup.projects.get(0).getFile("NewFile.txt");
ZipFileSystemTestSetup.ensureDoesNotExist(textFile);
textFile.create(new ByteArrayInputStream(new byte[0]), true, new NullProgressMonitor());
ZipFileSystemTestSetup.ensureExists(textFile);
IFile copyDestination = ZipFileSystemTestSetup.projects.get(0)
.getFile(zipFileName + "/" + "NewFile.txt");
textFile.copy(copyDestination.getFullPath(), true, getMonitor());
ensureExists(copyDestination);
ensureExists(textFile);
assertTextFileContent(textFile, "Foo");
textFile.copy(copyDestination.getFullPath(), true, new NullProgressMonitor());
ZipFileSystemTestSetup.ensureExists(copyDestination);
ZipFileSystemTestSetup.ensureExists(textFile);
}

@ParameterizedTest
@MethodSource("org.eclipse.core.tests.filesystem.zip.ZipFileSystemTestUtil#zipFileNames")
@MethodSource("org.eclipse.core.tests.filesystem.zip.ZipFileSystemTestSetup#zipFileNames")
public void testCopyFileFromOutsideOfZipFIleIntoFolderInZipFile(String zipFileName) throws Exception {
IFolder openedZipFile = ZipFileSystemTestSetup.firstProject
IFolder openedZipFile = ZipFileSystemTestSetup.projects.get(0)
.getFolder(zipFileName);
IFolder newFolder = openedZipFile.getFolder("NewFolder");
ensureDoesNotExist(newFolder);
newFolder.create(false, true, getMonitor());
ensureExists(newFolder);
IFile textFile = ZipFileSystemTestSetup.firstProject.getFile("NewFile.txt");
ensureDoesNotExist(textFile);
String text = "Foo";
InputStream stream = new ByteArrayInputStream(text.getBytes());
textFile.create(stream, true, getMonitor());
stream.close();
ensureExists(textFile);
ZipFileSystemTestSetup.ensureDoesNotExist(newFolder);
newFolder.create(false, true, new NullProgressMonitor());
ZipFileSystemTestSetup.ensureExists(newFolder);
IFile textFile = ZipFileSystemTestSetup.projects.get(0).getFile("NewFile.txt");
ZipFileSystemTestSetup.ensureDoesNotExist(textFile);
textFile.create(new ByteArrayInputStream(new byte[0]), true, new NullProgressMonitor());
ZipFileSystemTestSetup.ensureExists(textFile);
IFile copyDestination = newFolder.getFile("NewFile.txt");
ensureDoesNotExist(copyDestination);
textFile.copy(copyDestination.getFullPath(), true, getMonitor());
ensureExists(copyDestination);
ensureExists(textFile);
assertTextFileContent(textFile, "Foo");
ZipFileSystemTestSetup.ensureDoesNotExist(copyDestination);
textFile.copy(copyDestination.getFullPath(), true, new NullProgressMonitor());
ZipFileSystemTestSetup.ensureExists(copyDestination);
ZipFileSystemTestSetup.ensureExists(textFile);
}

@ParameterizedTest
@MethodSource("org.eclipse.core.tests.filesystem.zip.ZipFileSystemTestUtil#zipFileNames")
@MethodSource("org.eclipse.core.tests.filesystem.zip.ZipFileSystemTestSetup#zipFileNames")
public void testCopyFolderIntoFolderInZipFile(String zipFileName) throws Exception {
IFolder openedZipFile = ZipFileSystemTestSetup.firstProject
IFolder openedZipFile = ZipFileSystemTestSetup.projects.get(0)
.getFolder(zipFileName);
IFolder firstNewFolder = openedZipFile.getFolder("FirstNewFolder");
ensureDoesNotExist(firstNewFolder);
firstNewFolder.create(false, true, getMonitor());
ensureExists(firstNewFolder);
ZipFileSystemTestSetup.ensureDoesNotExist(firstNewFolder);
firstNewFolder.create(false, true, new NullProgressMonitor());
ZipFileSystemTestSetup.ensureExists(firstNewFolder);
IFolder secondNewFolder = openedZipFile.getFolder("SecondNewFolder");
ensureDoesNotExist(secondNewFolder);
secondNewFolder.create(false, true, getMonitor());
ensureExists(secondNewFolder);
ZipFileSystemTestSetup.ensureDoesNotExist(secondNewFolder);
secondNewFolder.create(false, true, new NullProgressMonitor());
ZipFileSystemTestSetup.ensureExists(secondNewFolder);
IFile textFile = firstNewFolder.getFile("NewFile.txt");
ensureDoesNotExist(textFile);
String text = "Foo";
try (InputStream stream = new ByteArrayInputStream(text.getBytes())) {
textFile.create(stream, true, getMonitor());
}
ensureExists(textFile);
ZipFileSystemTestSetup.ensureDoesNotExist(textFile);
textFile.create(new ByteArrayInputStream(new byte[0]), true, new NullProgressMonitor());
ZipFileSystemTestSetup.ensureExists(textFile);
IFolder copyDestination = secondNewFolder.getFolder("FirstNewFolder");
ensureDoesNotExist(copyDestination);
firstNewFolder.copy(copyDestination.getFullPath(), true, getMonitor());
ensureExists(copyDestination);
ensureExists(firstNewFolder);
assertTextFileContent(textFile, "Foo");
ZipFileSystemTestSetup.ensureDoesNotExist(copyDestination);
firstNewFolder.copy(copyDestination.getFullPath(), true, new NullProgressMonitor());
ZipFileSystemTestSetup.ensureExists(copyDestination);
ZipFileSystemTestSetup.ensureExists(firstNewFolder);
}

@ParameterizedTest
@MethodSource("org.eclipse.core.tests.filesystem.zip.ZipFileSystemTestUtil#zipFileNames")
@MethodSource("org.eclipse.core.tests.filesystem.zip.ZipFileSystemTestSetup#zipFileNames")
public void testCopyFileFromOneFolderToOtherFolderInsideofZipFile(String zipFileName) throws Exception {
IFolder openedZipFile = ZipFileSystemTestSetup.firstProject
IFolder openedZipFile = ZipFileSystemTestSetup.projects.get(0)
.getFolder(zipFileName);
IFolder firstNewFolder = openedZipFile.getFolder("FirstNewFolder");
ensureDoesNotExist(firstNewFolder);
firstNewFolder.create(false, true, getMonitor());
ensureExists(firstNewFolder);
ZipFileSystemTestSetup.ensureDoesNotExist(firstNewFolder);
firstNewFolder.create(false, true, new NullProgressMonitor());
ZipFileSystemTestSetup.ensureExists(firstNewFolder);
IFolder secondNewFolder = openedZipFile.getFolder("SecondNewFolder");
ensureDoesNotExist(secondNewFolder);
secondNewFolder.create(false, true, getMonitor());
ensureExists(secondNewFolder);
ZipFileSystemTestSetup.ensureDoesNotExist(secondNewFolder);
secondNewFolder.create(false, true, new NullProgressMonitor());
ZipFileSystemTestSetup.ensureExists(secondNewFolder);
IFile textFile = firstNewFolder.getFile("NewFile.txt");
ensureDoesNotExist(textFile);
String text = "Foo";
try (InputStream stream = new ByteArrayInputStream(text.getBytes())) {
textFile.create(stream, true, getMonitor());
}
ensureExists(textFile);
ZipFileSystemTestSetup.ensureDoesNotExist(textFile);
textFile.create(new ByteArrayInputStream(new byte[0]), true, new NullProgressMonitor());
ZipFileSystemTestSetup.ensureExists(textFile);
IFile copyDestination = secondNewFolder.getFile("NewFile.txt");
ensureDoesNotExist(copyDestination);
textFile.copy(copyDestination.getFullPath(), true, getMonitor());
ensureExists(copyDestination);
ensureExists(textFile);
assertTextFileContent(textFile, "Foo");
ZipFileSystemTestSetup.ensureDoesNotExist(copyDestination);
textFile.copy(copyDestination.getFullPath(), true, new NullProgressMonitor());
ZipFileSystemTestSetup.ensureExists(copyDestination);
ZipFileSystemTestSetup.ensureExists(textFile);
}
}
Loading

0 comments on commit 7021245

Please sign in to comment.