Search in sources :

Example 6 with CucumberException

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

the class TableConverter method toLists.

public <T> List<List<T>> toLists(DataTable dataTable, Type itemType) {
    try {
        xStream.setParameterInfo(parameterInfo);
        SingleValueConverter itemConverter = xStream.getSingleValueConverter(itemType);
        if (itemConverter == null) {
            throw new CucumberException(String.format("Can't convert DataTable to List<List<%s>>", itemType));
        }
        List<List<T>> result = new ArrayList<List<T>>();
        for (List<String> row : dataTable.raw()) {
            List<T> convertedRow = new ArrayList<T>();
            for (String cell : row) {
                convertedRow.add((T) itemConverter.fromString(cell));
            }
            result.add(Collections.unmodifiableList(convertedRow));
        }
        return Collections.unmodifiableList(result);
    } finally {
        xStream.unsetParameterInfo();
    }
}
Also used : ArrayList(java.util.ArrayList) SingleValueConverter(cucumber.deps.com.thoughtworks.xstream.converters.SingleValueConverter) ArrayList(java.util.ArrayList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) CucumberException(cucumber.runtime.CucumberException)

Example 7 with CucumberException

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

the class TableConverter method toMap.

public <K, V> Map<K, V> toMap(DataTable dataTable, Type keyType, Type valueType) {
    try {
        xStream.setParameterInfo(parameterInfo);
        SingleValueConverter keyConverter = xStream.getSingleValueConverter(keyType);
        SingleValueConverter valueConverter = xStream.getSingleValueConverter(valueType);
        if (keyConverter == null || valueConverter == null) {
            throw new CucumberException(String.format("Can't convert DataTable to Map<%s,%s>", keyType, valueType));
        }
        Map<K, V> result = new LinkedHashMap<K, V>();
        for (List<String> row : dataTable.raw()) {
            if (row.size() != 2) {
                throw new CucumberException("A DataTable can only be converted to a Map when there are 2 columns");
            }
            K key = (K) keyConverter.fromString(row.get(0));
            V value = (V) valueConverter.fromString(row.get(1));
            result.put(key, value);
        }
        return Collections.unmodifiableMap(result);
    } finally {
        xStream.unsetParameterInfo();
    }
}
Also used : SingleValueConverter(cucumber.deps.com.thoughtworks.xstream.converters.SingleValueConverter) CucumberException(cucumber.runtime.CucumberException) LinkedHashMap(java.util.LinkedHashMap)

Example 8 with CucumberException

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

the class CucumberExecutor method createRuntimeOptions.

private RuntimeOptions createRuntimeOptions(final Context context) {
    for (final Class<?> clazz : classFinder.getDescendants(Object.class, context.getPackageName())) {
        if (clazz.isAnnotationPresent(CucumberOptions.class)) {
            Log.d(TAG, "Found CucumberOptions in class " + clazz.getName());
            final RuntimeOptionsFactory factory = new RuntimeOptionsFactory(clazz);
            return factory.create();
        }
    }
    throw new CucumberException("No CucumberOptions annotation");
}
Also used : CucumberException(cucumber.runtime.CucumberException) RuntimeOptionsFactory(cucumber.runtime.RuntimeOptionsFactory)

Example 9 with CucumberException

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

the class AndroidResourceLoader method resources.

@Override
public Iterable<Resource> resources(final String path, final String suffix) {
    try {
        final List<Resource> resources = new ArrayList<Resource>();
        final AssetManager assetManager = context.getAssets();
        addResourceRecursive(resources, assetManager, path, suffix);
        return resources;
    } catch (final IOException e) {
        throw new CucumberException("Error loading resources from " + path + " with suffix " + suffix, e);
    }
}
Also used : AssetManager(android.content.res.AssetManager) ArrayList(java.util.ArrayList) Resource(cucumber.runtime.io.Resource) IOException(java.io.IOException) CucumberException(cucumber.runtime.CucumberException)

Example 10 with CucumberException

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

the class CalculatorTest method cucumber.

@Test
public void cucumber() throws Exception {
    assertNotNull(injector);
    assertNotNull(bundleContext);
    final ResourceLoader resourceLoader = new FileResourceLoader();
    final ClassLoader classLoader = Runtime.class.getClassLoader();
    final ObjectFactory objectFactory = new PaxExamObjectFactory(injector);
    final ClassFinder classFinder = new OsgiClassFinder(bundleContext);
    final Backend backend = new JavaBackend(objectFactory, classFinder);
    final RuntimeOptionsFactory runtimeOptionsFactory = new RuntimeOptionsFactory(getClass());
    final RuntimeOptions runtimeOptions = runtimeOptionsFactory.create();
    final Runtime runtime = new Runtime(resourceLoader, classLoader, Collections.singleton(backend), runtimeOptions);
    runtime.run();
    if (!runtime.getErrors().isEmpty()) {
        throw new CucumberException(runtime.getErrors().get(0));
    } else if (runtime.exitStatus() != 0x00) {
        throw new CucumberException("There are pending or undefined steps.");
    }
    assertEquals(runtime.getErrors().size(), 0);
}
Also used : ResourceLoader(cucumber.runtime.io.ResourceLoader) FileResourceLoader(cucumber.runtime.io.FileResourceLoader) JavaBackend(cucumber.runtime.java.JavaBackend) OsgiClassFinder(cucumber.java.runtime.osgi.OsgiClassFinder) Backend(cucumber.runtime.Backend) JavaBackend(cucumber.runtime.java.JavaBackend) Runtime(cucumber.runtime.Runtime) ObjectFactory(cucumber.api.java.ObjectFactory) PaxExamObjectFactory(cucumber.java.runtime.osgi.PaxExamObjectFactory) FileResourceLoader(cucumber.runtime.io.FileResourceLoader) PaxExamObjectFactory(cucumber.java.runtime.osgi.PaxExamObjectFactory) ClassFinder(cucumber.runtime.ClassFinder) OsgiClassFinder(cucumber.java.runtime.osgi.OsgiClassFinder) CucumberException(cucumber.runtime.CucumberException) RuntimeOptionsFactory(cucumber.runtime.RuntimeOptionsFactory) RuntimeOptions(cucumber.runtime.RuntimeOptions) Test(org.junit.Test)

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