Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change the default URI scheme to android.resource and support for loa… #34

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.os.Bundle;
import androidx.test.runner.AndroidJUnitRunner;
import cucumber.runtime.android.CucumberJUnitRunnerBuilder;
import java.net.URI;

/**
* {@link AndroidJUnitRunner} for cucumber tests. It supports running tests from Android Tests Orchestrator
Expand All @@ -12,6 +13,8 @@ public class CucumberAndroidJUnitRunner extends AndroidJUnitRunner {
public static final String CUCUMBER_ANDROID_TEST_CLASS = "cucumberAndroidTestClass";
private static final String ARGUMENT_ORCHESTRATOR_RUNNER_BUILDER = "runnerBuilder";
private static final String ARGUMENT_ORCHESTRATOR_CLASS = "class";
private static final String ARGUMENT_FEATURES = "features";
private static final String ANDROID_RESOURCE_SCHEMA = "android.resource:";
private Bundle arguments;

@Override
Expand All @@ -28,6 +31,19 @@ public void onCreate(final Bundle bundle) {
//because we delegate test execution to CucumberJUnitRunner
bundle.putString(ARGUMENT_ORCHESTRATOR_CLASS, CucumberJUnitRunnerBuilder.class.getName());

String features = bundle.getString(ARGUMENT_FEATURES, "");
if (features.isEmpty())
bundle.putString(ARGUMENT_FEATURES, ANDROID_RESOURCE_SCHEMA + "features");
else {
try {
URI uri = URI.create(features);
if (uri.getScheme() == null || uri.getScheme().isEmpty())
bundle.putString(ARGUMENT_FEATURES, ANDROID_RESOURCE_SCHEMA + uri.getSchemeSpecificPart());
} catch (IllegalArgumentException e) {
//do nothing
}
}

arguments = bundle;

super.onCreate(bundle);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.content.Context;
import android.content.res.AssetManager;
import cucumber.runtime.CucumberException;
import cucumber.runtime.io.MultiLoader;
import cucumber.runtime.io.Resource;
import cucumber.runtime.io.ResourceLoader;

Expand Down Expand Up @@ -37,6 +38,13 @@ final class AndroidResourceLoader implements ResourceLoader {

@Override
public Iterable<Resource> resources(final URI path, final String suffix) {
if (!path.getScheme().equals("android.resource")) {
MultiLoader multiLoader;
multiLoader = new MultiLoader(Thread.currentThread().getContextClassLoader());

return multiLoader.resources(path, suffix);
}

try {
final List<Resource> resources = new ArrayList<>();
final AssetManager assetManager = context.getAssets();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void beforeEachTest() {
public void retrieves_resource_by_given_path_and_suffix() {

// given
final URI path = URI.create("file:some/path/some.feature");
final URI path = URI.create("android.resource:some/path/some.feature");
final String suffix = "feature";

// when
Expand All @@ -56,7 +56,7 @@ public void retrieves_resource_by_given_path_and_suffix() {
public void retrieves_resources_recursively_from_given_path() throws IOException {

// given
final String path = "file:dir";
final String path = "android.resource:dir";
final String dir = "dir";
final String dirFile = "dir.feature";
final String subDir = "subdir";
Expand All @@ -80,7 +80,7 @@ public void only_retrieves_those_resources_which_end_the_specified_suffix() thro

// given
final String dir = "dir";
String path = "file:" + dir;
String path = "android.resource:" + dir;
final String expected = "expected.feature";
final String unexpected = "unexpected.thingy";
final String suffix = "feature";
Expand Down