1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-11 19:15:22 +02:00

launch bar: renamed test so it picked by gerrit verifier

- also mocked another target so it does not always test local one

Change-Id: Idf59342aac75bf5c92c5ca63870eade760065f70
Signed-off-by: Alena Laskavaia <elaskavaia.cdt@gmail.com>
This commit is contained in:
Alena Laskavaia 2015-03-18 16:28:55 -04:00
parent b447d528f8
commit 28985bd18d

View file

@ -54,7 +54,7 @@ import org.junit.Test;
import org.junit.runners.MethodSorters; import org.junit.runners.MethodSorters;
@FixMethodOrder(MethodSorters.JVM) @FixMethodOrder(MethodSorters.JVM)
public class LaunchBarManagerTest2 { public class LaunchBarManager2Test {
private LaunchBarManager manager; private LaunchBarManager manager;
private ILaunchConfigurationProvider provider; private ILaunchConfigurationProvider provider;
private ILaunchDescriptor descriptor; private ILaunchDescriptor descriptor;
@ -68,10 +68,14 @@ public class LaunchBarManagerTest2 {
IEclipsePreferences store = new EclipsePreferences(); IEclipsePreferences store = new EclipsePreferences();
private ArrayList<Object> elements; private ArrayList<Object> elements;
private IExtension extension; private IExtension extension;
private String targetTypeId; private String localTargetTypeId;
private String descriptorTypeId; private String descriptorTypeId;
private IRemoteConnection localtarget; private IRemoteConnection localTarget;
private String launchObject; private String launchObject;
private IRemoteServicesManager remoteServiceManager;
private IRemoteConnection otherTarget;
private String otherTargetTypeId;
private List<IRemoteConnection> targets;
public class FixedLaunchBarManager extends LaunchBarManager { public class FixedLaunchBarManager extends LaunchBarManager {
public FixedLaunchBarManager() throws CoreException { public FixedLaunchBarManager() throws CoreException {
@ -97,6 +101,11 @@ public class LaunchBarManagerTest2 {
IRemoteLaunchConfigService getRemoteLaunchConfigService() { IRemoteLaunchConfigService getRemoteLaunchConfigService() {
return mock(IRemoteLaunchConfigService.class); return mock(IRemoteLaunchConfigService.class);
} }
@Override
IRemoteServicesManager getRemoteServicesManager() {
return remoteServiceManager;
}
}; };
@Before @Before
@ -133,7 +142,7 @@ public class LaunchBarManagerTest2 {
protected void init() throws CoreException { protected void init() throws CoreException {
doReturn(elements.toArray(new IConfigurationElement[0])).when(extension).getConfigurationElements(); doReturn(elements.toArray(new IConfigurationElement[0])).when(extension).getConfigurationElements();
// Now inject the launch object doReturn(targets).when(remoteServiceManager).getAllRemoteConnections();
manager.init(); manager.init();
} }
@ -159,24 +168,6 @@ public class LaunchBarManagerTest2 {
return element; return element;
} }
@Test
public void testDescriptor() throws Exception {
// Create a descriptor type and inject an associated object
// Make sure the descriptor is active with the local target and proper mode
// Make sure the associated launch config is active too
// Mocking
manager.launchObjectAdded(launchObject);
assertEquals(descriptor, manager.getActiveLaunchDescriptor());
IRemoteServicesManager remoteManager = Activator.getService(IRemoteServicesManager.class);
IRemoteConnectionType localServices = remoteManager.getLocalConnectionType();
IRemoteConnection localConnection = localServices.getConnections().get(0);
assertNotNull(localConnection);
assertEquals(localConnection, manager.getActiveLaunchTarget());
assertEquals(launchConfig, manager.getActiveLaunchConfiguration());
assertNotNull(manager.getActiveLaunchMode());
assertEquals("run", manager.getActiveLaunchMode().getIdentifier());
}
protected void mockLaunchObjectOnDescriptor(Object launchObject) throws CoreException { protected void mockLaunchObjectOnDescriptor(Object launchObject) throws CoreException {
doReturn(true).when(descriptorType).ownsLaunchObject(launchObject); doReturn(true).when(descriptorType).ownsLaunchObject(launchObject);
doReturn(descriptor).when(descriptorType).getDescriptor(launchObject); doReturn(descriptor).when(descriptorType).getDescriptor(launchObject);
@ -275,6 +266,7 @@ public class LaunchBarManagerTest2 {
lman = mock(ILaunchManager.class); lman = mock(ILaunchManager.class);
doReturn(globalmodes.toArray(new ILaunchMode[globalmodes.size()])).when(lman).getLaunchModes(); doReturn(globalmodes.toArray(new ILaunchMode[globalmodes.size()])).when(lman).getLaunchModes();
doReturn(new ILaunchConfiguration[] {}).when(lman).getLaunchConfigurations(); doReturn(new ILaunchConfiguration[] {}).when(lman).getLaunchConfigurations();
remoteServiceManager = spy(Activator.getService(IRemoteServicesManager.class));
manager = new FixedLaunchBarManager(); manager = new FixedLaunchBarManager();
// mock // mock
// lc // lc
@ -283,7 +275,7 @@ public class LaunchBarManagerTest2 {
// launch config type // launch config type
mockLaunchModes(launchConfigType, "run", "debug"); mockLaunchModes(launchConfigType, "run", "debug");
// target // target
targetTypeId = mockLocalTargetElement(); localTargetTypeId = mockLocalTargetElement();
// launch descriptor and type // launch descriptor and type
descriptorType = mock(ILaunchDescriptorType.class); descriptorType = mock(ILaunchDescriptorType.class);
descriptorTypeId = "descType"; descriptorTypeId = "descType";
@ -294,11 +286,33 @@ public class LaunchBarManagerTest2 {
provider = mock(ILaunchConfigurationProvider.class); provider = mock(ILaunchConfigurationProvider.class);
mockProviderElement(provider); mockProviderElement(provider);
mockProviderTypes(provider); mockProviderTypes(provider);
// configType
mockConfigTypeElement(targetTypeId, descriptorTypeId, launchConfigType.getIdentifier());
launchObject = "test"; launchObject = "test";
mockLaunchObjectOnDescriptor(launchObject); mockLaunchObjectOnDescriptor(launchObject);
localtarget = manager.getRemoteServicesManager().getLocalConnectionType().getConnections().get(0); localTarget = manager.getRemoteServicesManager().getLocalConnectionType().getConnections().get(0);
otherTargetTypeId = "target2";
mockTargetElement(otherTargetTypeId);
otherTarget = mock(IRemoteConnection.class);
IRemoteConnectionType rtype = mock(IRemoteConnectionType.class);
doReturn(rtype).when(otherTarget).getConnectionType();
doReturn(otherTargetTypeId).when(rtype).getId();
targets = Arrays.asList(new IRemoteConnection[] { otherTarget, localTarget });
// configType
mockConfigTypeElement(otherTargetTypeId, descriptorTypeId, launchConfigType.getIdentifier());
}
@Test
public void testDescriptor() throws Exception {
// Create a descriptor type and inject an associated object
// Make sure the descriptor is active with the local target and proper mode
// Make sure the associated launch config is active too
// Mocking
manager.launchObjectAdded(launchObject);
assertEquals(descriptor, manager.getActiveLaunchDescriptor());
assertEquals(otherTarget, manager.getActiveLaunchTarget());
assertEquals(launchConfig, manager.getActiveLaunchConfiguration());
assertNotNull(manager.getActiveLaunchMode());
assertEquals("run", manager.getActiveLaunchMode().getIdentifier());
} }
@Test @Test
@ -384,7 +398,7 @@ public class LaunchBarManagerTest2 {
manager.setActiveLaunchDescriptor(descriptor); manager.setActiveLaunchDescriptor(descriptor);
List<IRemoteConnection> launchTargets = manager.getLaunchTargets(descriptor); List<IRemoteConnection> launchTargets = manager.getLaunchTargets(descriptor);
assertEquals(1, launchTargets.size()); assertEquals(1, launchTargets.size());
assertEquals(localtarget, launchTargets.get(0)); assertEquals(otherTarget, launchTargets.get(0));
} }
@Test @Test
@ -406,7 +420,7 @@ public class LaunchBarManagerTest2 {
elements.clear(); elements.clear();
mockLocalTargetElement(); mockLocalTargetElement();
mockDescriptorTypeElement(descriptorTypeId, descriptorType); mockDescriptorTypeElement(descriptorTypeId, descriptorType);
mockConfigTypeElement(targetTypeId, descriptorTypeId, launchConfigType.getIdentifier()); mockConfigTypeElement(localTargetTypeId, descriptorTypeId, launchConfigType.getIdentifier());
init(); init();
manager.launchObjectAdded(launchObject); manager.launchObjectAdded(launchObject);
ILaunchDescriptor desc = manager.getActiveLaunchDescriptor(); ILaunchDescriptor desc = manager.getActiveLaunchDescriptor();
@ -579,10 +593,10 @@ public class LaunchBarManagerTest2 {
aaa = mockProject("aaa"); aaa = mockProject("aaa");
descriptor = new ProjectLaunchDescriptor(descriptorType, aaa); descriptor = new ProjectLaunchDescriptor(descriptorType, aaa);
// setup some stuff // setup some stuff
targetTypeId = mockLocalTargetElement(); localTargetTypeId = mockLocalTargetElement();
IConfigurationElement element = mockDescriptorTypeElement(descriptorTypeId, descriptorType); IConfigurationElement element = mockDescriptorTypeElement(descriptorTypeId, descriptorType);
// configType // configType
mockConfigTypeElement(targetTypeId, descriptorTypeId, launchConfigType.getIdentifier()); mockConfigTypeElement(localTargetTypeId, descriptorTypeId, launchConfigType.getIdentifier());
//lc = provider.createLaunchConfiguration(lman, descType.getDescriptor(aaa)); //lc = provider.createLaunchConfiguration(lman, descType.getDescriptor(aaa));
mockLCProject(launchConfig, aaa); mockLCProject(launchConfig, aaa);
String ORIGINAL_NAME = org.eclipse.launchbar.core.internal.Activator.PLUGIN_ID + ".originalName"; String ORIGINAL_NAME = org.eclipse.launchbar.core.internal.Activator.PLUGIN_ID + ".originalName";
@ -593,7 +607,7 @@ public class LaunchBarManagerTest2 {
} }
/** /**
* This scenario when provider will change mapping element->descriptor, depending on other objects involved * Test duplicating a config. make sure it's default desc and same targets
*/ */
@Test @Test
public void testLaunchObjectAddedRemapping() throws CoreException { public void testLaunchObjectAddedRemapping() throws CoreException {
@ -806,11 +820,11 @@ public class LaunchBarManagerTest2 {
@Test @Test
public void testGetActiveLaunchModeFromDescActive() throws CoreException { public void testGetActiveLaunchModeFromDescActive() throws CoreException {
mockLaunchModes(launchConfigType, "run"); globalmodes.clear();
ILaunchMode mode = mockLaunchModes(launchConfigType, "foo")[0]; ILaunchMode mode = mockLaunchModes(launchConfigType, "foo","run")[0];
manager.launchObjectAdded(launchObject); manager.launchObjectAdded(launchObject);
manager.setActiveLaunchMode(mode);
manager.setActiveLaunchDescriptor(descriptor); manager.setActiveLaunchDescriptor(descriptor);
manager.setActiveLaunchMode(mode);
ILaunchMode resmode = manager.getActiveLaunchMode(); ILaunchMode resmode = manager.getActiveLaunchMode();
assertNotNull(resmode); assertNotNull(resmode);
assertEquals("foo", resmode.getIdentifier()); assertEquals("foo", resmode.getIdentifier());
@ -818,15 +832,15 @@ public class LaunchBarManagerTest2 {
@Test @Test
public void testGetActiveLaunchTarget() throws CoreException { public void testGetActiveLaunchTarget() throws CoreException {
manager.setActiveLaunchTarget(localtarget); manager.setActiveLaunchTarget(localTarget);
assertEquals(localtarget, manager.getActiveLaunchTarget()); assertEquals(localTarget, manager.getActiveLaunchTarget());
} }
@Test @Test
public void testGetLaunchTarget() throws CoreException { public void testGetLaunchTarget() throws CoreException {
final List<IRemoteConnection> list = manager.getLaunchTargets(Collections.singletonList(targetTypeId)); final List<IRemoteConnection> list = manager.getLaunchTargets(Collections.singletonList(localTargetTypeId));
assertEquals(1, list.size()); assertEquals(1, list.size());
assertEquals(localtarget, list.get(0)); assertEquals(localTarget, list.get(0));
} }
@Test @Test
@ -837,12 +851,12 @@ public class LaunchBarManagerTest2 {
@Test @Test
public void testGetLaunchConfigurationType() throws CoreException { public void testGetLaunchConfigurationType() throws CoreException {
assertNotNull(manager.getLaunchConfigurationType(descriptor, localtarget)); assertNotNull(manager.getLaunchConfigurationType(descriptor, otherTarget));
} }
@Test @Test
public void testGetLaunchConfigurationNull() throws CoreException { public void testGetLaunchConfigurationNull() throws CoreException {
assertNull(manager.getLaunchConfiguration(null, localtarget)); assertNull(manager.getLaunchConfiguration(null, otherTarget));
} }
@Test @Test
@ -853,8 +867,8 @@ public class LaunchBarManagerTest2 {
@Test @Test
public void testGetLaunchConfiguration() throws CoreException { public void testGetLaunchConfiguration() throws CoreException {
basicSetup(); basicSetup();
assertTrue(manager.supportsTargetType(descriptor, localtarget)); assertTrue(manager.supportsTargetType(descriptor, otherTarget));
assertNotNull(manager.getLaunchConfiguration(descriptor, localtarget)); assertNotNull(manager.getLaunchConfiguration(descriptor, otherTarget));
} }
@Test @Test
@ -899,7 +913,7 @@ public class LaunchBarManagerTest2 {
assertNotNull(launchDescriptors[0]); assertNotNull(launchDescriptors[0]);
assertEquals(launchConfig.getName(), launchDescriptors[0].getName()); assertEquals(launchConfig.getName(), launchDescriptors[0].getName());
manager.setActiveLaunchDescriptor(launchDescriptors[0]); manager.setActiveLaunchDescriptor(launchDescriptors[0]);
assertEquals(localtarget, manager.getActiveLaunchTarget()); assertEquals(otherTarget, manager.getActiveLaunchTarget());
assertEquals(mode, manager.getActiveLaunchMode()); assertEquals(mode, manager.getActiveLaunchMode());
} }
@ -916,7 +930,7 @@ public class LaunchBarManagerTest2 {
assertNotNull(launchDescriptors[0]); assertNotNull(launchDescriptors[0]);
assertEquals(lc2.getName(), launchDescriptors[0].getName()); assertEquals(lc2.getName(), launchDescriptors[0].getName());
manager.setActiveLaunchDescriptor(launchDescriptors[0]); manager.setActiveLaunchDescriptor(launchDescriptors[0]);
assertEquals(localtarget, manager.getActiveLaunchTarget()); assertEquals(localTarget, manager.getActiveLaunchTarget());
} }
@Test @Test
@ -955,9 +969,9 @@ public class LaunchBarManagerTest2 {
elements.clear(); elements.clear();
IConfigurationElement element = mockElementAndAdd("defaultConfigTarget"); IConfigurationElement element = mockElementAndAdd("defaultConfigTarget");
doReturn(launchConfigType.getIdentifier()).when(element).getAttribute("launchConfigurationType"); doReturn(launchConfigType.getIdentifier()).when(element).getAttribute("launchConfigurationType");
targetTypeId = "x2"; localTargetTypeId = "x2";
mockTargetElement(targetTypeId); mockTargetElement(localTargetTypeId);
doReturn(targetTypeId).when(element).getAttribute("targetType"); doReturn(localTargetTypeId).when(element).getAttribute("targetType");
init(); init();
manager.launchConfigurationAdded(launchConfig); manager.launchConfigurationAdded(launchConfig);
ILaunchDescriptor[] launchDescriptors = manager.getLaunchDescriptors(); ILaunchDescriptor[] launchDescriptors = manager.getLaunchDescriptors();
@ -974,7 +988,7 @@ public class LaunchBarManagerTest2 {
IConfigurationElement element = mockDescriptorTypeElement("d1", descriptorType = mock(ILaunchDescriptorType.class)); IConfigurationElement element = mockDescriptorTypeElement("d1", descriptorType = mock(ILaunchDescriptorType.class));
doThrow(new CoreException(new Status(1, "a", "n"))).when(element).createExecutableExtension("class"); doThrow(new CoreException(new Status(1, "a", "n"))).when(element).createExecutableExtension("class");
doReturn(new ILaunchConfiguration[] { launchConfig }).when(lman).getLaunchConfigurations(); doReturn(new ILaunchConfiguration[] { launchConfig }).when(lman).getLaunchConfigurations();
mockConfigTypeElement(targetTypeId, "d1", launchConfigType.getIdentifier()); mockConfigTypeElement(localTargetTypeId, "d1", launchConfigType.getIdentifier());
init(); init();
ILaunchDescriptor[] launchDescriptors = manager.getLaunchDescriptors(); ILaunchDescriptor[] launchDescriptors = manager.getLaunchDescriptors();
assertEquals(1, launchDescriptors.length); // XXX should be 0 assertEquals(1, launchDescriptors.length); // XXX should be 0