use of com.intellij.conversion.RunManagerSettings in project android by JetBrains.
the class AndroidJUnitConfigurationConverter method createRunConfigurationsConverter.
@NotNull
@Override
public ConversionProcessor<RunManagerSettings> createRunConfigurationsConverter() {
return new ConversionProcessor<RunManagerSettings>() {
@Override
public boolean isConversionNeeded(RunManagerSettings settings) {
return IdeInfo.getInstance().isAndroidStudio() && !getConfigurationsToConvert(settings).isEmpty();
}
@Override
public void process(RunManagerSettings settings) throws CannotConvertException {
// Converts the factory identifications from JUnitConfigurationType to AndroidJUnitConfigurationType
for (Element element : getConfigurationsToConvert(settings)) {
element.setAttribute(CONFIGURATION_TYPE_ATTRIBUTE, ANDROID_JUNIT_CONFIGURATION_TYPE);
element.setAttribute(FACTORY_NAME_ATTRIBUTE, ANDROID_JUNIT_CONFIGURATION_FACTORY_NAME);
}
}
@NotNull
private Collection<Element> getConfigurationsToConvert(RunManagerSettings settings) {
Collection<? extends Element> configurationElements = settings.getRunConfigurations();
Collection<Element> toConvert = new HashSet<>();
// Searches for RunConfiguration persistent elements of type JUnit and adds them to the ones to be converted
for (Element element : configurationElements) {
String typeName = element.getAttributeValue(CONFIGURATION_TYPE_ATTRIBUTE);
String factoryName = element.getAttributeValue(FACTORY_NAME_ATTRIBUTE);
Boolean isTemplate = Boolean.valueOf(element.getAttributeValue(TEMPLATE_FLAG_ATTRIBUTE)).booleanValue();
if (!isTemplate && typeName.equals(JUNIT_CONFIGURATION_TYPE) && factoryName.equals(JUNIT_CONFIGURATION_FACTORY_NAME)) {
toConvert.add(element);
}
}
return toConvert;
}
};
}
use of com.intellij.conversion.RunManagerSettings in project android by JetBrains.
the class AndroidJUnitConfigurationConverterTest method testConfigurationsAreNotConvertedInIdea.
public void testConfigurationsAreNotConvertedInIdea() {
mockIdeInfo = IdeComponents.replaceServiceWithMock(IdeInfo.class);
when(mockIdeInfo.isAndroidStudio()).thenReturn(false);
ConversionProcessor<RunManagerSettings> converter = new AndroidJUnitConfigurationConverter().createRunConfigurationsConverter();
RunManagerSettings runManagerSettings = getStubRunManagerSettings();
assertFalse(converter.isConversionNeeded(runManagerSettings));
}
use of com.intellij.conversion.RunManagerSettings in project android by JetBrains.
the class AndroidJUnitConfigurationConverterTest method testConfigurationsAreConvertedInStudio.
public void testConfigurationsAreConvertedInStudio() throws Exception {
mockIdeInfo = IdeComponents.replaceServiceWithMock(IdeInfo.class);
when(mockIdeInfo.isAndroidStudio()).thenReturn(true);
ConversionProcessor<RunManagerSettings> converter = new AndroidJUnitConfigurationConverter().createRunConfigurationsConverter();
RunManagerSettings runManagerSettings = getStubRunManagerSettings();
Collection<? extends Element> runConfigurations = runManagerSettings.getRunConfigurations();
assertTrue(converter.isConversionNeeded(runManagerSettings));
assertSize(2, getJUnitConfigurations(runConfigurations));
assertEmpty(getAndroidJUnitConfigurations(runConfigurations));
converter.process(runManagerSettings);
assertEmpty(getJUnitConfigurations(runConfigurations));
assertSize(2, getAndroidJUnitConfigurations(runConfigurations));
}
use of com.intellij.conversion.RunManagerSettings in project android by JetBrains.
the class AndroidJUnitConfigurationConverterTest method getStubRunManagerSettings.
@NotNull
private static RunManagerSettings getStubRunManagerSettings() {
return new RunManagerSettings() {
Collection<Element> myElements = null;
@NotNull
@Override
public Collection<? extends Element> getRunConfigurations() {
if (myElements == null) {
Element root = null;
try {
root = readElement(getTestDataPath() + "/" + TEST_ARTIFACTS_OLD_TESTS + "/.idea/workspace.xml");
} catch (Exception e) {
e.printStackTrace();
}
myElements = root != null ? root.getChild("component").getChildren("configuration") : Collections.emptySet();
}
return myElements;
}
};
}
Aggregations