Search in sources :

Example 1 with RunManagerSettings

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;
        }
    };
}
Also used : ConversionProcessor(com.intellij.conversion.ConversionProcessor) RunManagerSettings(com.intellij.conversion.RunManagerSettings) Element(org.jdom.Element) HashSet(java.util.HashSet) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with RunManagerSettings

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));
}
Also used : AndroidJUnitConfigurationConverter(com.android.tools.idea.testartifacts.junit.AndroidJUnitConfigurationConverter) IdeInfo(com.android.tools.idea.IdeInfo) RunManagerSettings(com.intellij.conversion.RunManagerSettings)

Example 3 with 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));
}
Also used : AndroidJUnitConfigurationConverter(com.android.tools.idea.testartifacts.junit.AndroidJUnitConfigurationConverter) IdeInfo(com.android.tools.idea.IdeInfo) RunManagerSettings(com.intellij.conversion.RunManagerSettings)

Example 4 with RunManagerSettings

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;
        }
    };
}
Also used : RunManagerSettings(com.intellij.conversion.RunManagerSettings) Element(org.jdom.Element) Collection(java.util.Collection) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

RunManagerSettings (com.intellij.conversion.RunManagerSettings)4 IdeInfo (com.android.tools.idea.IdeInfo)2 AndroidJUnitConfigurationConverter (com.android.tools.idea.testartifacts.junit.AndroidJUnitConfigurationConverter)2 Element (org.jdom.Element)2 NotNull (org.jetbrains.annotations.NotNull)2 ConversionProcessor (com.intellij.conversion.ConversionProcessor)1 Collection (java.util.Collection)1 HashSet (java.util.HashSet)1