Skip to content

Commit 442c4ed

Browse files
committed
Add RuntimeOptions.isMonochrome(), rm Runtime factory methods
Add RuntimeOptions.isMonochorme(), since commit 65f3bd6 on the master branch change RuntimeOptions to have private fields and getters. Basically revert commit c8feb10. Since the new android support on the master banch sends backends to the Runtime constructor, which previously only was done in tests, the change to use factory methods in Runtime no longer make sence.
1 parent 3a77cff commit 442c4ed

File tree

11 files changed

+27
-47
lines changed

11 files changed

+27
-47
lines changed

core/src/main/java/cucumber/api/cli/Main.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public static void main(String[] argv) throws Throwable {
1515
public static void run(String[] argv, ClassLoader classLoader) throws IOException {
1616
RuntimeOptions runtimeOptions = new RuntimeOptions(System.getProperties(), argv);
1717

18-
Runtime runtime = Runtime.createRuntime(new MultiLoader(classLoader), classLoader, runtimeOptions);
18+
Runtime runtime = new Runtime(new MultiLoader(classLoader), classLoader, runtimeOptions);
1919
runtime.writeStepdefsJson();
2020
runtime.run();
2121
System.exit(runtime.exitStatus());

core/src/main/java/cucumber/runtime/Runtime.java

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,11 @@
1010
import gherkin.formatter.Argument;
1111
import gherkin.formatter.Formatter;
1212
import gherkin.formatter.Reporter;
13-
import gherkin.formatter.model.Comment;
14-
import gherkin.formatter.model.DataTableRow;
15-
import gherkin.formatter.model.DocString;
16-
import gherkin.formatter.model.Match;
17-
import gherkin.formatter.model.Result;
18-
import gherkin.formatter.model.Step;
19-
import gherkin.formatter.model.Tag;
13+
import gherkin.formatter.model.*;
2014

2115
import java.io.IOException;
2216
import java.io.PrintStream;
23-
import java.util.ArrayList;
24-
import java.util.Arrays;
25-
import java.util.Collection;
26-
import java.util.Collections;
27-
import java.util.List;
28-
import java.util.Set;
17+
import java.util.*;
2918

3019
/**
3120
* This is the main entry point for running Cucumber features.
@@ -59,8 +48,12 @@ public class Runtime implements UnreportedStepExecutor {
5948
private boolean skipNextStep = false;
6049
private ScenarioImpl scenarioResult = null;
6150

62-
public static Runtime createRuntime(ResourceLoader resourceLoader, ClassLoader classLoader, RuntimeOptions runtimeOptions) {
63-
return new Runtime(resourceLoader, classLoader, loadBackends(resourceLoader, classLoader), runtimeOptions, null);
51+
public Runtime(ResourceLoader resourceLoader, ClassLoader classLoader, RuntimeOptions runtimeOptions) {
52+
this(resourceLoader, classLoader, loadBackends(resourceLoader, classLoader), runtimeOptions);
53+
}
54+
55+
public Runtime(ResourceLoader resourceLoader, ClassLoader classLoader, Collection<? extends Backend> backends, RuntimeOptions runtimeOptions) {
56+
this(resourceLoader, classLoader, backends, runtimeOptions, null);
6457
}
6558

6659
public Runtime(ResourceLoader resourceLoader, ClassLoader classLoader, Collection<? extends Backend> backends,
@@ -73,7 +66,7 @@ public Runtime(ResourceLoader resourceLoader, ClassLoader classLoader, Collectio
7366
this.backends = backends;
7467
this.runtimeOptions = runtimeOptions;
7568
this.glue = optionalGlue != null ? optionalGlue : new RuntimeGlue(undefinedStepsTracker, new LocalizedXStreams(classLoader));
76-
this.summaryCounter = new SummaryCounter(runtimeOptions.monochrome);
69+
this.summaryCounter = new SummaryCounter(runtimeOptions.isMonochrome());
7770

7871
for (Backend backend : backends) {
7972
backend.loadGlue(glue, runtimeOptions.glue);

core/src/main/java/cucumber/runtime/RuntimeOptions.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,4 +149,8 @@ public Object invoke(Object target, Method method, Object[] args) throws Throwab
149149
}
150150
});
151151
}
152+
153+
public boolean isMonochrome() {
154+
return monochrome;
155+
}
152156
}

core/src/test/java/cucumber/runtime/BackgroundTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class BackgroundTest {
1818
public void should_run_background() throws IOException {
1919
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
2020
RuntimeOptions runtimeOptions = new RuntimeOptions(new Properties());
21-
Runtime runtime = RuntimeTest.createRuntime(new ClasspathResourceLoader(classLoader), classLoader, asList(mock(Backend.class)), runtimeOptions);
21+
Runtime runtime = new Runtime(new ClasspathResourceLoader(classLoader), classLoader, asList(mock(Backend.class)), runtimeOptions);
2222
CucumberFeature feature = feature("test.feature", "" +
2323
"Feature:\n" +
2424
" Background:\n" +

core/src/test/java/cucumber/runtime/HookOrderTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public class HookOrderTest {
3131
public void buildMockWorld() {
3232
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
3333
RuntimeOptions runtimeOptions = new RuntimeOptions(new Properties());
34-
runtime = RuntimeTest.createRuntime(mock(ResourceLoader.class), classLoader, asList(mock(Backend.class)), runtimeOptions);
34+
runtime = new Runtime(mock(ResourceLoader.class), classLoader, asList(mock(Backend.class)), runtimeOptions);
3535
runtime.buildBackendWorlds(null, Collections.<Tag>emptySet());
3636
glue = runtime.getGlue();
3737
}

core/src/test/java/cucumber/runtime/HookTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public void after_hooks_execute_before_objects_are_disposed() throws Throwable {
4545

4646
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
4747
RuntimeOptions runtimeOptions = new RuntimeOptions(new Properties());
48-
Runtime runtime = RuntimeTest.createRuntime(new ClasspathResourceLoader(classLoader), classLoader, asList(backend), runtimeOptions);
48+
Runtime runtime = new Runtime(new ClasspathResourceLoader(classLoader), classLoader, asList(backend), runtimeOptions);
4949
runtime.getGlue().addAfterHook(hook);
5050

5151
scenario.run(mock(Formatter.class), mock(Reporter.class), runtime);

core/src/test/java/cucumber/runtime/RuntimeTest.java

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public void runs_feature_with_json_formatter() throws Exception {
5454
List<Backend> backends = asList(mock(Backend.class));
5555
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
5656
RuntimeOptions runtimeOptions = new RuntimeOptions(new Properties());
57-
Runtime runtime = createRuntime(new ClasspathResourceLoader(classLoader), classLoader, backends, runtimeOptions);
57+
Runtime runtime = new Runtime(new ClasspathResourceLoader(classLoader), classLoader, backends, runtimeOptions);
5858
feature.run(jsonFormatter, jsonFormatter, runtime);
5959
jsonFormatter.done();
6060
String expected = "" +
@@ -182,7 +182,7 @@ public void strict_with_errors() {
182182
public void should_throw_cucumer_exception_if_no_backends_are_found() throws Exception {
183183
try {
184184
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
185-
createRuntime(new ClasspathResourceLoader(classLoader), classLoader, Collections.<Backend>emptyList(),
185+
new Runtime(new ClasspathResourceLoader(classLoader), classLoader, Collections.<Backend>emptyList(),
186186
new RuntimeOptions(new Properties()));
187187
fail("A CucumberException should have been thrown");
188188
} catch (CucumberException e) {
@@ -363,17 +363,7 @@ private Runtime createRuntime(String... runtimeArgs) {
363363
Backend backend = mock(Backend.class);
364364
Collection<Backend> backends = Arrays.asList(backend);
365365

366-
return createRuntime(resourceLoader, classLoader, backends, runtimeOptions);
367-
}
368-
369-
public static Runtime createRuntime(ResourceLoader resourceLoader, ClassLoader classLoader,
370-
Collection<? extends Backend> backends, RuntimeOptions runtimeOptions) {
371-
return new Runtime(resourceLoader, classLoader, backends, runtimeOptions, null);
372-
}
373-
374-
public static Runtime createRuntime(ResourceLoader resourceLoader, ClassLoader classLoader,
375-
Collection<Backend> backends, RuntimeOptions runtimeOptions, RuntimeGlue glue) {
376-
return new Runtime(resourceLoader, classLoader, backends, runtimeOptions, glue);
366+
return new Runtime(resourceLoader, classLoader, backends, runtimeOptions);
377367
}
378368

379369
private Runtime createRuntimeWithMockedGlue(StepDefinitionMatch match, String... runtimeArgs) {
@@ -400,7 +390,7 @@ private Runtime createRuntimeWithMockedGlue(StepDefinitionMatch match, boolean i
400390
mockHook(glue, hook, isBefore);
401391
Collection<Backend> backends = Arrays.asList(backend);
402392

403-
return createRuntime(resourceLoader, classLoader, backends, runtimeOptions, glue);
393+
return new Runtime(resourceLoader, classLoader, backends, runtimeOptions, glue);
404394
}
405395

406396
private void mockMatch(RuntimeGlue glue, StepDefinitionMatch match, boolean isAmbiguous) {

core/src/test/java/cucumber/runtime/formatter/JSONPrettyFormatterTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package cucumber.runtime.formatter;
22

33
import cucumber.runtime.Backend;
4+
import cucumber.runtime.Runtime;
45
import cucumber.runtime.RuntimeOptions;
5-
import cucumber.runtime.RuntimeTest;
66
import cucumber.runtime.io.ClasspathResourceLoader;
77
import gherkin.formatter.model.Step;
88
import org.junit.Test;
@@ -45,7 +45,7 @@ private File runFeaturesWithJSONPrettyFormatter(final List<String> featurePaths)
4545
RuntimeOptions runtimeOptions = new RuntimeOptions(new Properties(), args.toArray(new String[args.size()]));
4646
Backend backend = mock(Backend.class);
4747
when(backend.getSnippet(any(Step.class))).thenReturn("TEST SNIPPET");
48-
final cucumber.runtime.Runtime runtime = RuntimeTest.createRuntime(resourceLoader, classLoader, asList(backend), runtimeOptions);
48+
final cucumber.runtime.Runtime runtime = new Runtime(resourceLoader, classLoader, asList(backend), runtimeOptions);
4949
runtime.run();
5050
return report;
5151
}

core/src/test/java/cucumber/runtime/formatter/JUnitFormatterTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package cucumber.runtime.formatter;
22

33
import cucumber.runtime.Backend;
4+
import cucumber.runtime.Runtime;
45
import cucumber.runtime.RuntimeOptions;
5-
import cucumber.runtime.RuntimeTest;
66
import cucumber.runtime.io.ClasspathResourceLoader;
77
import gherkin.formatter.model.Step;
88
import org.custommonkey.xmlunit.Diff;
@@ -58,7 +58,7 @@ private File runFeaturesWithJunitFormatter(final List<String> featurePaths) thro
5858
RuntimeOptions runtimeOptions = new RuntimeOptions(new Properties(), args.toArray(new String[args.size()]));
5959
Backend backend = mock(Backend.class);
6060
when(backend.getSnippet(any(Step.class))).thenReturn("TEST SNIPPET");
61-
final cucumber.runtime.Runtime runtime = RuntimeTest.createRuntime(resourceLoader, classLoader, asList(backend), runtimeOptions);
61+
final cucumber.runtime.Runtime runtime = new Runtime(resourceLoader, classLoader, asList(backend), runtimeOptions);
6262
runtime.run();
6363
return report;
6464
}

java/src/test/java/cucumber/runtime/java/JavaStepDefinitionTest.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import cucumber.api.java.en.Given;
44
import cucumber.runtime.AmbiguousStepDefinitionsException;
5-
import cucumber.runtime.Backend;
65
import cucumber.runtime.DuplicateStepDefinitionException;
76
import cucumber.runtime.Glue;
87
import cucumber.runtime.Runtime;
@@ -20,7 +19,6 @@
2019
import org.mockito.ArgumentCaptor;
2120

2221
import java.lang.reflect.Method;
23-
import java.util.Collection;
2422
import java.util.Collections;
2523
import java.util.HashSet;
2624
import java.util.List;
@@ -53,7 +51,7 @@ public class JavaStepDefinitionTest {
5351
private final JavaBackend backend = new JavaBackend(new SingletonFactory(defs));
5452
private final ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
5553
private final RuntimeOptions runtimeOptions = new RuntimeOptions(new Properties());
56-
private final Runtime runtime = createRuntime(new ClasspathResourceLoader(classLoader), classLoader, asList(backend), runtimeOptions);
54+
private final Runtime runtime = new Runtime(new ClasspathResourceLoader(classLoader), classLoader, asList(backend), runtimeOptions);
5755
private final Glue glue = runtime.getGlue();
5856

5957
@org.junit.Before
@@ -147,9 +145,4 @@ private <T> Set<T> asSet(T... items) {
147145
set.addAll(asList(items));
148146
return set;
149147
}
150-
151-
private Runtime createRuntime(ResourceLoader resourceLoader, ClassLoader classLoader,
152-
Collection<? extends Backend> backends, RuntimeOptions runtimeOptions) {
153-
return new Runtime(resourceLoader, classLoader, backends, runtimeOptions, null);
154-
}
155148
}

junit/src/main/java/cucumber/api/junit/Cucumber.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public Cucumber(Class clazz) throws InitializationError, IOException {
5656
RuntimeOptions runtimeOptions = runtimeOptionsFactory.create();
5757

5858
ResourceLoader resourceLoader = new MultiLoader(classLoader);
59-
runtime = Runtime.createRuntime(resourceLoader, classLoader, runtimeOptions);
59+
runtime = new Runtime(resourceLoader, classLoader, runtimeOptions);
6060

6161
jUnitReporter = new JUnitReporter(runtimeOptions.reporter(classLoader), runtimeOptions.formatter(classLoader), runtimeOptions.strict);
6262
addChildren(runtimeOptions.cucumberFeatures(resourceLoader));

0 commit comments

Comments
 (0)