Search in sources :

Example 21 with CucumberException

use of cucumber.runtime.CucumberException in project cucumber-jvm by cucumber.

the class TestNGCucumberRunner method provideFeatures.

/**
     * @return returns the cucumber features as a two dimensional array of
     * {@link CucumberFeatureWrapper} objects.
     */
public Object[][] provideFeatures() {
    try {
        List<CucumberFeature> features = getFeatures();
        List<Object[]> featuresList = new ArrayList<Object[]>(features.size());
        for (CucumberFeature feature : features) {
            featuresList.add(new Object[] { new CucumberFeatureWrapperImpl(feature) });
        }
        return featuresList.toArray(new Object[][] {});
    } catch (CucumberException e) {
        return new Object[][] { new Object[] { new CucumberExceptionWrapper(e) } };
    }
}
Also used : CucumberFeature(cucumber.runtime.model.CucumberFeature) ArrayList(java.util.ArrayList) CucumberException(cucumber.runtime.CucumberException)

Example 22 with CucumberException

use of cucumber.runtime.CucumberException in project cucumber-jvm by cucumber.

the class JavaHookTest method fails_if_hook_argument_is_not_scenario_result.

@Test
public void fails_if_hook_argument_is_not_scenario_result() throws Throwable {
    objectFactory.setInstance(new BadHook());
    backend.buildWorld();
    backend.addHook(BAD_AFTER.getAnnotation(After.class), BAD_AFTER);
    HookDefinition bad = glue.getAfterHooks().get(0);
    try {
        bad.execute(mock(Scenario.class));
        fail();
    } catch (CucumberException expected) {
        assertEquals("When a hook declares an argument it must be of type cucumber.api.Scenario. public void cucumber.runtime.java.JavaHookTest$BadHook.after(java.lang.String)", expected.getMessage());
    }
}
Also used : After(cucumber.api.java.After) CucumberException(cucumber.runtime.CucumberException) HookDefinition(cucumber.runtime.HookDefinition) Scenario(cucumber.api.Scenario) Test(org.junit.Test)

Example 23 with CucumberException

use of cucumber.runtime.CucumberException in project cucumber-jvm by cucumber.

the class DexClassFinder method getDescendants.

@Override
public <T> Collection<Class<? extends T>> getDescendants(final Class<T> parentType, final String packageName) {
    final List<Class<? extends T>> result = new ArrayList<Class<? extends T>>();
    final Enumeration<String> entries = dexFile.entries();
    while (entries.hasMoreElements()) {
        final String className = entries.nextElement();
        if (isInPackage(className, packageName) && !isGenerated(className)) {
            try {
                final Class<? extends T> clazz = loadClass(className);
                if (clazz != null && !parentType.equals(clazz) && parentType.isAssignableFrom(clazz)) {
                    result.add(clazz.asSubclass(parentType));
                }
            } catch (ClassNotFoundException e) {
                throw new CucumberException(e);
            }
        }
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) CucumberException(cucumber.runtime.CucumberException)

Example 24 with CucumberException

use of cucumber.runtime.CucumberException in project cucumber-jvm by cucumber.

the class ConverterWithFormat method transform.

/**
     * Parses a value using one of the java.util.text format classes.
     *
     * @param format   The format to use
     * @param argument The object to parse
     * @return The object
     */
@SuppressWarnings("unchecked")
Object transform(final Format format, final String argument) {
    ParsePosition position = new ParsePosition(0);
    Object result = format.parseObject(argument, position);
    if (position.getErrorIndex() != -1) {
        throw new CucumberException("Can't parse '" + argument + "' using format " + format);
    }
    return result;
}
Also used : CucumberException(cucumber.runtime.CucumberException) ParsePosition(java.text.ParsePosition)

Example 25 with CucumberException

use of cucumber.runtime.CucumberException in project cucumber-jvm by cucumber.

the class CucumberScenarioOutline method createExampleStep.

static ExampleStep createExampleStep(Step step, ExamplesTableRow header, ExamplesTableRow example) {
    Set<Integer> matchedColumns = new HashSet<Integer>();
    List<String> headerCells = header.getCells();
    List<String> exampleCells = example.getCells();
    // Create a step with replaced tokens
    String name = replaceTokens(matchedColumns, headerCells, exampleCells, step.getName());
    if (name.isEmpty()) {
        throw new CucumberException("Step generated from scenario outline '" + step.getName() + "' is empty");
    }
    return new ExampleStep(step.getComments(), step.getKeyword(), name, step.getLine(), rowsWithTokensReplaced(step.getRows(), headerCells, exampleCells, matchedColumns), docStringWithTokensReplaced(step.getDocString(), headerCells, exampleCells, matchedColumns), matchedColumns);
}
Also used : DocString(gherkin.formatter.model.DocString) CucumberException(cucumber.runtime.CucumberException) HashSet(java.util.HashSet)

Aggregations

CucumberException (cucumber.runtime.CucumberException)37 Test (org.junit.Test)7 ArrayList (java.util.ArrayList)6 SingleValueConverter (cucumber.deps.com.thoughtworks.xstream.converters.SingleValueConverter)4 IOException (java.io.IOException)4 Step (gherkin.formatter.model.Step)3 ObjectFactory (cucumber.api.java.ObjectFactory)2 StepdefBody (cucumber.api.java8.StepdefBody)2 RuntimeOptionsFactory (cucumber.runtime.RuntimeOptionsFactory)2 Resource (cucumber.runtime.io.Resource)2 Java8StepDefinition (cucumber.runtime.java.Java8StepDefinition)2 AssetManager (android.content.res.AssetManager)1 DataTable (cucumber.api.DataTable)1 PendingException (cucumber.api.PendingException)1 Scenario (cucumber.api.Scenario)1 After (cucumber.api.java.After)1 Cucumber (cucumber.api.junit.Cucumber)1 OsgiClassFinder (cucumber.java.runtime.osgi.OsgiClassFinder)1 PaxExamObjectFactory (cucumber.java.runtime.osgi.PaxExamObjectFactory)1 Backend (cucumber.runtime.Backend)1