Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate all tests in o.e.team.tests.core.* to JUnit 4 #903 #997

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
*******************************************************************************/
package org.eclipse.team.tests.core;

import org.eclipse.core.tests.resources.ResourceTest;
import org.eclipse.team.tests.core.regression.AllTeamRegressionTests;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
Expand All @@ -27,5 +26,5 @@
StreamTests.class, //
UserMappingTest.class, //
})
public class AllTeamTests extends ResourceTest {
public class AllTeamTests {
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,26 @@
*******************************************************************************/
package org.eclipse.team.tests.core;

import junit.framework.Test;
import static org.junit.Assert.assertNotNull;

import org.eclipse.core.runtime.Platform;
import org.eclipse.team.core.Team;
import org.eclipse.team.core.mapping.IStorageMerger;
import org.junit.Test;

public class StorageMergerTests extends TeamTest {

public StorageMergerTests() {
super();
}

public StorageMergerTests(String name) {
super(name);
}

public static Test suite() {
return suite(StorageMergerTests.class);
}
public class StorageMergerTests {

@Test
public void testGetByExtension() {
IStorageMerger merger = new Team().createStorageMerger("blah");
IStorageMerger merger = Team.createMerger("blah");
assertNotNull("Merger for extension is missing", merger);
}

@Test
public void testGetByContentType() {
IStorageMerger merger = new Team().createStorageMerger(Platform.getContentTypeManager().getContentType("org.eclipse.team.tests.core.content-type1"));
IStorageMerger merger = Team.createMerger(
Platform.getContentTypeManager().getContentType("org.eclipse.team.tests.core.content-type1"));
assertNotNull("Merger for extension is missing", merger);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,19 @@
*******************************************************************************/
package org.eclipse.team.tests.core;

import static org.junit.Assert.assertEquals;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;

import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.eclipse.team.internal.core.streams.CRLFtoLFInputStream;
import org.eclipse.team.internal.core.streams.LFtoCRLFInputStream;
import org.junit.Test;

public class StreamTests extends TestCase {

public StreamTests(String name) {
super(name);
}

public static Test suite() {
return new TestSuite(StreamTests.class);
}
public class StreamTests {

@Test
public void testCRLFtoLFInputStream() throws IOException {
testCRLFtoLFTranslation("", "");
testCRLFtoLFTranslation("a", "a");
Expand All @@ -52,6 +45,7 @@ private void testCRLFtoLFTranslation(String pre, String post) throws IOException
assertStreamEquals(inExpected, in);
}

@Test
public void testLFtoCRLFInputStream() throws IOException {
testLFtoCRLFTranslation("", "");
testLFtoCRLFTranslation("a", "a");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,21 @@
*******************************************************************************/
package org.eclipse.team.tests.core;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.team.internal.core.TeamPlugin;
import org.eclipse.team.internal.core.UserStringMappings;
import org.junit.Test;
import org.osgi.service.prefs.BackingStoreException;

import junit.framework.TestSuite;

@SuppressWarnings("restriction")
public final class UserMappingTest extends TeamTest {
public final class UserMappingTest {

private static final String KEY = "key";

@Test
public void testParsedCorrectly() {
UserStringMappings mappings = mappings();
assertEquals((int) UserStringMappings.TEXT, mappings.getType("*.ext"));
Expand All @@ -35,13 +37,15 @@ public void testParsedCorrectly() {
assertEquals((int) UserStringMappings.UNKNOWN, mappings.getType(null));
}

@Test
public void testPicksExternalChanges() throws BackingStoreException {
UserStringMappings mappings = mappings();
assertEquals((int) UserStringMappings.UNKNOWN, mappings.getType("some"));
modify("some\n2\n");
assertEquals((int) UserStringMappings.BINARY, mappings.getType("some"));
}

@Test
public void testAcceptsCorruptedData() throws BackingStoreException {
UserStringMappings mappings = mappings();
assertEquals((int) UserStringMappings.TEXT, mappings.getType("*.ext"));
Expand All @@ -63,8 +67,4 @@ private UserStringMappings mappings() {
return mappings;
}

public static TestSuite suite() {
return new TestSuite(UserMappingTest.class);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,34 @@
*******************************************************************************/
package org.eclipse.team.tests.core.mapping;

import java.lang.reflect.InvocationTargetException;
import static org.eclipse.core.resources.ResourcesPlugin.getWorkspace;
import static org.eclipse.core.tests.resources.ResourceTestUtil.buildResources;
import static org.eclipse.core.tests.resources.ResourceTestUtil.createInWorkspace;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertThrows;

import junit.framework.Test;
import java.lang.reflect.InvocationTargetException;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.mapping.*;
import org.eclipse.core.runtime.*;
import org.eclipse.core.resources.mapping.ResourceMapping;
import org.eclipse.core.resources.mapping.ResourceMappingContext;
import org.eclipse.core.resources.mapping.ResourceTraversal;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.tests.resources.WorkspaceTestRule;
import org.eclipse.team.core.mapping.ISynchronizationScopeManager;
import org.eclipse.team.core.mapping.provider.SynchronizationScopeManager;
import org.eclipse.team.internal.core.mapping.ResourceMappingScope;
import org.eclipse.team.tests.core.TeamTest;
import org.eclipse.team.ui.synchronize.ModelOperation;
import org.junit.Rule;
import org.junit.Test;

public class ScopeBuildingTests {

public class ScopeBuildingTests extends TeamTest {
@Rule
public WorkspaceTestRule workspaceRule = new WorkspaceTestRule();

private static final RuntimeException PROMPT_EXCEPTION = new RuntimeException();
protected static final String TEST_MODEL_PROVIDER_ID = "id1";
Expand Down Expand Up @@ -63,31 +76,9 @@ protected void execute(IProgressMonitor monitor) throws InvocationTargetExceptio
}
}

public static Test suite() {
return suite(ScopeBuildingTests.class);
}

public ScopeBuildingTests() {
super();
}

public ScopeBuildingTests(String name) {
super(name);
}

private void expectPrompt(TestResourceMappingOperation op) {
try {
op.run(new NullProgressMonitor());
} catch (InvocationTargetException e) {
fail("Unexpected exception: " + e.getTargetException().getMessage());
} catch (InterruptedException e) {
fail("Unexpected interupt");
} catch (RuntimeException e) {
if (e == PROMPT_EXCEPTION)
return;
throw e;
}
fail("Expected prompt did not occur");
RuntimeException exception = assertThrows(RuntimeException.class, () -> op.run(new NullProgressMonitor()));
assertSame("expected prompt did not occur", exception, PROMPT_EXCEPTION);
}

private ResourceMapping getMapping(final IProject project, final IResource[] resources, final int depth) {
Expand Down Expand Up @@ -121,8 +112,14 @@ public boolean contains(ResourceMapping mapping) {
};
}

@Test
public void testAdditionalResources() throws CoreException {
IProject project = createProject(new String[]{"file.txt", "folder1/file2.txt", "folder1/folder2/file3.txt", "folder3/"});
IProject project = getWorkspace().getRoot().getProject("Project");
createInWorkspace(project);
IResource[] contents = buildResources(project,
new String[] { "file.txt", "folder1/file2.txt", "folder1/folder2/file3.txt", "folder3/" });
createInWorkspace(contents);

ResourceMapping[] mappings = new ResourceMapping[] {
getMapping(project, new IResource[] { project.getFolder("folder1") }, IResource.DEPTH_INFINITE)
};
Expand All @@ -133,5 +130,4 @@ public void testAdditionalResources() throws CoreException {
expectPrompt(op);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -13,49 +13,61 @@
*******************************************************************************/
package org.eclipse.team.tests.core.mapping;

import junit.framework.Test;
import static org.eclipse.core.resources.ResourcesPlugin.getWorkspace;
import static org.eclipse.core.tests.resources.ResourceTestUtil.createInWorkspace;
import static org.junit.Assert.fail;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.mapping.ResourceMapping;
import org.eclipse.core.runtime.*;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.OperationCanceledException;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.core.tests.resources.WorkspaceTestRule;
import org.eclipse.team.core.mapping.ISynchronizationScopeManager;
import org.eclipse.team.core.subscribers.SubscriberScopeManager;
import org.eclipse.team.internal.ui.Utils;
import org.eclipse.team.tests.core.TeamTest;
import org.eclipse.ui.*;
import org.eclipse.ui.IWorkingSet;
import org.eclipse.ui.IWorkingSetManager;
import org.eclipse.ui.PlatformUI;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;

public class ScopeTests extends TeamTest {
public class ScopeTests {

@Rule
public WorkspaceTestRule workspaceRule = new WorkspaceTestRule();

public static Test suite() {
return suite(ScopeTests.class);
}
private IProject project1, project2, project3;
private IWorkingSet workingSet;
private SubscriberScopeManager manager;

public ScopeTests() {
super();
}

public ScopeTests(String name) {
super(name);
}

@Override
protected void setUp() throws Exception {
super.setUp();
project1 = createProject("p1", new String[]{"file.txt"});
project2 = createProject("p2", new String[]{"file.txt"});
project3 = createProject("p3", new String[]{"file.txt"});
@Before
public void setUp() throws Exception {
project1 = createProjectWithFile("p1", "file.txt");
project2 = createProjectWithFile("p2", "file.txt");
project3 = createProjectWithFile("p3", "file.txt");
IWorkingSetManager manager = PlatformUI.getWorkbench().getWorkingSetManager();
workingSet = manager.createWorkingSet("TestWS", new IProject[] { project1 });
manager.addWorkingSet(workingSet);
}

@Override
protected void tearDown() throws Exception {
super.tearDown();
/*
* This method creates a project with the given resources
*/
private IProject createProjectWithFile(String name, String fileName) throws CoreException {
IProject project = getWorkspace().getRoot().getProject(name);
createInWorkspace(project);
createInWorkspace(project.getFile(fileName));
return project;
}

@After
public void tearDown() throws Exception {
this.manager.dispose();
IWorkingSetManager manager = PlatformUI.getWorkbench().getWorkingSetManager();
manager.removeWorkingSet(workingSet);
Expand Down Expand Up @@ -100,13 +112,15 @@ private ISynchronizationScopeManager createScopeManager() throws CoreException,
return manager;
}

@Test
public void testScopeExpansion() throws CoreException, OperationCanceledException, InterruptedException {
ISynchronizationScopeManager sm = createScopeManager();
assertProperContainment(sm);
workingSet.setElements( new IProject[] { project1, project2 });
assertProperContainment(sm);
}

@Test
public void testScopeContraction() throws OperationCanceledException, InterruptedException, CoreException {
workingSet.setElements( new IProject[] { project1, project2 });
ISynchronizationScopeManager sm = createScopeManager();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,31 @@
*******************************************************************************/
package org.eclipse.team.tests.core.regression;

import junit.framework.Test;
import junit.framework.TestSuite;

import static org.eclipse.core.resources.ResourcesPlugin.getWorkspace;
import static org.eclipse.core.tests.harness.FileSystemHelper.getRandomLocation;
import static org.eclipse.core.tests.resources.ResourceTestUtil.createUniqueString;
import static org.eclipse.core.tests.resources.ResourceTestUtil.setReadOnly;
import static org.junit.Assert.assertTrue;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.ResourceAttributes;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.tests.resources.WorkspaceTestRule;
import org.eclipse.team.core.RepositoryProvider;
import org.eclipse.team.tests.core.TeamTest;
import static org.eclipse.core.tests.resources.ResourceTestUtil.*;
import org.junit.Rule;
import org.junit.Test;

public class Bug_217673 extends TeamTest {
public class Bug_217673 {

public void test() throws CoreException {
@Rule
public WorkspaceTestRule workspaceRule = new WorkspaceTestRule();

IWorkspace workspace = ResourcesPlugin.getWorkspace();
@Test
public void test() throws CoreException {
IWorkspace workspace = getWorkspace();
final IProject project = workspace.getRoot().getProject(
createUniqueString());
project.create(null);
Expand Down Expand Up @@ -63,8 +67,4 @@ private boolean isReadOnly(IResource resource) {
return resourceAttributes.isReadOnly();
}

public static Test suite() {
return new TestSuite(Bug_217673.class);
}

}
Loading
Loading