Android Open Source - CucumberAndroidGradle Android Java Step Definition






From Project

Back to project page CucumberAndroidGradle.

License

The source code is released under:

Apache License

If you think the Android project CucumberAndroidGradle listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package cucumber.runtime.android;
/*  ww w .ja  v  a2s .c  om*/
import cucumber.runtime.JdkPatternArgumentMatcher;
import cucumber.runtime.ParameterInfo;
import cucumber.runtime.StepDefinition;
import cucumber.runtime.Utils;
import cucumber.runtime.java.ObjectFactory;
import gherkin.I18n;
import gherkin.formatter.Argument;
import gherkin.formatter.model.Step;

import java.lang.reflect.Method;
import java.lang.reflect.Type;
import java.util.List;
import java.util.regex.Pattern;

class AndroidJavaStepDefinition implements StepDefinition {
    private final Method mMethod;
    private final Pattern mPattern;
    private final int mTimeout;
    private final JdkPatternArgumentMatcher mArgumentMatcher;
    private final ObjectFactory mObjectFactory;
    private List<ParameterInfo> mParameterInfos;

    public AndroidJavaStepDefinition(Method method, Pattern pattern, int timeout, ObjectFactory objectFactory) {
        mMethod = method;
        mParameterInfos = ParameterInfo.fromMethod(method);
        mPattern = pattern;
        mArgumentMatcher = new JdkPatternArgumentMatcher(pattern);
        mTimeout = timeout;
        mObjectFactory = objectFactory;
    }

    public void execute(I18n i18n, Object[] args) throws Throwable {
        Utils.invoke(mObjectFactory.getInstance(mMethod.getDeclaringClass()), mMethod, mTimeout, args);
    }

    public List<Argument> matchedArguments(Step step) {
        return mArgumentMatcher.argumentsFrom(step.getName());
    }

    public String getLocation(boolean detail) {
        AndroidMethodFormat format = detail ? AndroidMethodFormat.FULL : AndroidMethodFormat.SHORT;
        return format.format(mMethod);
    }

    @Override
    public Integer getParameterCount() {
        return mParameterInfos.size();
    }

    @Override
    public ParameterInfo getParameterType(int n, Type argumentType) {
        return mParameterInfos.get(n);
    }

    public boolean isDefinedAt(StackTraceElement e) {
        return e.getClassName().equals(mMethod.getDeclaringClass().getName()) && e.getMethodName().equals(mMethod.getName());
    }

    @Override
    public String getPattern() {
        return mPattern.pattern();
    }
}




Java Source Code List

com.example.cucumberandroid.MainActivity.java
cucumber.api.android.CucumberInstrumentationTestRunner.java
cucumber.api.android.CucumberInstrumentation.java
cucumber.api.android.RunWithCucumber.java
cucumber.runtime.android.AndroidBackend.java
cucumber.runtime.android.AndroidClasspathMethodScanner.java
cucumber.runtime.android.AndroidFormatter.java
cucumber.runtime.android.AndroidJavaStepDefinition.java
cucumber.runtime.android.AndroidMethodFormat.java
cucumber.runtime.android.AndroidObjectFactory.java
cucumber.runtime.android.AndroidResourceLoader.java
cucumber.runtime.android.AndroidResource.java
cucumber.runtime.android.JavaHookDefinition.java
cucumber.runtime.android.JavaSnippet.java
ext.com.android.internal.os.LoggingPrintStream.java
ext.com.google.android.collect.Maps.java
ext.com.google.android.collect.Sets.java