Skip to content

Commit

Permalink
Migrate SnapshotTest to JUnit 5 eclipse-platform#903
Browse files Browse the repository at this point in the history
This migrates the SnapshotTest to JUnit 5, using the
SessionTestExtension with the CustomSessionWorkspace. Also re-enables
the test cases on MacOS.

Contributes to
eclipse-platform#903
  • Loading branch information
HeikoKlare committed May 16, 2024
1 parent 08f15a2 commit abeb265
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 87 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import static org.eclipse.core.tests.resources.ResourceTestUtil.assertExistsInWorkspace;
import static org.eclipse.core.tests.resources.ResourceTestUtil.buildResources;
import static org.eclipse.core.tests.resources.ResourceTestUtil.createInWorkspace;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
Expand All @@ -29,7 +31,7 @@
* as expected (failing or not) and may add more "user actions" to be
* verified in the next session and so on.
*/
public class Snapshot1Test extends SnapshotTest {
public class Snapshot1Test {

protected static String[] defineHierarchy1() {
return new String[] {"/folder110/", "/folder110/folder120/", "/folder110/folder120/folder130/", "/folder110/folder120/folder130/folder140/", "/folder110/folder120/folder130/folder140/folder150/", "/folder110/folder120/folder130/folder140/folder150/file160", "/folder110/folder120/folder130/folder140/file150", "/folder110/folder121/", "/folder110/folder121/folder131/", "/folder110/folder120/folder130/folder141/"};
Expand All @@ -41,11 +43,11 @@ protected static String[] defineHierarchy2() {

// copy and paste in the scrapbook to run
public void testCreateMyProject() throws CoreException {
IProject project = getWorkspace().getRoot().getProject(PROJECT_1);
IProject project = getWorkspace().getRoot().getProject(SnapshotTest.PROJECT_1);
project.create(null);
project.open(null);
assertTrue("0.1", project.exists());
assertTrue("0.2", project.isOpen());
assertTrue(project.exists());
assertTrue(project.isOpen());

// create some children
IResource[] resources = buildResources(project, defineHierarchy1());
Expand All @@ -54,19 +56,19 @@ public void testCreateMyProject() throws CoreException {
assertExistsInWorkspace(resources);

project.close(null);
assertTrue("2.1", project.exists());
assertTrue("2.2", !project.isOpen());
assertTrue(project.exists());
assertFalse(project.isOpen());
}

/**
* Create another project and leave it closed for next session.
*/
public void testCreateProject2() throws CoreException {
IProject project = getWorkspace().getRoot().getProject(PROJECT_2);
IProject project = getWorkspace().getRoot().getProject(SnapshotTest.PROJECT_2);
project.create(null);
project.open(null);
assertTrue("0.1", project.exists());
assertTrue("0.2", project.isOpen());
assertTrue(project.exists());
assertTrue(project.isOpen());

// create some children
IResource[] resources = buildResources(project, defineHierarchy2());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import static org.eclipse.core.tests.resources.ResourceTestUtil.assertExistsInWorkspace;
import static org.eclipse.core.tests.resources.ResourceTestUtil.buildResources;
import static org.eclipse.core.tests.resources.ResourceTestUtil.createInWorkspace;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.ArrayList;
import java.util.Arrays;
Expand All @@ -34,15 +36,15 @@
* but not written to disk (only in the tree).
* Only snapshots are taken. No full saves.
*/
public class Snapshot2Test extends SnapshotTest {
public class Snapshot2Test {

protected static String[] defineHierarchy1() {
List<String> result = new ArrayList<>();
String[] old = Snapshot1Test.defineHierarchy1();
result.addAll(Arrays.asList(old));
result.add(IPath.fromOSString(PROJECT_1).append("added file").toString());
result.add(IPath.fromOSString(PROJECT_1).append("yet another file").toString());
result.add(IPath.fromOSString(PROJECT_1).append("a folder").addTrailingSeparator().toString());
result.add(IPath.fromOSString(SnapshotTest.PROJECT_1).append("added file").toString());
result.add(IPath.fromOSString(SnapshotTest.PROJECT_1).append("yet another file").toString());
result.add(IPath.fromOSString(SnapshotTest.PROJECT_1).append("a folder").addTrailingSeparator().toString());
return result.toArray(new String[result.size()]);
}

Expand All @@ -52,9 +54,9 @@ protected static String[] defineHierarchy2() {

public void testChangeMyProject() throws CoreException {
// MyProject
IProject project = getWorkspace().getRoot().getProject(PROJECT_1);
assertTrue("0.1", project.exists());
assertTrue("0.2", project.isOpen());
IProject project = getWorkspace().getRoot().getProject(SnapshotTest.PROJECT_1);
assertTrue(project.exists());
assertTrue(project.isOpen());

// create some children
IResource[] resources = buildResources(project, defineHierarchy1());
Expand All @@ -64,9 +66,9 @@ public void testChangeMyProject() throws CoreException {
}

public void testChangeProject2() throws CoreException {
IProject project = getWorkspace().getRoot().getProject("Project2");
assertTrue("0.1", project.exists());
assertTrue("0.2", project.isOpen());
IProject project = getWorkspace().getRoot().getProject(SnapshotTest.PROJECT_2);
assertTrue(project.exists());
assertTrue(project.isOpen());

// remove all resources
IResource[] children = project.members();
Expand All @@ -85,22 +87,22 @@ public void testSnapshotWorkspace() throws CoreException {

public void testVerifyPreviousSession() throws CoreException {
// MyProject
IProject project = getWorkspace().getRoot().getProject(PROJECT_1);
assertTrue("0.0", project.exists());
assertTrue("0.1", !project.isOpen());
IProject project = getWorkspace().getRoot().getProject(SnapshotTest.PROJECT_1);
assertTrue(project.exists());
assertFalse(project.isOpen());

project.open(null);
assertTrue("1.2", project.isOpen());
assertTrue(project.isOpen());

// verify existence of children
IResource[] resources = buildResources(project, Snapshot1Test.defineHierarchy1());
assertExistsInFileSystem(resources);
assertExistsInWorkspace(resources);

// Project2
project = getWorkspace().getRoot().getProject(PROJECT_2);
assertTrue("3.0", project.exists());
assertTrue("3.1", project.isOpen());
project = getWorkspace().getRoot().getProject(SnapshotTest.PROJECT_2);
assertTrue(project.exists());
assertTrue(project.isOpen());

// verify existence of children
resources = buildResources(project, Snapshot1Test.defineHierarchy2());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import static org.eclipse.core.tests.resources.ResourceTestUtil.assertExistsInFileSystem;
import static org.eclipse.core.tests.resources.ResourceTestUtil.assertExistsInWorkspace;
import static org.eclipse.core.tests.resources.ResourceTestUtil.buildResources;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IProjectDescription;
Expand All @@ -28,7 +30,7 @@
* This session only performs a full save. The workspace should stay
* the same.
*/
public class Snapshot3Test extends SnapshotTest {
public class Snapshot3Test {

protected static String[] defineHierarchy1() {
return Snapshot2Test.defineHierarchy1();
Expand All @@ -44,22 +46,22 @@ public void testSaveWorkspace() throws CoreException {

public void testVerifyPreviousSession() throws CoreException {
// MyProject
IProject project = getWorkspace().getRoot().getProject(PROJECT_1);
assertTrue("0.0", project.exists());
assertTrue("0.1", project.isOpen());
IProject project = getWorkspace().getRoot().getProject(SnapshotTest.PROJECT_1);
assertTrue(project.exists());
assertTrue(project.isOpen());

// verify existence of children
IResource[] resources = buildResources(project, Snapshot2Test.defineHierarchy1());
assertExistsInFileSystem(resources);
assertExistsInWorkspace(resources);

// Project2
project = getWorkspace().getRoot().getProject(PROJECT_2);
assertTrue("3.0", project.exists());
assertTrue("3.1", project.isOpen());
project = getWorkspace().getRoot().getProject(SnapshotTest.PROJECT_2);
assertTrue(project.exists());
assertTrue(project.isOpen());

assertThat(project.members()).hasSize(4);
assertNotNull("4.1", project.findMember(IProjectDescription.DESCRIPTION_FILE_NAME));
assertNotNull(project.findMember(IProjectDescription.DESCRIPTION_FILE_NAME));

// verify existence of children
resources = buildResources(project, Snapshot2Test.defineHierarchy2());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
import static org.eclipse.core.tests.resources.ResourceTestUtil.assertExistsInFileSystem;
import static org.eclipse.core.tests.resources.ResourceTestUtil.assertExistsInWorkspace;
import static org.eclipse.core.tests.resources.ResourceTestUtil.buildResources;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.ArrayList;
import java.util.Arrays;
Expand All @@ -36,15 +39,15 @@
/**
* Change some resources mixing full saves and snapshots.
*/
public class Snapshot4Test extends SnapshotTest {
public class Snapshot4Test {

protected static String[] defineHierarchy1() {
List<String> result = new ArrayList<>();
String[] old = Snapshot3Test.defineHierarchy1();
result.addAll(Arrays.asList(old));
result.remove(IPath.fromOSString(PROJECT_1).append("added file").toString());
result.remove(IPath.fromOSString(PROJECT_1).append("yet another file").toString());
result.remove(IPath.fromOSString(PROJECT_1).append("a folder").addTrailingSeparator().toString());
result.remove(IPath.fromOSString(SnapshotTest.PROJECT_1).append("added file").toString());
result.remove(IPath.fromOSString(SnapshotTest.PROJECT_1).append("yet another file").toString());
result.remove(IPath.fromOSString(SnapshotTest.PROJECT_1).append("a folder").addTrailingSeparator().toString());
return result.toArray(new String[result.size()]);
}

Expand All @@ -54,9 +57,9 @@ protected static String[] defineHierarchy2() {

public void testChangeMyProject() throws CoreException {
// MyProject
IProject project = getWorkspace().getRoot().getProject(PROJECT_1);
assertTrue("0.1", project.exists());
assertTrue("0.2", project.isOpen());
IProject project = getWorkspace().getRoot().getProject(SnapshotTest.PROJECT_1);
assertTrue(project.exists());
assertTrue(project.isOpen());

// remove resources
IFile file = project.getFile("added file");
Expand Down Expand Up @@ -87,36 +90,36 @@ public void testChangeMyProject() throws CoreException {
}

public void testChangeProject2() throws CoreException {
IProject project = getWorkspace().getRoot().getProject(PROJECT_2);
assertTrue("0.1", project.exists());
assertTrue("0.2", project.isOpen());
IProject project = getWorkspace().getRoot().getProject(SnapshotTest.PROJECT_2);
assertTrue(project.exists());
assertTrue(project.isOpen());

// remove project
project.delete(true, true, null);
assertTrue("1.1", !project.exists());
assertFalse(project.exists());

// snapshot
getWorkspace().save(false, null);
}

public void testVerifyPreviousSession() throws CoreException {
// MyProject
IProject project = getWorkspace().getRoot().getProject(PROJECT_1);
assertTrue("0.0", project.exists());
assertTrue("0.1", project.isOpen());
IProject project = getWorkspace().getRoot().getProject(SnapshotTest.PROJECT_1);
assertTrue(project.exists());
assertTrue(project.isOpen());

// verify existence of children
IResource[] resources = buildResources(project, Snapshot3Test.defineHierarchy1());
assertExistsInFileSystem(resources);
assertExistsInWorkspace(resources);

// Project2
project = getWorkspace().getRoot().getProject(PROJECT_2);
assertTrue("3.0", project.exists());
assertTrue("3.1", project.isOpen());
project = getWorkspace().getRoot().getProject(SnapshotTest.PROJECT_2);
assertTrue(project.exists());
assertTrue(project.isOpen());

assertThat(project.members()).hasSize(4);
assertNotNull("4.1", project.findMember(IProjectDescription.DESCRIPTION_FILE_NAME));
assertNotNull(project.findMember(IProjectDescription.DESCRIPTION_FILE_NAME));

// verify existence of children
resources = buildResources(project, Snapshot3Test.defineHierarchy2());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import static org.eclipse.core.tests.resources.ResourceTestUtil.assertExistsInFileSystem;
import static org.eclipse.core.tests.resources.ResourceTestUtil.assertExistsInWorkspace;
import static org.eclipse.core.tests.resources.ResourceTestUtil.buildResources;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
Expand All @@ -29,12 +31,12 @@
/**
* Only verifies previous session.
*/
public class Snapshot5Test extends SnapshotTest {
public class Snapshot5Test {
public void testVerifyPreviousSession() throws CoreException {
// MyProject
IProject project = getWorkspace().getRoot().getProject(PROJECT_1);
assertTrue("0.0", project.exists());
assertTrue("0.1", project.isOpen());
IProject project = getWorkspace().getRoot().getProject(SnapshotTest.PROJECT_1);
assertTrue(project.exists());
assertTrue(project.isOpen());

// verify existence of children
IResource[] resources = buildResources(project, Snapshot4Test.defineHierarchy1());
Expand All @@ -51,8 +53,8 @@ public void testVerifyPreviousSession() throws CoreException {
assertDoesNotExistInWorkspace(folder);

// Project2
project = getWorkspace().getRoot().getProject(PROJECT_2);
assertTrue("3.0", !project.exists());
project = getWorkspace().getRoot().getProject(SnapshotTest.PROJECT_2);
assertFalse(project.exists());
}

}
Loading

0 comments on commit abeb265

Please sign in to comment.