Search in sources :

Example 1 with FlexUnitRuntimeConfigurationProducer

use of com.intellij.lang.javascript.flex.flexunit.FlexUnitRuntimeConfigurationProducer in project intellij-plugins by JetBrains.

the class FlexUnitConfigurationTest method doTest.

private void doTest(String filename) throws Exception {
    configureByFile(BASE_PATH + filename);
    final Map<Integer, String> markers = JSTestUtils.extractPositionMarkers(getProject(), getEditor().getDocument());
    assertFalse("No caret markers found", markers.isEmpty());
    assertFalse("No 'expected' value", markers.containsValue(null));
    final DataContext dataContext = DataManager.getInstance().getDataContext(getEditor().getComponent());
    int i = 1;
    for (Map.Entry<Integer, String> marker : markers.entrySet()) {
        String place = filename + ": marker " + i++ + ": ";
        getEditor().getCaretModel().moveToOffset(marker.getKey());
        final ConfigurationFromContext configurationFromContext = new FlexUnitRuntimeConfigurationProducer().createConfigurationFromContext(ConfigurationContext.getFromContext(dataContext));
        final RunConfiguration configuration = configurationFromContext == null ? null : configurationFromContext.getConfiguration();
        if ("null".equals(marker.getValue())) {
            assertNull(place + "Null configuration expected", configuration);
        } else {
            assertNotNull(place + "Not null configuration expected", configuration);
            assertTrue(place + "Invalid configuration", configuration instanceof FlexUnitRunConfiguration);
            final String[] expected;
            if ("null".equals(marker.getValue())) {
                expected = null;
            } else {
                expected = marker.getValue().split(" ");
                assertEquals(place + "Expected should be in the form: \"Class com.test.Foo\" or \"Method com.test.Foo.testBar()\" or \"Package com.test\"", 2, expected.length);
            }
            final FlexUnitRunnerParameters params = ((FlexUnitRunConfiguration) configuration).getRunnerParameters();
            assertEquals(place + "Invalid scope", expected[0], params.getScope().name());
            final String definition;
            switch(params.getScope()) {
                case Class:
                    definition = params.getClassName();
                    break;
                case Method:
                    definition = params.getClassName() + "." + params.getMethodName() + "()";
                    break;
                case Package:
                    definition = params.getPackageName();
                    break;
                default:
                    fail(place + "Unknown scope: " + params.getScope());
                    definition = null;
            }
            assertEquals(place + "Invalid definition", expected[1], definition);
        }
    }
}
Also used : FlexUnitRunConfiguration(com.intellij.lang.javascript.flex.flexunit.FlexUnitRunConfiguration) FlexUnitRuntimeConfigurationProducer(com.intellij.lang.javascript.flex.flexunit.FlexUnitRuntimeConfigurationProducer) DataContext(com.intellij.openapi.actionSystem.DataContext) RunConfiguration(com.intellij.execution.configurations.RunConfiguration) FlexUnitRunConfiguration(com.intellij.lang.javascript.flex.flexunit.FlexUnitRunConfiguration) FlexUnitRunnerParameters(com.intellij.lang.javascript.flex.flexunit.FlexUnitRunnerParameters) ConfigurationFromContext(com.intellij.execution.actions.ConfigurationFromContext) Map(java.util.Map)

Aggregations

ConfigurationFromContext (com.intellij.execution.actions.ConfigurationFromContext)1 RunConfiguration (com.intellij.execution.configurations.RunConfiguration)1 FlexUnitRunConfiguration (com.intellij.lang.javascript.flex.flexunit.FlexUnitRunConfiguration)1 FlexUnitRunnerParameters (com.intellij.lang.javascript.flex.flexunit.FlexUnitRunnerParameters)1 FlexUnitRuntimeConfigurationProducer (com.intellij.lang.javascript.flex.flexunit.FlexUnitRuntimeConfigurationProducer)1 DataContext (com.intellij.openapi.actionSystem.DataContext)1 Map (java.util.Map)1