From dfc8d8fdcffd144269dc93c848d5b79cdba9967b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aslak=20Helles=C3=B8y?= Date: Tue, 21 Feb 2012 21:11:30 +0000 Subject: [PATCH 01/10] Giving another stab at #160 --- .../scalacalculator/RunCukesTest.scala | 5 +- .../main/java/cucumber/junit/Cucumber.java | 60 ++++++++++++++----- .../src/main/java/cucumber/junit/Feature.java | 34 ----------- .../java/cucumber/junit/CucumberTest.java | 4 +- 4 files changed, 51 insertions(+), 52 deletions(-) delete mode 100644 junit/src/main/java/cucumber/junit/Feature.java diff --git a/examples/scala-calculator/src/test/scala/cucumber/examples/scalacalculator/RunCukesTest.scala b/examples/scala-calculator/src/test/scala/cucumber/examples/scalacalculator/RunCukesTest.scala index 47966f25d7..811005adbd 100644 --- a/examples/scala-calculator/src/test/scala/cucumber/examples/scalacalculator/RunCukesTest.scala +++ b/examples/scala-calculator/src/test/scala/cucumber/examples/scalacalculator/RunCukesTest.scala @@ -1,8 +1,9 @@ package cucumber.examples.scalacalculator import org.junit.runner.RunWith -import cucumber.junit.{Feature, Cucumber} +import cucumber.junit.Cucumber.Options +import cucumber.junit.{Options, Cucumber} @RunWith(classOf[Cucumber]) -@Feature("basic_arithmetic.feature") +@Options("basic_arithmetic.feature") class RunCukesTest \ No newline at end of file diff --git a/junit/src/main/java/cucumber/junit/Cucumber.java b/junit/src/main/java/cucumber/junit/Cucumber.java index e1616cce67..6d0b941ad7 100644 --- a/junit/src/main/java/cucumber/junit/Cucumber.java +++ b/junit/src/main/java/cucumber/junit/Cucumber.java @@ -13,6 +13,10 @@ import org.junit.runners.model.InitializationError; import java.io.IOException; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; import java.util.ArrayList; import java.util.List; @@ -27,9 +31,9 @@ * Cucumber will look for a {@code .feature} file on the classpath, using the same resource * path as the annotated class ({@code .class} substituted by {@code .feature}). *

- * Additional hints can be given to Cucumber by annotating the class with {@link cucumber.junit.Feature}. + * Additional hints can be given to Cucumber by annotating the class with {@link Options}. * - * @see cucumber.junit.Feature + * @see Options */ public class Cucumber extends ParentRunner { private final ResourceLoader resourceLoader; @@ -101,10 +105,10 @@ private void assertNoDeclaredMethods(Class clazz) { * @return either a path to a single feature, or to a directory or classpath entry containing them */ private List featurePaths(Class clazz) { - cucumber.junit.Feature featureAnnotation = getFeatureAnnotation(clazz); + Options cucumberOptions = getFeatureAnnotation(clazz); String featurePath; - if (featureAnnotation != null) { - featurePath = featureAnnotation.value(); + if (cucumberOptions != null) { + featurePath = cucumberOptions.value(); } else { featurePath = packagePath(clazz); } @@ -117,9 +121,9 @@ private List gluePaths(Class clazz) { gluePaths.add(packagePath(clazz)); // Add additional ones - cucumber.junit.Feature featureAnnotation = getFeatureAnnotation(clazz); - if (featureAnnotation != null) { - for (String packageName : featureAnnotation.packages()) { + Options cucumberOptions = getFeatureAnnotation(clazz); + if (cucumberOptions != null) { + for (String packageName : cucumberOptions.packages()) { gluePaths.add(packagePath(packageName)); } } @@ -127,12 +131,12 @@ private List gluePaths(Class clazz) { } private List filters(Class clazz) { - cucumber.junit.Feature featureAnnotation = getFeatureAnnotation(clazz); + Options cucumberOptions = getFeatureAnnotation(clazz); Object[] filters = new Object[0]; - if (featureAnnotation != null) { - filters = toLong(featureAnnotation.lines()); + if (cucumberOptions != null) { + filters = toLong(cucumberOptions.lines()); if (filters.length == 0) { - filters = featureAnnotation.tags(); + filters = cucumberOptions.tags(); } } return asList(filters); @@ -153,7 +157,35 @@ private Long[] toLong(long[] primitiveLongs) { return longs; } - private Feature getFeatureAnnotation(Class clazz) { - return (Feature) clazz.getAnnotation(Feature.class); + private Options getFeatureAnnotation(Class clazz) { + return (Options) clazz.getAnnotation(Options.class); + } + + /** + * This annotation can be used to give additional hints to the {@link cucumber.junit.Cucumber} runner + * about what to run. It provides similar options to the Cucumber command line used by {@link cucumber.cli.Main} + */ + @Retention(RetentionPolicy.RUNTIME) + @Target({ElementType.TYPE}) + public static @interface Options { + /** + * @return the path to the feature(s) + */ + String value(); + + /** + * @return what lines in the feature should be executed + */ + long[] lines() default {}; + + /** + * @return what tags in the feature should be executed + */ + String[] tags() default {}; + + /** + * @return where to look for glue code (stepdefs and hooks) + */ + String[] packages() default {}; } } diff --git a/junit/src/main/java/cucumber/junit/Feature.java b/junit/src/main/java/cucumber/junit/Feature.java deleted file mode 100644 index a59abb5289..0000000000 --- a/junit/src/main/java/cucumber/junit/Feature.java +++ /dev/null @@ -1,34 +0,0 @@ -package cucumber.junit; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; - -/** - * This annotation can be used to give additional hints to the {@link Cucumber} runner - * about what to run. - */ -@Retention(RetentionPolicy.RUNTIME) -@Target({ElementType.TYPE}) -public @interface Feature { - /** - * @return the path to the .feature - */ - String value(); - - /** - * @return what lines in the feature should be executed - */ - long[] lines() default {}; - - /** - * @return what tags in the feature should be executed - */ - String[] tags() default {}; - - /** - * @return where to look for glue code (stepdefs and hooks) - */ - String[] packages() default {}; -} diff --git a/junit/src/test/java/cucumber/junit/CucumberTest.java b/junit/src/test/java/cucumber/junit/CucumberTest.java index 5ce2ed6621..4f93072f1a 100644 --- a/junit/src/test/java/cucumber/junit/CucumberTest.java +++ b/junit/src/test/java/cucumber/junit/CucumberTest.java @@ -52,11 +52,11 @@ public void finds_no_features_when_explicit_package_has_nothnig() throws IOExcep private class ImplicitPackage { } - @Feature("cucumber/junit") + @Cucumber.Options("cucumber/junit") private class ExplicitPackage { } - @Feature("gibber/ish") + @Cucumber.Options("gibber/ish") private class ExplicitPackageWithNoFeatures { } } From 18e4a388c6f97b884580f707d0fd6b1a2f464ccf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aslak=20Helles=C3=B8y?= Date: Thu, 23 Feb 2012 22:29:47 +0000 Subject: [PATCH 02/10] WIP for #160 --- core/pom.xml | 4 ++ .../java/cucumber/runtime/RuntimeOptions.java | 54 +++++++++++++++++++ .../cucumber/runtime/RuntimeOptionsTest.java | 29 ++++++++++ .../scalacalculator/RunCukesTest.scala | 4 +- pom.xml | 11 +++- 5 files changed, 97 insertions(+), 5 deletions(-) create mode 100644 core/src/main/java/cucumber/runtime/RuntimeOptions.java create mode 100644 core/src/test/java/cucumber/runtime/RuntimeOptionsTest.java diff --git a/core/pom.xml b/core/pom.xml index e7fa75639d..a8c01517d4 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -22,6 +22,10 @@ info.cukes cucumber-html + + com.beust + jcommander + com.thoughtworks.xstream diff --git a/core/src/main/java/cucumber/runtime/RuntimeOptions.java b/core/src/main/java/cucumber/runtime/RuntimeOptions.java new file mode 100644 index 0000000000..db070ed8e9 --- /dev/null +++ b/core/src/main/java/cucumber/runtime/RuntimeOptions.java @@ -0,0 +1,54 @@ +package cucumber.runtime; + +import com.beust.jcommander.IStringConverter; +import com.beust.jcommander.IStringConverterFactory; +import com.beust.jcommander.JCommander; +import com.beust.jcommander.Parameter; +import cucumber.formatter.HTMLFormatter; +import gherkin.formatter.Formatter; + +import java.io.File; +import java.util.List; + +public class RuntimeOptions { + @Parameter(names = {"-g", "--glue"}, description = "Where cucumber looks for step definitions and hooks.", required = true) + public String glue; + + @Parameter(names = {"--dotcucumber"}, description = "Where to output .cucumber files (for code completion).") + public File dotCucumber; + + @Parameter(names = {"--dry-run"}, description = "Don't run anything, just format the features.") + public File dryRun; + + @Parameter(names = {"--tags"}, description = "Only execute scenarios matching TAG_EXPRESSION.") + public List tags; + + @Parameter(names = {"--strict"}, description = "Fail if there are any undefined or pending steps.") + public boolean strict; + + @Parameter(names = {"--format"}, description = "Formatter to use.") + public List formatters; + + + public RuntimeOptions(String... args) { + JCommander cmd = new JCommander(this); + cmd.addConverterFactory(new FormatterFactory()); + cmd.setProgramName("cucumber"); + cmd.parse(args); + } + + public static class FormatterFactory implements IStringConverterFactory { + @Override + public Class> getConverter(Class forType) { + if (forType.equals(Formatter.class)) return FormatterConverter.class; + else return null; + } + } + + public static class FormatterConverter implements IStringConverter { + @Override + public Formatter convert(String value) { + return new HTMLFormatter(new File("target")); + } + } +} diff --git a/core/src/test/java/cucumber/runtime/RuntimeOptionsTest.java b/core/src/test/java/cucumber/runtime/RuntimeOptionsTest.java new file mode 100644 index 0000000000..7b27b8c2aa --- /dev/null +++ b/core/src/test/java/cucumber/runtime/RuntimeOptionsTest.java @@ -0,0 +1,29 @@ +package cucumber.runtime; + +import com.beust.jcommander.JCommander; +import cucumber.formatter.HTMLFormatter; +import org.junit.Test; + +import java.io.File; + +import static junit.framework.Assert.assertEquals; + +public class RuntimeOptionsTest { + @Test + public void assigns_glue() { + RuntimeOptions options = new RuntimeOptions("--glue", "somewhere"); + assertEquals("somewhere", options.glue); + } + + @Test + public void assigns_dotcucumber() { + RuntimeOptions options = new RuntimeOptions("--dotcucumber", "somewhere", "--glue", "somewhere"); + assertEquals(new File("somewhere"), options.dotCucumber); + } + + @Test + public void creates_formatter() { + RuntimeOptions options = new RuntimeOptions("--format", "html:some/dir", "--glue", "somewhere"); + assertEquals(HTMLFormatter.class, options.formatters.get(0).getClass()); + } +} diff --git a/examples/scala-calculator/src/test/scala/cucumber/examples/scalacalculator/RunCukesTest.scala b/examples/scala-calculator/src/test/scala/cucumber/examples/scalacalculator/RunCukesTest.scala index 811005adbd..c2472fe246 100644 --- a/examples/scala-calculator/src/test/scala/cucumber/examples/scalacalculator/RunCukesTest.scala +++ b/examples/scala-calculator/src/test/scala/cucumber/examples/scalacalculator/RunCukesTest.scala @@ -1,9 +1,7 @@ package cucumber.examples.scalacalculator import org.junit.runner.RunWith -import cucumber.junit.Cucumber.Options -import cucumber.junit.{Options, Cucumber} +import cucumber.junit.Cucumber @RunWith(classOf[Cucumber]) -@Options("basic_arithmetic.feature") class RunCukesTest \ No newline at end of file diff --git a/pom.xml b/pom.xml index 8fb23ef6e3..9c60f6ad92 100644 --- a/pom.xml +++ b/pom.xml @@ -1,4 +1,5 @@ - + 4.0.0 info.cukes cucumber-jvm @@ -79,6 +80,11 @@ gherkin ${gherkin.version} + + com.beust + jcommander + 1.23 + org.codehaus.groovy groovy-all @@ -341,7 +347,8 @@ true full - + cucumber.cli.Main From 7f8844a9ac3a7456ae410df6fecf30c4449445ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aslak=20Helles=C3=B8y?= Date: Sun, 11 Mar 2012 23:08:30 +0000 Subject: [PATCH 03/10] Ease RuntimeOptions into the Runtime API --- .../java/cucumber/cli/DefaultRuntimeFactory.java | 13 ------------- core/src/main/java/cucumber/cli/Main.java | 9 ++++++--- core/src/main/java/cucumber/cli/RuntimeFactory.java | 10 ---------- core/src/main/java/cucumber/runtime/Runtime.java | 11 +++++++++-- .../main/java/cucumber/runtime/RuntimeOptions.java | 8 +++++--- .../java/cucumber/formatter/HTMLFormatterTest.java | 4 +++- .../java/cucumber/formatter/JUnitFormatterTest.java | 4 +++- .../test/java/cucumber/runtime/BackgroundTest.java | 3 ++- .../test/java/cucumber/runtime/HookOrderTest.java | 3 ++- core/src/test/java/cucumber/runtime/HookTest.java | 3 ++- .../java/cucumber/runtime/RuntimeOptionsTest.java | 10 ++++++++-- .../src/test/java/cucumber/runtime/RuntimeTest.java | 3 ++- .../runtime/java/JavaStepDefinitionTest.java | 4 +++- jruby/pom.xml | 2 +- .../cucumber/runtime/jruby/test/cukes.feature | 9 +++++---- .../cucumber/runtime/jruby/test/example.rb | 2 +- jython/bin/cucumber-jvm.py | 2 +- 17 files changed, 53 insertions(+), 47 deletions(-) delete mode 100644 core/src/main/java/cucumber/cli/DefaultRuntimeFactory.java delete mode 100644 core/src/main/java/cucumber/cli/RuntimeFactory.java diff --git a/core/src/main/java/cucumber/cli/DefaultRuntimeFactory.java b/core/src/main/java/cucumber/cli/DefaultRuntimeFactory.java deleted file mode 100644 index a6572ca5ae..0000000000 --- a/core/src/main/java/cucumber/cli/DefaultRuntimeFactory.java +++ /dev/null @@ -1,13 +0,0 @@ -package cucumber.cli; - -import cucumber.io.ResourceLoader; -import cucumber.runtime.Runtime; - -import java.util.List; - -public class DefaultRuntimeFactory implements RuntimeFactory { - @Override - public cucumber.runtime.Runtime createRuntime(ResourceLoader resourceLoader, List gluePaths, ClassLoader classLoader, boolean dryRun) { - return new Runtime(resourceLoader, gluePaths, classLoader, dryRun); - } -} diff --git a/core/src/main/java/cucumber/cli/Main.java b/core/src/main/java/cucumber/cli/Main.java index 8a2ae329bd..0651d65640 100644 --- a/core/src/main/java/cucumber/cli/Main.java +++ b/core/src/main/java/cucumber/cli/Main.java @@ -4,6 +4,7 @@ import cucumber.formatter.MultiFormatter; import cucumber.io.FileResourceLoader; import cucumber.runtime.Runtime; +import cucumber.runtime.RuntimeOptions; import cucumber.runtime.snippets.SummaryPrinter; import gherkin.formatter.Formatter; import gherkin.formatter.Reporter; @@ -22,10 +23,12 @@ public class Main { static final String VERSION = ResourceBundle.getBundle("cucumber.version").getString("cucumber-jvm.version"); public static void main(String[] argv) throws Throwable { - run(argv, Thread.currentThread().getContextClassLoader(), new DefaultRuntimeFactory()); + run(argv, Thread.currentThread().getContextClassLoader()); } - public static void run(String[] argv, ClassLoader classLoader, RuntimeFactory runtimeFactory) throws IOException { + public static void run(String[] argv, ClassLoader classLoader) throws IOException { + RuntimeOptions runtimeOptions = new RuntimeOptions(argv); + List featurePaths = new ArrayList(); List gluePaths = new ArrayList(); List filters = new ArrayList(); @@ -82,7 +85,7 @@ public static void run(String[] argv, ClassLoader classLoader, RuntimeFactory ru System.exit(1); } - Runtime runtime = runtimeFactory.createRuntime(new FileResourceLoader(), gluePaths, classLoader, isDryRun); + Runtime runtime = new Runtime(new FileResourceLoader(), gluePaths, classLoader, runtimeOptions); if (dotCucumber != null) { writeDotCucumber(featurePaths, dotCucumber, runtime); diff --git a/core/src/main/java/cucumber/cli/RuntimeFactory.java b/core/src/main/java/cucumber/cli/RuntimeFactory.java deleted file mode 100644 index 985ceedb5a..0000000000 --- a/core/src/main/java/cucumber/cli/RuntimeFactory.java +++ /dev/null @@ -1,10 +0,0 @@ -package cucumber.cli; - -import cucumber.io.ResourceLoader; -import cucumber.runtime.Runtime; - -import java.util.List; - -public interface RuntimeFactory { - Runtime createRuntime(ResourceLoader fileResourceLoader, List gluePaths, ClassLoader classLoader, boolean dryRun); -} diff --git a/core/src/main/java/cucumber/runtime/Runtime.java b/core/src/main/java/cucumber/runtime/Runtime.java index c9c84ad19e..bf7b3aecf8 100644 --- a/core/src/main/java/cucumber/runtime/Runtime.java +++ b/core/src/main/java/cucumber/runtime/Runtime.java @@ -1,6 +1,7 @@ package cucumber.runtime; import cucumber.io.ClasspathResourceLoader; +import cucumber.io.FileResourceLoader; import cucumber.io.ResourceLoader; import cucumber.runtime.converters.LocalizedXStreams; import cucumber.runtime.model.CucumberFeature; @@ -46,16 +47,21 @@ public class Runtime implements UnreportedStepExecutor { //They really should be created each time a scenario is run, not in here private boolean skipNextStep = false; private ScenarioResultImpl scenarioResult = null; + private final RuntimeOptions runtimeOptions; public Runtime(ResourceLoader resourceLoader, List gluePaths, ClassLoader classLoader) { this(resourceLoader, gluePaths, classLoader, false); } public Runtime(ResourceLoader resourceLoader, List gluePaths, ClassLoader classLoader, boolean isDryRun) { - this(resourceLoader, gluePaths, classLoader, loadBackends(resourceLoader, classLoader), isDryRun); + this(resourceLoader, gluePaths, classLoader, loadBackends(resourceLoader, classLoader), isDryRun, null); } - public Runtime(ResourceLoader resourceLoader, List gluePaths, ClassLoader classLoader, Collection backends, boolean isDryRun) { + public Runtime(ResourceLoader resourceLoader, List gluePaths, ClassLoader classLoader, RuntimeOptions runtimeOptions) { + this(resourceLoader, gluePaths, classLoader, loadBackends(resourceLoader, classLoader), runtimeOptions.dryRun, runtimeOptions); + } + + public Runtime(ResourceLoader resourceLoader, List gluePaths, ClassLoader classLoader, Collection backends, boolean isDryRun, RuntimeOptions runtimeOptions) { if (backends.isEmpty()) { throw new CucumberException("No backends were found. Please make sure you have a backend module on your CLASSPATH."); } @@ -68,6 +74,7 @@ public Runtime(ResourceLoader resourceLoader, List gluePaths, ClassLoade backend.loadGlue(glue, gluePaths); backend.setUnreportedStepExecutor(this); } + this.runtimeOptions = runtimeOptions; } private static Collection loadBackends(ResourceLoader resourceLoader, ClassLoader classLoader) { diff --git a/core/src/main/java/cucumber/runtime/RuntimeOptions.java b/core/src/main/java/cucumber/runtime/RuntimeOptions.java index db070ed8e9..7d50986e26 100644 --- a/core/src/main/java/cucumber/runtime/RuntimeOptions.java +++ b/core/src/main/java/cucumber/runtime/RuntimeOptions.java @@ -11,14 +11,14 @@ import java.util.List; public class RuntimeOptions { - @Parameter(names = {"-g", "--glue"}, description = "Where cucumber looks for step definitions and hooks.", required = true) - public String glue; + @Parameter(names = {"-g", "--glue"}, description = "Where cucumber looks for step definitions and hooks.") + public List glue; @Parameter(names = {"--dotcucumber"}, description = "Where to output .cucumber files (for code completion).") public File dotCucumber; @Parameter(names = {"--dry-run"}, description = "Don't run anything, just format the features.") - public File dryRun; + public boolean dryRun; @Parameter(names = {"--tags"}, description = "Only execute scenarios matching TAG_EXPRESSION.") public List tags; @@ -29,6 +29,8 @@ public class RuntimeOptions { @Parameter(names = {"--format"}, description = "Formatter to use.") public List formatters; + @Parameter(description = "Feature paths") + public List featurePaths; public RuntimeOptions(String... args) { JCommander cmd = new JCommander(this); diff --git a/core/src/test/java/cucumber/formatter/HTMLFormatterTest.java b/core/src/test/java/cucumber/formatter/HTMLFormatterTest.java index 1275a3d271..6a0043a259 100644 --- a/core/src/test/java/cucumber/formatter/HTMLFormatterTest.java +++ b/core/src/test/java/cucumber/formatter/HTMLFormatterTest.java @@ -3,6 +3,7 @@ import cucumber.io.ClasspathResourceLoader; import cucumber.runtime.Backend; import cucumber.runtime.Runtime; +import cucumber.runtime.RuntimeOptions; import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.nodes.Element; @@ -60,7 +61,8 @@ private void runFeaturesWithFormatter(final List featurePaths, File outp final ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); final ClasspathResourceLoader resourceLoader = new ClasspathResourceLoader(classLoader); final List gluePaths = emptyList(); - final Runtime runtime = new Runtime(resourceLoader, gluePaths, classLoader, asList(mock(Backend.class)), false); + RuntimeOptions runtimeOptions = new RuntimeOptions(); + final Runtime runtime = new Runtime(resourceLoader, gluePaths, classLoader, asList(mock(Backend.class)), false, runtimeOptions); runtime.run(featurePaths, emptyList(), f, f); f.done(); f.close(); diff --git a/core/src/test/java/cucumber/formatter/JUnitFormatterTest.java b/core/src/test/java/cucumber/formatter/JUnitFormatterTest.java index 8dcb2f9853..7e73c17868 100644 --- a/core/src/test/java/cucumber/formatter/JUnitFormatterTest.java +++ b/core/src/test/java/cucumber/formatter/JUnitFormatterTest.java @@ -3,6 +3,7 @@ import cucumber.io.ClasspathResourceLoader; import cucumber.runtime.Backend; import cucumber.runtime.Runtime; +import cucumber.runtime.RuntimeOptions; import org.custommonkey.xmlunit.Diff; import org.custommonkey.xmlunit.XMLUnit; import org.junit.Test; @@ -49,7 +50,8 @@ private void runFeaturesWithFormatter(final List featurePaths) throws IO final ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); final ClasspathResourceLoader resourceLoader = new ClasspathResourceLoader(classLoader); final List gluePaths = emptyList(); - final cucumber.runtime.Runtime runtime = new Runtime(resourceLoader, gluePaths, classLoader, asList(mock(Backend.class)), false); + RuntimeOptions runtimeOptions = new RuntimeOptions(); + final cucumber.runtime.Runtime runtime = new Runtime(resourceLoader, gluePaths, classLoader, asList(mock(Backend.class)), false, runtimeOptions); runtime.run(featurePaths, emptyList(), f, f); f.done(); f.close(); diff --git a/core/src/test/java/cucumber/runtime/BackgroundTest.java b/core/src/test/java/cucumber/runtime/BackgroundTest.java index a436d71330..ccbd53e3db 100644 --- a/core/src/test/java/cucumber/runtime/BackgroundTest.java +++ b/core/src/test/java/cucumber/runtime/BackgroundTest.java @@ -17,7 +17,8 @@ public class BackgroundTest { @Test public void should_run_background() throws IOException { ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); - Runtime runtime = new Runtime(new ClasspathResourceLoader(classLoader), new ArrayList(), classLoader, asList(mock(Backend.class)), false); + RuntimeOptions runtimeOptions = new RuntimeOptions(); + Runtime runtime = new Runtime(new ClasspathResourceLoader(classLoader), new ArrayList(), classLoader, asList(mock(Backend.class)), false, runtimeOptions); CucumberFeature feature = feature("test.feature", "" + "Feature:\n" + " Background:\n" + diff --git a/core/src/test/java/cucumber/runtime/HookOrderTest.java b/core/src/test/java/cucumber/runtime/HookOrderTest.java index ede57bb358..6891dfc675 100644 --- a/core/src/test/java/cucumber/runtime/HookOrderTest.java +++ b/core/src/test/java/cucumber/runtime/HookOrderTest.java @@ -27,7 +27,8 @@ public class HookOrderTest { @Before public void buildMockWorld() { ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); - runtime = new Runtime(mock(ResourceLoader.class), new ArrayList(), classLoader, asList(mock(Backend.class)), false); + RuntimeOptions runtimeOptions = new RuntimeOptions(); + runtime = new Runtime(mock(ResourceLoader.class), new ArrayList(), classLoader, asList(mock(Backend.class)), false, runtimeOptions); glue = runtime.getGlue(); } diff --git a/core/src/test/java/cucumber/runtime/HookTest.java b/core/src/test/java/cucumber/runtime/HookTest.java index 53e022a440..8f220f19cd 100644 --- a/core/src/test/java/cucumber/runtime/HookTest.java +++ b/core/src/test/java/cucumber/runtime/HookTest.java @@ -47,7 +47,8 @@ public void after_hooks_execute_before_objects_are_disposed() throws Throwable { CucumberScenario scenario = new CucumberScenario(feature, null, gherkinScenario); ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); - Runtime runtime = new Runtime(new ClasspathResourceLoader(classLoader), CODE_PATHS, classLoader, asList(backend), false); + RuntimeOptions runtimeOptions = new RuntimeOptions(); + Runtime runtime = new Runtime(new ClasspathResourceLoader(classLoader), CODE_PATHS, classLoader, asList(backend), false, runtimeOptions); runtime.getGlue().addAfterHook(hook); scenario.run(mock(Formatter.class), mock(Reporter.class), runtime); diff --git a/core/src/test/java/cucumber/runtime/RuntimeOptionsTest.java b/core/src/test/java/cucumber/runtime/RuntimeOptionsTest.java index 7b27b8c2aa..95d45aeddb 100644 --- a/core/src/test/java/cucumber/runtime/RuntimeOptionsTest.java +++ b/core/src/test/java/cucumber/runtime/RuntimeOptionsTest.java @@ -1,18 +1,24 @@ package cucumber.runtime; -import com.beust.jcommander.JCommander; import cucumber.formatter.HTMLFormatter; import org.junit.Test; import java.io.File; +import static java.util.Arrays.asList; import static junit.framework.Assert.assertEquals; public class RuntimeOptionsTest { + @Test + public void assigns_feature_paths() { + RuntimeOptions options = new RuntimeOptions("--glue", "somewhere", "somewhere_else"); + assertEquals(asList(new File("somewhere_else")), options.featurePaths); + } + @Test public void assigns_glue() { RuntimeOptions options = new RuntimeOptions("--glue", "somewhere"); - assertEquals("somewhere", options.glue); + assertEquals(asList(new File("somewhere")), options.glue); } @Test diff --git a/core/src/test/java/cucumber/runtime/RuntimeTest.java b/core/src/test/java/cucumber/runtime/RuntimeTest.java index 2f67437f94..da38606e73 100644 --- a/core/src/test/java/cucumber/runtime/RuntimeTest.java +++ b/core/src/test/java/cucumber/runtime/RuntimeTest.java @@ -26,7 +26,8 @@ public void runs_feature_with_json_formatter() throws Exception { JSONPrettyFormatter jsonFormatter = new JSONPrettyFormatter(out); List backends = asList(mock(Backend.class)); ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); - new Runtime(new ClasspathResourceLoader(classLoader), Collections.emptyList(), classLoader, backends, true).run(feature, jsonFormatter, jsonFormatter); + RuntimeOptions runtimeOptions = new RuntimeOptions(); + new Runtime(new ClasspathResourceLoader(classLoader), Collections.emptyList(), classLoader, backends, true, runtimeOptions).run(feature, jsonFormatter, jsonFormatter); jsonFormatter.done(); String expected = "" + "[\n" + diff --git a/java/src/test/java/cucumber/runtime/java/JavaStepDefinitionTest.java b/java/src/test/java/cucumber/runtime/java/JavaStepDefinitionTest.java index 420b56c6ba..2bbba5d1b7 100644 --- a/java/src/test/java/cucumber/runtime/java/JavaStepDefinitionTest.java +++ b/java/src/test/java/cucumber/runtime/java/JavaStepDefinitionTest.java @@ -5,6 +5,7 @@ import cucumber.runtime.AmbiguousStepDefinitionsException; import cucumber.runtime.Glue; import cucumber.runtime.Runtime; +import cucumber.runtime.RuntimeOptions; import gherkin.I18n; import gherkin.formatter.Reporter; import gherkin.formatter.model.Comment; @@ -46,7 +47,8 @@ public class JavaStepDefinitionTest { private final Defs defs = new Defs(); private final JavaBackend backend = new JavaBackend(new SingletonFactory(defs)); private final ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); - private final Runtime runtime = new Runtime(new ClasspathResourceLoader(classLoader), NO_PATHS, classLoader, asList(backend), false); + private final RuntimeOptions runtimeOptions = new RuntimeOptions(); + private final Runtime runtime = new Runtime(new ClasspathResourceLoader(classLoader), NO_PATHS, classLoader, asList(backend), false, runtimeOptions); private final Glue glue = runtime.getGlue(); @org.junit.Before diff --git a/jruby/pom.xml b/jruby/pom.xml index c354751838..04b1e8864c 100644 --- a/jruby/pom.xml +++ b/jruby/pom.xml @@ -95,7 +95,7 @@ - + diff --git a/jruby/src/test/resources/cucumber/runtime/jruby/test/cukes.feature b/jruby/src/test/resources/cucumber/runtime/jruby/test/cukes.feature index 986cc64882..581a84fb7e 100644 --- a/jruby/src/test/resources/cucumber/runtime/jruby/test/cukes.feature +++ b/jruby/src/test/resources/cucumber/runtime/jruby/test/cukes.feature @@ -42,7 +42,8 @@ Feature: Cukes Given I store the value "" When I grab another value "" Then those values are the same - Examples: - | value | otherValue | - | 1 | 1 | - | awesome | awesome | \ No newline at end of file + + Examples: + | value | otherValue | + | 1 | 1 | + | awesome | awesome | \ No newline at end of file diff --git a/jruby/src/test/resources/cucumber/runtime/jruby/test/example.rb b/jruby/src/test/resources/cucumber/runtime/jruby/test/example.rb index 8f453a060d..7bdb69f2b4 100644 --- a/jruby/src/test/resources/cucumber/runtime/jruby/test/example.rb +++ b/jruby/src/test/resources/cucumber/runtime/jruby/test/example.rb @@ -1,7 +1,7 @@ # JRUBY will barf out warnings when we redefine constants :D DEFINE_A_CONSTANT = 1 -#this will help me ensure that jruby stuff is only loaded one time +# this will help me ensure that jruby stuff is only loaded one time # otherwise tests will bomb and fail, as they should. if @loaded_already raise "OMG PARSED MULTIPLE TIMES!!!!1" diff --git a/jython/bin/cucumber-jvm.py b/jython/bin/cucumber-jvm.py index 620e05d629..6e11f04914 100644 --- a/jython/bin/cucumber-jvm.py +++ b/jython/bin/cucumber-jvm.py @@ -18,4 +18,4 @@ def createRuntime(resourceLoader, gluePaths, classLoader, dryRun): jythonBackend = JythonBackend(resourceLoader) return Runtime(resourceLoader, gluePaths, classLoader, [jythonBackend], dryRun) -Main.run(sys.argv[1:], cl, createRuntime) +Main.run(sys.argv[1:], cl) From 46aa3ecd3efaf1d722329730f469729bfdfefea5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aslak=20Helles=C3=B8y?= Date: Sun, 11 Mar 2012 23:21:52 +0000 Subject: [PATCH 04/10] Get dryRun from runtimeOptions --- .../main/java/cucumber/runtime/Runtime.java | 21 +++---------------- .../cucumber/formatter/HTMLFormatterTest.java | 2 +- .../formatter/JUnitFormatterTest.java | 2 +- .../java/cucumber/runtime/BackgroundTest.java | 2 +- .../java/cucumber/runtime/HookOrderTest.java | 2 +- .../test/java/cucumber/runtime/HookTest.java | 2 +- .../java/cucumber/runtime/RuntimeTest.java | 2 +- .../runtime/java/JavaStepDefinitionTest.java | 2 +- .../main/java/cucumber/junit/Cucumber.java | 14 +++++++++++-- 9 files changed, 22 insertions(+), 27 deletions(-) diff --git a/core/src/main/java/cucumber/runtime/Runtime.java b/core/src/main/java/cucumber/runtime/Runtime.java index bf7b3aecf8..4698d72db6 100644 --- a/core/src/main/java/cucumber/runtime/Runtime.java +++ b/core/src/main/java/cucumber/runtime/Runtime.java @@ -1,7 +1,6 @@ package cucumber.runtime; import cucumber.io.ClasspathResourceLoader; -import cucumber.io.FileResourceLoader; import cucumber.io.ResourceLoader; import cucumber.runtime.converters.LocalizedXStreams; import cucumber.runtime.model.CucumberFeature; @@ -40,7 +39,6 @@ public class Runtime implements UnreportedStepExecutor { private final List errors = new ArrayList(); private final Collection backends; - private final boolean isDryRun; private final ResourceLoader resourceLoader; //TODO: These are really state machine variables, and I'm not sure the runtime is the best place for this state machine @@ -49,25 +47,16 @@ public class Runtime implements UnreportedStepExecutor { private ScenarioResultImpl scenarioResult = null; private final RuntimeOptions runtimeOptions; - public Runtime(ResourceLoader resourceLoader, List gluePaths, ClassLoader classLoader) { - this(resourceLoader, gluePaths, classLoader, false); - } - - public Runtime(ResourceLoader resourceLoader, List gluePaths, ClassLoader classLoader, boolean isDryRun) { - this(resourceLoader, gluePaths, classLoader, loadBackends(resourceLoader, classLoader), isDryRun, null); - } - public Runtime(ResourceLoader resourceLoader, List gluePaths, ClassLoader classLoader, RuntimeOptions runtimeOptions) { - this(resourceLoader, gluePaths, classLoader, loadBackends(resourceLoader, classLoader), runtimeOptions.dryRun, runtimeOptions); + this(resourceLoader, gluePaths, classLoader, loadBackends(resourceLoader, classLoader), runtimeOptions); } - public Runtime(ResourceLoader resourceLoader, List gluePaths, ClassLoader classLoader, Collection backends, boolean isDryRun, RuntimeOptions runtimeOptions) { + public Runtime(ResourceLoader resourceLoader, List gluePaths, ClassLoader classLoader, Collection backends, RuntimeOptions runtimeOptions) { if (backends.isEmpty()) { throw new CucumberException("No backends were found. Please make sure you have a backend module on your CLASSPATH."); } this.backends = backends; this.resourceLoader = resourceLoader; - this.isDryRun = isDryRun; glue = new RuntimeGlue(undefinedStepsTracker, new LocalizedXStreams(classLoader)); for (Backend backend : backends) { @@ -132,10 +121,6 @@ public void disposeBackendWorlds() { } } - public boolean isDryRun() { - return isDryRun; - } - public List getErrors() { return errors; } @@ -229,7 +214,7 @@ public void runStep(String uri, Step step, Reporter reporter, I18n i18n) { return; } - if (isDryRun()) { + if (runtimeOptions.dryRun) { skipNextStep = true; } diff --git a/core/src/test/java/cucumber/formatter/HTMLFormatterTest.java b/core/src/test/java/cucumber/formatter/HTMLFormatterTest.java index 6a0043a259..754830f742 100644 --- a/core/src/test/java/cucumber/formatter/HTMLFormatterTest.java +++ b/core/src/test/java/cucumber/formatter/HTMLFormatterTest.java @@ -62,7 +62,7 @@ private void runFeaturesWithFormatter(final List featurePaths, File outp final ClasspathResourceLoader resourceLoader = new ClasspathResourceLoader(classLoader); final List gluePaths = emptyList(); RuntimeOptions runtimeOptions = new RuntimeOptions(); - final Runtime runtime = new Runtime(resourceLoader, gluePaths, classLoader, asList(mock(Backend.class)), false, runtimeOptions); + final Runtime runtime = new Runtime(resourceLoader, gluePaths, classLoader, asList(mock(Backend.class)), runtimeOptions); runtime.run(featurePaths, emptyList(), f, f); f.done(); f.close(); diff --git a/core/src/test/java/cucumber/formatter/JUnitFormatterTest.java b/core/src/test/java/cucumber/formatter/JUnitFormatterTest.java index 7e73c17868..e5bfbfc847 100644 --- a/core/src/test/java/cucumber/formatter/JUnitFormatterTest.java +++ b/core/src/test/java/cucumber/formatter/JUnitFormatterTest.java @@ -51,7 +51,7 @@ private void runFeaturesWithFormatter(final List featurePaths) throws IO final ClasspathResourceLoader resourceLoader = new ClasspathResourceLoader(classLoader); final List gluePaths = emptyList(); RuntimeOptions runtimeOptions = new RuntimeOptions(); - final cucumber.runtime.Runtime runtime = new Runtime(resourceLoader, gluePaths, classLoader, asList(mock(Backend.class)), false, runtimeOptions); + final cucumber.runtime.Runtime runtime = new Runtime(resourceLoader, gluePaths, classLoader, asList(mock(Backend.class)), runtimeOptions); runtime.run(featurePaths, emptyList(), f, f); f.done(); f.close(); diff --git a/core/src/test/java/cucumber/runtime/BackgroundTest.java b/core/src/test/java/cucumber/runtime/BackgroundTest.java index ccbd53e3db..1604fdec2f 100644 --- a/core/src/test/java/cucumber/runtime/BackgroundTest.java +++ b/core/src/test/java/cucumber/runtime/BackgroundTest.java @@ -18,7 +18,7 @@ public class BackgroundTest { public void should_run_background() throws IOException { ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); RuntimeOptions runtimeOptions = new RuntimeOptions(); - Runtime runtime = new Runtime(new ClasspathResourceLoader(classLoader), new ArrayList(), classLoader, asList(mock(Backend.class)), false, runtimeOptions); + Runtime runtime = new Runtime(new ClasspathResourceLoader(classLoader), new ArrayList(), classLoader, asList(mock(Backend.class)), runtimeOptions); CucumberFeature feature = feature("test.feature", "" + "Feature:\n" + " Background:\n" + diff --git a/core/src/test/java/cucumber/runtime/HookOrderTest.java b/core/src/test/java/cucumber/runtime/HookOrderTest.java index 6891dfc675..170dd84d3c 100644 --- a/core/src/test/java/cucumber/runtime/HookOrderTest.java +++ b/core/src/test/java/cucumber/runtime/HookOrderTest.java @@ -28,7 +28,7 @@ public class HookOrderTest { public void buildMockWorld() { ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); RuntimeOptions runtimeOptions = new RuntimeOptions(); - runtime = new Runtime(mock(ResourceLoader.class), new ArrayList(), classLoader, asList(mock(Backend.class)), false, runtimeOptions); + runtime = new Runtime(mock(ResourceLoader.class), new ArrayList(), classLoader, asList(mock(Backend.class)), runtimeOptions); glue = runtime.getGlue(); } diff --git a/core/src/test/java/cucumber/runtime/HookTest.java b/core/src/test/java/cucumber/runtime/HookTest.java index 8f220f19cd..d0c6a1c33b 100644 --- a/core/src/test/java/cucumber/runtime/HookTest.java +++ b/core/src/test/java/cucumber/runtime/HookTest.java @@ -48,7 +48,7 @@ public void after_hooks_execute_before_objects_are_disposed() throws Throwable { ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); RuntimeOptions runtimeOptions = new RuntimeOptions(); - Runtime runtime = new Runtime(new ClasspathResourceLoader(classLoader), CODE_PATHS, classLoader, asList(backend), false, runtimeOptions); + Runtime runtime = new Runtime(new ClasspathResourceLoader(classLoader), CODE_PATHS, classLoader, asList(backend), runtimeOptions); runtime.getGlue().addAfterHook(hook); scenario.run(mock(Formatter.class), mock(Reporter.class), runtime); diff --git a/core/src/test/java/cucumber/runtime/RuntimeTest.java b/core/src/test/java/cucumber/runtime/RuntimeTest.java index da38606e73..6e322966ff 100644 --- a/core/src/test/java/cucumber/runtime/RuntimeTest.java +++ b/core/src/test/java/cucumber/runtime/RuntimeTest.java @@ -27,7 +27,7 @@ public void runs_feature_with_json_formatter() throws Exception { List backends = asList(mock(Backend.class)); ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); RuntimeOptions runtimeOptions = new RuntimeOptions(); - new Runtime(new ClasspathResourceLoader(classLoader), Collections.emptyList(), classLoader, backends, true, runtimeOptions).run(feature, jsonFormatter, jsonFormatter); + new Runtime(new ClasspathResourceLoader(classLoader), Collections.emptyList(), classLoader, backends, runtimeOptions).run(feature, jsonFormatter, jsonFormatter); jsonFormatter.done(); String expected = "" + "[\n" + diff --git a/java/src/test/java/cucumber/runtime/java/JavaStepDefinitionTest.java b/java/src/test/java/cucumber/runtime/java/JavaStepDefinitionTest.java index 2bbba5d1b7..81ffd626dc 100644 --- a/java/src/test/java/cucumber/runtime/java/JavaStepDefinitionTest.java +++ b/java/src/test/java/cucumber/runtime/java/JavaStepDefinitionTest.java @@ -48,7 +48,7 @@ public class JavaStepDefinitionTest { private final JavaBackend backend = new JavaBackend(new SingletonFactory(defs)); private final ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); private final RuntimeOptions runtimeOptions = new RuntimeOptions(); - private final Runtime runtime = new Runtime(new ClasspathResourceLoader(classLoader), NO_PATHS, classLoader, asList(backend), false, runtimeOptions); + private final Runtime runtime = new Runtime(new ClasspathResourceLoader(classLoader), NO_PATHS, classLoader, asList(backend), runtimeOptions); private final Glue glue = runtime.getGlue(); @org.junit.Before diff --git a/junit/src/main/java/cucumber/junit/Cucumber.java b/junit/src/main/java/cucumber/junit/Cucumber.java index 6d0b941ad7..a63c67494d 100644 --- a/junit/src/main/java/cucumber/junit/Cucumber.java +++ b/junit/src/main/java/cucumber/junit/Cucumber.java @@ -5,6 +5,7 @@ import cucumber.io.ResourceLoader; import cucumber.runtime.CucumberException; import cucumber.runtime.Runtime; +import cucumber.runtime.RuntimeOptions; import cucumber.runtime.model.CucumberFeature; import cucumber.runtime.snippets.SummaryPrinter; import org.junit.runner.Description; @@ -55,9 +56,9 @@ public Cucumber(Class clazz) throws InitializationError, IOException { resourceLoader = new ClasspathResourceLoader(classLoader); assertNoDeclaredMethods(clazz); List featurePaths = featurePaths(clazz); - List gluePaths = gluePaths(clazz); - runtime = new Runtime(resourceLoader, gluePaths, classLoader); + RuntimeOptions runtimeOptions = runtimeOptions(clazz); + runtime = new Runtime(resourceLoader, gluePaths, classLoader, runtimeOptions); // TODO: Create formatter(s) based on Annotations. Use same technique as in cli.Main for MultiFormatter jUnitReporter = new JUnitReporter(new NullReporter(), new NullReporter()); @@ -100,6 +101,15 @@ private void assertNoDeclaredMethods(Class clazz) { } } + private RuntimeOptions runtimeOptions(Class clazz) { + Options cucumberOptions = getFeatureAnnotation(clazz); + + List args = new ArrayList(); + + RuntimeOptions runtimeOptions = new RuntimeOptions(args.toArray(new String[args.size()])); + return runtimeOptions; + } + /** * @param clazz the Class used to kick it all off * @return either a path to a single feature, or to a directory or classpath entry containing them From 0e143c0b933d90e9794ff873dd7b5a7dac417a25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aslak=20Helles=C3=B8y?= Date: Sun, 11 Mar 2012 23:46:41 +0000 Subject: [PATCH 05/10] Get gluePath from runtimeOptions --- core/src/main/java/cucumber/cli/Main.java | 2 +- .../main/java/cucumber/runtime/Runtime.java | 8 ++-- .../java/cucumber/runtime/RuntimeOptions.java | 5 +- .../cucumber/formatter/HTMLFormatterTest.java | 2 +- .../formatter/JUnitFormatterTest.java | 2 +- .../java/cucumber/runtime/BackgroundTest.java | 3 +- .../java/cucumber/runtime/HookOrderTest.java | 2 +- .../test/java/cucumber/runtime/HookTest.java | 2 +- .../cucumber/runtime/RuntimeOptionsTest.java | 4 +- .../java/cucumber/runtime/RuntimeTest.java | 3 +- .../runtime/java/JavaStepDefinitionTest.java | 2 +- .../main/java/cucumber/junit/Cucumber.java | 47 ++++++++----------- .../spring/hooks/SpringTransactionHooks.java | 4 +- 13 files changed, 38 insertions(+), 48 deletions(-) diff --git a/core/src/main/java/cucumber/cli/Main.java b/core/src/main/java/cucumber/cli/Main.java index 0651d65640..ecc0bb42ee 100644 --- a/core/src/main/java/cucumber/cli/Main.java +++ b/core/src/main/java/cucumber/cli/Main.java @@ -85,7 +85,7 @@ public static void run(String[] argv, ClassLoader classLoader) throws IOExceptio System.exit(1); } - Runtime runtime = new Runtime(new FileResourceLoader(), gluePaths, classLoader, runtimeOptions); + Runtime runtime = new Runtime(new FileResourceLoader(), classLoader, runtimeOptions); if (dotCucumber != null) { writeDotCucumber(featurePaths, dotCucumber, runtime); diff --git a/core/src/main/java/cucumber/runtime/Runtime.java b/core/src/main/java/cucumber/runtime/Runtime.java index 4698d72db6..e14b31212b 100644 --- a/core/src/main/java/cucumber/runtime/Runtime.java +++ b/core/src/main/java/cucumber/runtime/Runtime.java @@ -47,11 +47,11 @@ public class Runtime implements UnreportedStepExecutor { private ScenarioResultImpl scenarioResult = null; private final RuntimeOptions runtimeOptions; - public Runtime(ResourceLoader resourceLoader, List gluePaths, ClassLoader classLoader, RuntimeOptions runtimeOptions) { - this(resourceLoader, gluePaths, classLoader, loadBackends(resourceLoader, classLoader), runtimeOptions); + public Runtime(ResourceLoader resourceLoader, ClassLoader classLoader, RuntimeOptions runtimeOptions) { + this(resourceLoader, classLoader, loadBackends(resourceLoader, classLoader), runtimeOptions); } - public Runtime(ResourceLoader resourceLoader, List gluePaths, ClassLoader classLoader, Collection backends, RuntimeOptions runtimeOptions) { + public Runtime(ResourceLoader resourceLoader, ClassLoader classLoader, Collection backends, RuntimeOptions runtimeOptions) { if (backends.isEmpty()) { throw new CucumberException("No backends were found. Please make sure you have a backend module on your CLASSPATH."); } @@ -60,7 +60,7 @@ public Runtime(ResourceLoader resourceLoader, List gluePaths, ClassLoade glue = new RuntimeGlue(undefinedStepsTracker, new LocalizedXStreams(classLoader)); for (Backend backend : backends) { - backend.loadGlue(glue, gluePaths); + backend.loadGlue(glue, runtimeOptions.glue); backend.setUnreportedStepExecutor(this); } this.runtimeOptions = runtimeOptions; diff --git a/core/src/main/java/cucumber/runtime/RuntimeOptions.java b/core/src/main/java/cucumber/runtime/RuntimeOptions.java index 7d50986e26..6fd15db667 100644 --- a/core/src/main/java/cucumber/runtime/RuntimeOptions.java +++ b/core/src/main/java/cucumber/runtime/RuntimeOptions.java @@ -8,11 +8,12 @@ import gherkin.formatter.Formatter; import java.io.File; +import java.util.ArrayList; import java.util.List; public class RuntimeOptions { @Parameter(names = {"-g", "--glue"}, description = "Where cucumber looks for step definitions and hooks.") - public List glue; + public List glue = new ArrayList(); @Parameter(names = {"--dotcucumber"}, description = "Where to output .cucumber files (for code completion).") public File dotCucumber; @@ -30,7 +31,7 @@ public class RuntimeOptions { public List formatters; @Parameter(description = "Feature paths") - public List featurePaths; + public List featurePaths; public RuntimeOptions(String... args) { JCommander cmd = new JCommander(this); diff --git a/core/src/test/java/cucumber/formatter/HTMLFormatterTest.java b/core/src/test/java/cucumber/formatter/HTMLFormatterTest.java index 754830f742..164afab171 100644 --- a/core/src/test/java/cucumber/formatter/HTMLFormatterTest.java +++ b/core/src/test/java/cucumber/formatter/HTMLFormatterTest.java @@ -62,7 +62,7 @@ private void runFeaturesWithFormatter(final List featurePaths, File outp final ClasspathResourceLoader resourceLoader = new ClasspathResourceLoader(classLoader); final List gluePaths = emptyList(); RuntimeOptions runtimeOptions = new RuntimeOptions(); - final Runtime runtime = new Runtime(resourceLoader, gluePaths, classLoader, asList(mock(Backend.class)), runtimeOptions); + final Runtime runtime = new Runtime(resourceLoader, classLoader, asList(mock(Backend.class)), runtimeOptions); runtime.run(featurePaths, emptyList(), f, f); f.done(); f.close(); diff --git a/core/src/test/java/cucumber/formatter/JUnitFormatterTest.java b/core/src/test/java/cucumber/formatter/JUnitFormatterTest.java index e5bfbfc847..f6c56bac18 100644 --- a/core/src/test/java/cucumber/formatter/JUnitFormatterTest.java +++ b/core/src/test/java/cucumber/formatter/JUnitFormatterTest.java @@ -51,7 +51,7 @@ private void runFeaturesWithFormatter(final List featurePaths) throws IO final ClasspathResourceLoader resourceLoader = new ClasspathResourceLoader(classLoader); final List gluePaths = emptyList(); RuntimeOptions runtimeOptions = new RuntimeOptions(); - final cucumber.runtime.Runtime runtime = new Runtime(resourceLoader, gluePaths, classLoader, asList(mock(Backend.class)), runtimeOptions); + final cucumber.runtime.Runtime runtime = new Runtime(resourceLoader, classLoader, asList(mock(Backend.class)), runtimeOptions); runtime.run(featurePaths, emptyList(), f, f); f.done(); f.close(); diff --git a/core/src/test/java/cucumber/runtime/BackgroundTest.java b/core/src/test/java/cucumber/runtime/BackgroundTest.java index 1604fdec2f..39bef90c78 100644 --- a/core/src/test/java/cucumber/runtime/BackgroundTest.java +++ b/core/src/test/java/cucumber/runtime/BackgroundTest.java @@ -6,7 +6,6 @@ import org.junit.Test; import java.io.IOException; -import java.util.ArrayList; import static cucumber.runtime.TestHelper.feature; import static java.util.Arrays.asList; @@ -18,7 +17,7 @@ public class BackgroundTest { public void should_run_background() throws IOException { ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); RuntimeOptions runtimeOptions = new RuntimeOptions(); - Runtime runtime = new Runtime(new ClasspathResourceLoader(classLoader), new ArrayList(), classLoader, asList(mock(Backend.class)), runtimeOptions); + Runtime runtime = new Runtime(new ClasspathResourceLoader(classLoader), classLoader, asList(mock(Backend.class)), runtimeOptions); CucumberFeature feature = feature("test.feature", "" + "Feature:\n" + " Background:\n" + diff --git a/core/src/test/java/cucumber/runtime/HookOrderTest.java b/core/src/test/java/cucumber/runtime/HookOrderTest.java index 170dd84d3c..75906421a9 100644 --- a/core/src/test/java/cucumber/runtime/HookOrderTest.java +++ b/core/src/test/java/cucumber/runtime/HookOrderTest.java @@ -28,7 +28,7 @@ public class HookOrderTest { public void buildMockWorld() { ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); RuntimeOptions runtimeOptions = new RuntimeOptions(); - runtime = new Runtime(mock(ResourceLoader.class), new ArrayList(), classLoader, asList(mock(Backend.class)), runtimeOptions); + runtime = new Runtime(mock(ResourceLoader.class), classLoader, asList(mock(Backend.class)), runtimeOptions); glue = runtime.getGlue(); } diff --git a/core/src/test/java/cucumber/runtime/HookTest.java b/core/src/test/java/cucumber/runtime/HookTest.java index d0c6a1c33b..25b524ff4a 100644 --- a/core/src/test/java/cucumber/runtime/HookTest.java +++ b/core/src/test/java/cucumber/runtime/HookTest.java @@ -48,7 +48,7 @@ public void after_hooks_execute_before_objects_are_disposed() throws Throwable { ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); RuntimeOptions runtimeOptions = new RuntimeOptions(); - Runtime runtime = new Runtime(new ClasspathResourceLoader(classLoader), CODE_PATHS, classLoader, asList(backend), runtimeOptions); + Runtime runtime = new Runtime(new ClasspathResourceLoader(classLoader), classLoader, asList(backend), runtimeOptions); runtime.getGlue().addAfterHook(hook); scenario.run(mock(Formatter.class), mock(Reporter.class), runtime); diff --git a/core/src/test/java/cucumber/runtime/RuntimeOptionsTest.java b/core/src/test/java/cucumber/runtime/RuntimeOptionsTest.java index 95d45aeddb..6a422b4c1a 100644 --- a/core/src/test/java/cucumber/runtime/RuntimeOptionsTest.java +++ b/core/src/test/java/cucumber/runtime/RuntimeOptionsTest.java @@ -12,13 +12,13 @@ public class RuntimeOptionsTest { @Test public void assigns_feature_paths() { RuntimeOptions options = new RuntimeOptions("--glue", "somewhere", "somewhere_else"); - assertEquals(asList(new File("somewhere_else")), options.featurePaths); + assertEquals(asList("somewhere_else"), options.featurePaths); } @Test public void assigns_glue() { RuntimeOptions options = new RuntimeOptions("--glue", "somewhere"); - assertEquals(asList(new File("somewhere")), options.glue); + assertEquals(asList("somewhere"), options.glue); } @Test diff --git a/core/src/test/java/cucumber/runtime/RuntimeTest.java b/core/src/test/java/cucumber/runtime/RuntimeTest.java index 6e322966ff..ac6965038e 100644 --- a/core/src/test/java/cucumber/runtime/RuntimeTest.java +++ b/core/src/test/java/cucumber/runtime/RuntimeTest.java @@ -5,7 +5,6 @@ import gherkin.formatter.JSONPrettyFormatter; import org.junit.Test; -import java.util.Collections; import java.util.List; import static cucumber.runtime.TestHelper.feature; @@ -27,7 +26,7 @@ public void runs_feature_with_json_formatter() throws Exception { List backends = asList(mock(Backend.class)); ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); RuntimeOptions runtimeOptions = new RuntimeOptions(); - new Runtime(new ClasspathResourceLoader(classLoader), Collections.emptyList(), classLoader, backends, runtimeOptions).run(feature, jsonFormatter, jsonFormatter); + new Runtime(new ClasspathResourceLoader(classLoader), classLoader, backends, runtimeOptions).run(feature, jsonFormatter, jsonFormatter); jsonFormatter.done(); String expected = "" + "[\n" + diff --git a/java/src/test/java/cucumber/runtime/java/JavaStepDefinitionTest.java b/java/src/test/java/cucumber/runtime/java/JavaStepDefinitionTest.java index 81ffd626dc..f8cdc9db3a 100644 --- a/java/src/test/java/cucumber/runtime/java/JavaStepDefinitionTest.java +++ b/java/src/test/java/cucumber/runtime/java/JavaStepDefinitionTest.java @@ -48,7 +48,7 @@ public class JavaStepDefinitionTest { private final JavaBackend backend = new JavaBackend(new SingletonFactory(defs)); private final ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); private final RuntimeOptions runtimeOptions = new RuntimeOptions(); - private final Runtime runtime = new Runtime(new ClasspathResourceLoader(classLoader), NO_PATHS, classLoader, asList(backend), runtimeOptions); + private final Runtime runtime = new Runtime(new ClasspathResourceLoader(classLoader), classLoader, asList(backend), runtimeOptions); private final Glue glue = runtime.getGlue(); @org.junit.Before diff --git a/junit/src/main/java/cucumber/junit/Cucumber.java b/junit/src/main/java/cucumber/junit/Cucumber.java index a63c67494d..2a766aef17 100644 --- a/junit/src/main/java/cucumber/junit/Cucumber.java +++ b/junit/src/main/java/cucumber/junit/Cucumber.java @@ -55,10 +55,9 @@ public Cucumber(Class clazz) throws InitializationError, IOException { ClassLoader classLoader = clazz.getClassLoader(); resourceLoader = new ClasspathResourceLoader(classLoader); assertNoDeclaredMethods(clazz); - List featurePaths = featurePaths(clazz); - List gluePaths = gluePaths(clazz); + List featurePaths = featurePaths(clazz, getFeatureAnnotation(clazz)); RuntimeOptions runtimeOptions = runtimeOptions(clazz); - runtime = new Runtime(resourceLoader, gluePaths, classLoader, runtimeOptions); + runtime = new Runtime(resourceLoader, classLoader, runtimeOptions); // TODO: Create formatter(s) based on Annotations. Use same technique as in cli.Main for MultiFormatter jUnitReporter = new JUnitReporter(new NullReporter(), new NullReporter()); @@ -102,20 +101,27 @@ private void assertNoDeclaredMethods(Class clazz) { } private RuntimeOptions runtimeOptions(Class clazz) { - Options cucumberOptions = getFeatureAnnotation(clazz); - List args = new ArrayList(); - + Options cucumberOptions = getFeatureAnnotation(clazz); + addGlue(cucumberOptions, clazz, args); + RuntimeOptions runtimeOptions = new RuntimeOptions(args.toArray(new String[args.size()])); return runtimeOptions; } - /** - * @param clazz the Class used to kick it all off - * @return either a path to a single feature, or to a directory or classpath entry containing them - */ - private List featurePaths(Class clazz) { - Options cucumberOptions = getFeatureAnnotation(clazz); + private void addGlue(Options options, Class clazz, List args) { + if(options != null) { + for (String glue : options.glue()) { + args.add("--glue"); + args.add(glue); + } + } else { + args.add("--glue"); + args.add(packagePath(clazz)); + } + } + + private List featurePaths(Class clazz, Options cucumberOptions) { String featurePath; if (cucumberOptions != null) { featurePath = cucumberOptions.value(); @@ -125,21 +131,6 @@ private List featurePaths(Class clazz) { return asList(featurePath); } - private List gluePaths(Class clazz) { - List gluePaths = new ArrayList(); - - gluePaths.add(packagePath(clazz)); - - // Add additional ones - Options cucumberOptions = getFeatureAnnotation(clazz); - if (cucumberOptions != null) { - for (String packageName : cucumberOptions.packages()) { - gluePaths.add(packagePath(packageName)); - } - } - return gluePaths; - } - private List filters(Class clazz) { Options cucumberOptions = getFeatureAnnotation(clazz); Object[] filters = new Object[0]; @@ -196,6 +187,6 @@ private Options getFeatureAnnotation(Class clazz) { /** * @return where to look for glue code (stepdefs and hooks) */ - String[] packages() default {}; + String[] glue() default {}; } } diff --git a/spring/src/main/java/cucumber/runtime/java/spring/hooks/SpringTransactionHooks.java b/spring/src/main/java/cucumber/runtime/java/spring/hooks/SpringTransactionHooks.java index 50bddede33..8f143f4ca1 100644 --- a/spring/src/main/java/cucumber/runtime/java/spring/hooks/SpringTransactionHooks.java +++ b/spring/src/main/java/cucumber/runtime/java/spring/hooks/SpringTransactionHooks.java @@ -13,8 +13,8 @@ * This class defines before and after hooks which provide automatic spring rollback capabilities. * These hooks will apply to any element(s) within a .feature file tagged with @txn. *

- * Clients wishing to leverage these hooks should include this class' package in the packages property of the - * Test class' Feature annotation. + * Clients wishing to leverage these hooks should include this class' package in the glue property of the + * Test class' {@link Cucumber.Options} annotation. *

* The BEFORE and AFTER hooks both rely on being able to obtain a PlatformTransactionManager by type, or * by an optionally specified bean name, from the runtime BeanFactory. From e1da19eaab24fc1c3f2fb18f0d1542fbd9212ccc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aslak=20Helles=C3=B8y?= Date: Mon, 12 Mar 2012 00:00:10 +0000 Subject: [PATCH 06/10] Get featurePaths from runtimeOptions --- .../main/java/cucumber/junit/Cucumber.java | 23 +++++++++---------- .../java/cucumber/junit/CucumberTest.java | 4 ++-- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/junit/src/main/java/cucumber/junit/Cucumber.java b/junit/src/main/java/cucumber/junit/Cucumber.java index 2a766aef17..a5e688d878 100644 --- a/junit/src/main/java/cucumber/junit/Cucumber.java +++ b/junit/src/main/java/cucumber/junit/Cucumber.java @@ -19,6 +19,7 @@ import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import static cucumber.runtime.Utils.packagePath; @@ -55,13 +56,12 @@ public Cucumber(Class clazz) throws InitializationError, IOException { ClassLoader classLoader = clazz.getClassLoader(); resourceLoader = new ClasspathResourceLoader(classLoader); assertNoDeclaredMethods(clazz); - List featurePaths = featurePaths(clazz, getFeatureAnnotation(clazz)); RuntimeOptions runtimeOptions = runtimeOptions(clazz); runtime = new Runtime(resourceLoader, classLoader, runtimeOptions); // TODO: Create formatter(s) based on Annotations. Use same technique as in cli.Main for MultiFormatter jUnitReporter = new JUnitReporter(new NullReporter(), new NullReporter()); - addChildren(featurePaths, filters(clazz)); + addChildren(runtimeOptions.featurePaths, filters(clazz)); } @Override @@ -103,10 +103,11 @@ private void assertNoDeclaredMethods(Class clazz) { private RuntimeOptions runtimeOptions(Class clazz) { List args = new ArrayList(); Options cucumberOptions = getFeatureAnnotation(clazz); + addGlue(cucumberOptions, clazz, args); + addFeaturePaths(cucumberOptions, clazz, args); - RuntimeOptions runtimeOptions = new RuntimeOptions(args.toArray(new String[args.size()])); - return runtimeOptions; + return new RuntimeOptions(args.toArray(new String[args.size()])); } private void addGlue(Options options, Class clazz, List args) { @@ -121,14 +122,12 @@ private void addGlue(Options options, Class clazz, List args) { } } - private List featurePaths(Class clazz, Options cucumberOptions) { - String featurePath; - if (cucumberOptions != null) { - featurePath = cucumberOptions.value(); + private void addFeaturePaths(Options options, Class clazz, List args) { + if(options != null) { + Collections.addAll(args, options.features()); } else { - featurePath = packagePath(clazz); + args.add(packagePath(clazz)); } - return asList(featurePath); } private List filters(Class clazz) { @@ -170,9 +169,9 @@ private Options getFeatureAnnotation(Class clazz) { @Target({ElementType.TYPE}) public static @interface Options { /** - * @return the path to the feature(s) + * @return the paths to the feature(s) */ - String value(); + String[] features(); /** * @return what lines in the feature should be executed diff --git a/junit/src/test/java/cucumber/junit/CucumberTest.java b/junit/src/test/java/cucumber/junit/CucumberTest.java index 4f93072f1a..d42ebb9bde 100644 --- a/junit/src/test/java/cucumber/junit/CucumberTest.java +++ b/junit/src/test/java/cucumber/junit/CucumberTest.java @@ -52,11 +52,11 @@ public void finds_no_features_when_explicit_package_has_nothnig() throws IOExcep private class ImplicitPackage { } - @Cucumber.Options("cucumber/junit") + @Cucumber.Options(features={"cucumber/junit"}) private class ExplicitPackage { } - @Cucumber.Options("gibber/ish") + @Cucumber.Options(features={"gibber/ish"}) private class ExplicitPackageWithNoFeatures { } } From 4baf99f876f35079d7b08b79db4ae6cc9670c3a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aslak=20Helles=C3=B8y?= Date: Mon, 12 Mar 2012 00:27:56 +0000 Subject: [PATCH 07/10] Add dry run --- .../java/cucumber/runtime/RuntimeOptions.java | 17 +++- .../main/java/cucumber/junit/Cucumber.java | 90 +++---------------- .../cucumber/junit/RuntimeOptionsFactory.java | 74 +++++++++++++++ 3 files changed, 104 insertions(+), 77 deletions(-) create mode 100644 junit/src/main/java/cucumber/junit/RuntimeOptionsFactory.java diff --git a/core/src/main/java/cucumber/runtime/RuntimeOptions.java b/core/src/main/java/cucumber/runtime/RuntimeOptions.java index 6fd15db667..31fe239b34 100644 --- a/core/src/main/java/cucumber/runtime/RuntimeOptions.java +++ b/core/src/main/java/cucumber/runtime/RuntimeOptions.java @@ -5,12 +5,16 @@ import com.beust.jcommander.JCommander; import com.beust.jcommander.Parameter; import cucumber.formatter.HTMLFormatter; +import cucumber.io.ResourceLoader; +import cucumber.runtime.model.CucumberFeature; import gherkin.formatter.Formatter; import java.io.File; import java.util.ArrayList; import java.util.List; +import static cucumber.runtime.model.CucumberFeature.load; + public class RuntimeOptions { @Parameter(names = {"-g", "--glue"}, description = "Where cucumber looks for step definitions and hooks.") public List glue = new ArrayList(); @@ -22,7 +26,7 @@ public class RuntimeOptions { public boolean dryRun; @Parameter(names = {"--tags"}, description = "Only execute scenarios matching TAG_EXPRESSION.") - public List tags; + public List tags= new ArrayList(); @Parameter(names = {"--strict"}, description = "Fail if there are any undefined or pending steps.") public boolean strict; @@ -40,6 +44,17 @@ public RuntimeOptions(String... args) { cmd.parse(args); } + public List cucumberFeatures(ResourceLoader resourceLoader) { + return load(resourceLoader, featurePaths, filters()); + } + + private List filters() { + List filters = new ArrayList(); + filters.addAll(tags); + // TODO: Add lines and patterns (names) + return filters; + } + public static class FormatterFactory implements IStringConverterFactory { @Override public Class> getConverter(Class forType) { diff --git a/junit/src/main/java/cucumber/junit/Cucumber.java b/junit/src/main/java/cucumber/junit/Cucumber.java index a5e688d878..7342e3eda0 100644 --- a/junit/src/main/java/cucumber/junit/Cucumber.java +++ b/junit/src/main/java/cucumber/junit/Cucumber.java @@ -14,18 +14,10 @@ import org.junit.runners.model.InitializationError; import java.io.IOException; -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.RetentionPolicy; -import java.lang.annotation.Target; +import java.lang.annotation.*; import java.util.ArrayList; -import java.util.Collections; import java.util.List; -import static cucumber.runtime.Utils.packagePath; -import static cucumber.runtime.model.CucumberFeature.load; -import static java.util.Arrays.asList; - /** * Classes annotated with {@code @RunWith(Cucumber.class)} will run a Cucumber Feature. * The class should be empty without any fields or methods. @@ -38,7 +30,6 @@ * @see Options */ public class Cucumber extends ParentRunner { - private final ResourceLoader resourceLoader; private final JUnitReporter jUnitReporter; private final List children = new ArrayList(); private final Runtime runtime; @@ -54,14 +45,16 @@ public class Cucumber extends ParentRunner { public Cucumber(Class clazz) throws InitializationError, IOException { super(clazz); ClassLoader classLoader = clazz.getClassLoader(); - resourceLoader = new ClasspathResourceLoader(classLoader); + ResourceLoader resourceLoader = new ClasspathResourceLoader(classLoader); assertNoDeclaredMethods(clazz); - RuntimeOptions runtimeOptions = runtimeOptions(clazz); + + RuntimeOptionsFactory runtimeOptionsFactory = new RuntimeOptionsFactory(clazz); + RuntimeOptions runtimeOptions = runtimeOptionsFactory.create(); runtime = new Runtime(resourceLoader, classLoader, runtimeOptions); // TODO: Create formatter(s) based on Annotations. Use same technique as in cli.Main for MultiFormatter jUnitReporter = new JUnitReporter(new NullReporter(), new NullReporter()); - addChildren(runtimeOptions.featurePaths, filters(clazz)); + addChildren(runtimeOptions.cucumberFeatures(resourceLoader)); } @Override @@ -100,67 +93,12 @@ private void assertNoDeclaredMethods(Class clazz) { } } - private RuntimeOptions runtimeOptions(Class clazz) { - List args = new ArrayList(); - Options cucumberOptions = getFeatureAnnotation(clazz); - - addGlue(cucumberOptions, clazz, args); - addFeaturePaths(cucumberOptions, clazz, args); - - return new RuntimeOptions(args.toArray(new String[args.size()])); - } - - private void addGlue(Options options, Class clazz, List args) { - if(options != null) { - for (String glue : options.glue()) { - args.add("--glue"); - args.add(glue); - } - } else { - args.add("--glue"); - args.add(packagePath(clazz)); - } - } - - private void addFeaturePaths(Options options, Class clazz, List args) { - if(options != null) { - Collections.addAll(args, options.features()); - } else { - args.add(packagePath(clazz)); - } - } - - private List filters(Class clazz) { - Options cucumberOptions = getFeatureAnnotation(clazz); - Object[] filters = new Object[0]; - if (cucumberOptions != null) { - filters = toLong(cucumberOptions.lines()); - if (filters.length == 0) { - filters = cucumberOptions.tags(); - } - } - return asList(filters); - } - - private void addChildren(List featurePaths, final List filters) throws InitializationError { - List cucumberFeatures = load(resourceLoader, featurePaths, filters); + private void addChildren(List cucumberFeatures) throws InitializationError { for (CucumberFeature cucumberFeature : cucumberFeatures) { children.add(new FeatureRunner(cucumberFeature, runtime, jUnitReporter)); } } - private Long[] toLong(long[] primitiveLongs) { - Long[] longs = new Long[primitiveLongs.length]; - for (int i = 0; i < primitiveLongs.length; i++) { - longs[i] = primitiveLongs[i]; - } - return longs; - } - - private Options getFeatureAnnotation(Class clazz) { - return (Options) clazz.getAnnotation(Options.class); - } - /** * This annotation can be used to give additional hints to the {@link cucumber.junit.Cucumber} runner * about what to run. It provides similar options to the Cucumber command line used by {@link cucumber.cli.Main} @@ -168,24 +106,24 @@ private Options getFeatureAnnotation(Class clazz) { @Retention(RetentionPolicy.RUNTIME) @Target({ElementType.TYPE}) public static @interface Options { + /** + * @return true if this is a dry run + */ + boolean dryRun() default false; + /** * @return the paths to the feature(s) */ String[] features(); /** - * @return what lines in the feature should be executed + * @return where to look for glue code (stepdefs and hooks) */ - long[] lines() default {}; + String[] glue() default {}; /** * @return what tags in the feature should be executed */ String[] tags() default {}; - - /** - * @return where to look for glue code (stepdefs and hooks) - */ - String[] glue() default {}; } } diff --git a/junit/src/main/java/cucumber/junit/RuntimeOptionsFactory.java b/junit/src/main/java/cucumber/junit/RuntimeOptionsFactory.java new file mode 100644 index 0000000000..868ce0e157 --- /dev/null +++ b/junit/src/main/java/cucumber/junit/RuntimeOptionsFactory.java @@ -0,0 +1,74 @@ +package cucumber.junit; + +import cucumber.runtime.RuntimeOptions; + +import java.lang.annotation.Annotation; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; + +import static cucumber.runtime.Utils.packagePath; + +public class RuntimeOptionsFactory { + private Class clazz; + + public RuntimeOptionsFactory(Class clazz) { + this.clazz = clazz; + } + + public RuntimeOptions create() { + List args = new ArrayList(); + Cucumber.Options cucumberOptions = getFeatureAnnotation(clazz); + + addDryRun(cucumberOptions, args); + addGlue(cucumberOptions, clazz, args); + addFeatures(cucumberOptions, clazz, args); + addTags(cucumberOptions, args); + + return new RuntimeOptions(args.toArray(new String[args.size()])); + + } + + private Cucumber.Options getFeatureAnnotation(Class clazz) { + Annotation annotation = clazz.getAnnotation(Cucumber.Options.class); + return Cucumber.Options.class.cast(annotation); + } + + private void addDryRun(Cucumber.Options options, List args) { + if(options != null) { + if(options.dryRun()) { + args.add("--dry-run"); + } + } + } + + private void addGlue(Cucumber.Options options, Class clazz, List args) { + if(options != null) { + for (String glue : options.glue()) { + args.add("--glue"); + args.add(glue); + } + } else { + args.add("--glue"); + args.add(packagePath(clazz)); + } + } + + private void addFeatures(Cucumber.Options options, Class clazz, List args) { + if(options != null) { + Collections.addAll(args, options.features()); + } else { + args.add(packagePath(clazz)); + } + } + + private void addTags(Cucumber.Options options, List args) { + if(options != null) { + for (String tags : options.tags()) { + args.add("--tags"); + args.add(tags); + } + } + } + +} From abc65aba18bc2086c70f4a87be0261f3e1642ef0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aslak=20Helles=C3=B8y?= Date: Mon, 12 Mar 2012 00:44:52 +0000 Subject: [PATCH 08/10] Ensure sensible defaults for junit --- .../java/cucumber/runtime/RuntimeOptions.java | 4 +- .../main/java/cucumber/junit/Cucumber.java | 2 +- .../cucumber/junit/RuntimeOptionsFactory.java | 4 +- .../java/picocontainer/DatesSteps.java | 2 +- .../test/resources/.cucumber/stepdefs.json | 74 +++++++++++++++++-- .../{cukes.featureX => cukes.feature} | 0 6 files changed, 74 insertions(+), 12 deletions(-) rename picocontainer/src/test/resources/cucumber/runtime/java/picocontainer/{cukes.featureX => cukes.feature} (100%) diff --git a/core/src/main/java/cucumber/runtime/RuntimeOptions.java b/core/src/main/java/cucumber/runtime/RuntimeOptions.java index 31fe239b34..3da8034add 100644 --- a/core/src/main/java/cucumber/runtime/RuntimeOptions.java +++ b/core/src/main/java/cucumber/runtime/RuntimeOptions.java @@ -26,7 +26,7 @@ public class RuntimeOptions { public boolean dryRun; @Parameter(names = {"--tags"}, description = "Only execute scenarios matching TAG_EXPRESSION.") - public List tags= new ArrayList(); + public List tags = new ArrayList(); @Parameter(names = {"--strict"}, description = "Fail if there are any undefined or pending steps.") public boolean strict; @@ -35,7 +35,7 @@ public class RuntimeOptions { public List formatters; @Parameter(description = "Feature paths") - public List featurePaths; + public List featurePaths = new ArrayList(); public RuntimeOptions(String... args) { JCommander cmd = new JCommander(this); diff --git a/junit/src/main/java/cucumber/junit/Cucumber.java b/junit/src/main/java/cucumber/junit/Cucumber.java index 7342e3eda0..f4c620e556 100644 --- a/junit/src/main/java/cucumber/junit/Cucumber.java +++ b/junit/src/main/java/cucumber/junit/Cucumber.java @@ -114,7 +114,7 @@ private void addChildren(List cucumberFeatures) throws Initiali /** * @return the paths to the feature(s) */ - String[] features(); + String[] features() default {}; /** * @return where to look for glue code (stepdefs and hooks) diff --git a/junit/src/main/java/cucumber/junit/RuntimeOptionsFactory.java b/junit/src/main/java/cucumber/junit/RuntimeOptionsFactory.java index 868ce0e157..a2706bc416 100644 --- a/junit/src/main/java/cucumber/junit/RuntimeOptionsFactory.java +++ b/junit/src/main/java/cucumber/junit/RuntimeOptionsFactory.java @@ -43,7 +43,7 @@ private void addDryRun(Cucumber.Options options, List args) { } private void addGlue(Cucumber.Options options, Class clazz, List args) { - if(options != null) { + if(options != null && options.glue().length != 0) { for (String glue : options.glue()) { args.add("--glue"); args.add(glue); @@ -55,7 +55,7 @@ private void addGlue(Cucumber.Options options, Class clazz, List args) { } private void addFeatures(Cucumber.Options options, Class clazz, List args) { - if(options != null) { + if(options != null && options.features().length != 0) { Collections.addAll(args, options.features()); } else { args.add(packagePath(clazz)); diff --git a/picocontainer/src/test/java/cucumber/runtime/java/picocontainer/DatesSteps.java b/picocontainer/src/test/java/cucumber/runtime/java/picocontainer/DatesSteps.java index d8fb452ccb..543c4ada85 100644 --- a/picocontainer/src/test/java/cucumber/runtime/java/picocontainer/DatesSteps.java +++ b/picocontainer/src/test/java/cucumber/runtime/java/picocontainer/DatesSteps.java @@ -24,7 +24,7 @@ public void the_iso_date_is(@DateFormat("yyyy-MM-dd'T'HH:mm:ss") Date date) { this.date = toMidnight(date); } - @Given("^the iso calendar is (\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2})$") + @Given("^the iso calendar is (\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2})$") public void the_iso_calendar_is(@DateFormat("yyyy-MM-dd'T'HH:mm:ss") Calendar cal) { this.date = toMidnight(cal); } diff --git a/picocontainer/src/test/resources/.cucumber/stepdefs.json b/picocontainer/src/test/resources/.cucumber/stepdefs.json index 04cc098a97..1b89ca5498 100644 --- a/picocontainer/src/test/resources/.cucumber/stepdefs.json +++ b/picocontainer/src/test/resources/.cucumber/stepdefs.json @@ -7,17 +7,59 @@ { "source": "^I have (\\d+) (.*) in my belly$", "flags": "", - "steps": [] + "steps": [ + { + "name": "I have 12 cukes in my belly", + "args": [ + { + "offset": 7, + "val": "12" + }, + { + "offset": 10, + "val": "cukes" + } + ] + }, + { + "name": "I have 3 cukes in my belly", + "args": [ + { + "offset": 7, + "val": "3" + }, + { + "offset": 9, + "val": "cukes" + } + ] + } + ] }, { "source": "^I have this in my basket:$", "flags": "", - "steps": [] + "steps": [ + { + "name": "I have this in my basket:", + "args": [] + } + ] }, { "source": "^I should be (.*)$", "flags": "", - "steps": [] + "steps": [ + { + "name": "I should be \u003cmood\u003e", + "args": [ + { + "offset": 12, + "val": "\u003cmood\u003e" + } + ] + } + ] }, { "source": "^the (.*) contains (.*)", @@ -45,9 +87,19 @@ ] }, { - "source": "^the iso calendar is (\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2})$", + "source": "^the iso calendar is (\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2})$", "flags": "", - "steps": [] + "steps": [ + { + "name": "the iso calendar is 2012-03-01T06:54:14", + "args": [ + { + "offset": 20, + "val": "2012-03-01T06:54:14" + } + ] + } + ] }, { "source": "^the iso date is (.+)$", @@ -57,6 +109,16 @@ { "source": "^there are (\\d+) cukes in my belly", "flags": "", - "steps": [] + "steps": [ + { + "name": "there are 3 cukes in my belly", + "args": [ + { + "offset": 10, + "val": "3" + } + ] + } + ] } ] \ No newline at end of file diff --git a/picocontainer/src/test/resources/cucumber/runtime/java/picocontainer/cukes.featureX b/picocontainer/src/test/resources/cucumber/runtime/java/picocontainer/cukes.feature similarity index 100% rename from picocontainer/src/test/resources/cucumber/runtime/java/picocontainer/cukes.featureX rename to picocontainer/src/test/resources/cucumber/runtime/java/picocontainer/cukes.feature From db8c4fbe2ddac729c48a1b9637c0a5d509333b48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aslak=20Helles=C3=B8y?= Date: Wed, 14 Mar 2012 22:41:19 +0000 Subject: [PATCH 09/10] Mostly finished CLI refactoring --- core/src/main/java/cucumber/DateFormat.java | 2 +- core/src/main/java/cucumber/cli/Main.java | 90 +------------ .../formatter/CucumberPrettyFormatter.java | 9 ++ .../formatter/FormatterConverter.java | 126 ++++++++++++++++++ .../cucumber/formatter/FormatterFactory.java | 66 --------- .../cucumber/formatter/HTMLFormatter.java | 20 +-- .../cucumber/formatter/JUnitFormatter.java | 9 +- .../cucumber/formatter/MultiFormatter.java | 52 -------- .../java/cucumber/formatter/NullReporter.java | 77 ----------- .../cucumber/formatter/ProgressFormatter.java | 13 +- .../java/cucumber/runtime/FeatureBuilder.java | 7 +- .../main/java/cucumber/runtime/Runtime.java | 71 ++++------ .../java/cucumber/runtime/RuntimeGlue.java | 24 ++-- .../java/cucumber/runtime/RuntimeOptions.java | 50 +++++-- .../autocomplete/StepdefGenerator.java | 6 +- .../runtime/converters/LocalizedXStreams.java | 6 +- .../runtime/converters/TimeConverter.java | 7 +- .../runtime/model/CucumberFeature.java | 22 ++- .../model/CucumberScenarioOutline.java | 10 +- .../java/cucumber/table/TableConverter.java | 7 +- .../formatter/FormatterConverterTest.java | 38 ++++++ .../formatter/FormatterFactoryTest.java | 67 ---------- .../cucumber/formatter/HTMLFormatterTest.java | 41 +----- .../formatter/JUnitFormatterTest.java | 48 +++---- .../test/java/cucumber/formatter/TempDir.java | 26 ++++ .../cucumber/formatter/TestFormatter.java | 7 +- .../java/cucumber/runtime/BackgroundTest.java | 2 +- .../java/cucumber/runtime/HookOrderTest.java | 5 +- .../test/java/cucumber/runtime/HookTest.java | 4 +- .../java/cucumber/runtime/RuntimeTest.java | 3 +- .../runtime/StepDefinitionMatchTest.java | 4 +- .../test/java/cucumber/runtime/UtilsTest.java | 8 +- .../runtime/model/CucumberExamplesTest.java | 8 +- .../model/CucumberScenarioOutlineTest.java | 6 +- .../cucumber/table/FromDataTableTest.java | 7 +- .../runtime/java/guice/GuiceFactoryTest.java | 4 +- .../runtime/java/JavaStepDefinition.java | 6 +- .../java/ClasspathMethodScannerTest.java | 4 +- .../cucumber/runtime/java/JavaHookTest.java | 4 +- .../runtime/java/JavaStepDefinitionTest.java | 4 +- .../cucumber/runtime/jruby/JRubyBackend.java | 12 +- .../main/java/cucumber/junit/Cucumber.java | 8 +- .../java/cucumber/junit/JUnitReporter.java | 8 +- .../cucumber/junit/JUnitReporterTest.java | 4 +- .../java/openejb/OpenEJBObjectFactory.java | 7 +- .../java/spring/SpringFactoryTest.java | 6 +- .../hooks/SpringTransactionHooksTest.java | 4 +- .../src/test/resources/applicationContext.xml | 3 +- 48 files changed, 370 insertions(+), 652 deletions(-) create mode 100644 core/src/main/java/cucumber/formatter/CucumberPrettyFormatter.java create mode 100644 core/src/main/java/cucumber/formatter/FormatterConverter.java delete mode 100644 core/src/main/java/cucumber/formatter/FormatterFactory.java delete mode 100644 core/src/main/java/cucumber/formatter/MultiFormatter.java delete mode 100644 core/src/main/java/cucumber/formatter/NullReporter.java create mode 100644 core/src/test/java/cucumber/formatter/FormatterConverterTest.java delete mode 100644 core/src/test/java/cucumber/formatter/FormatterFactoryTest.java create mode 100644 core/src/test/java/cucumber/formatter/TempDir.java diff --git a/core/src/main/java/cucumber/DateFormat.java b/core/src/main/java/cucumber/DateFormat.java index cba6af376b..ae43c95e53 100644 --- a/core/src/main/java/cucumber/DateFormat.java +++ b/core/src/main/java/cucumber/DateFormat.java @@ -29,7 +29,7 @@ *
  * @Given("^the date is (\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2})$")
  * public void the_date_is(@DateFormat("yyyy-MM-dd'T'HH:mm:ss") Calendar cal) {
- *     this.date = date;
+ *     this.cal = cal;
  * }
  * 
*

diff --git a/core/src/main/java/cucumber/cli/Main.java b/core/src/main/java/cucumber/cli/Main.java index ecc0bb42ee..bdcd22bca0 100644 --- a/core/src/main/java/cucumber/cli/Main.java +++ b/core/src/main/java/cucumber/cli/Main.java @@ -1,25 +1,13 @@ package cucumber.cli; -import cucumber.formatter.FormatterFactory; -import cucumber.formatter.MultiFormatter; import cucumber.io.FileResourceLoader; import cucumber.runtime.Runtime; import cucumber.runtime.RuntimeOptions; -import cucumber.runtime.snippets.SummaryPrinter; -import gherkin.formatter.Formatter; -import gherkin.formatter.Reporter; -import java.io.File; import java.io.IOException; -import java.util.ArrayList; -import java.util.List; import java.util.ResourceBundle; -import java.util.Stack; - -import static java.util.Arrays.asList; public class Main { - private static final String USAGE = "TODO - Write the help"; static final String VERSION = ResourceBundle.getBundle("cucumber.version").getString("cucumber-jvm.version"); public static void main(String[] argv) throws Throwable { @@ -28,84 +16,10 @@ public static void main(String[] argv) throws Throwable { public static void run(String[] argv, ClassLoader classLoader) throws IOException { RuntimeOptions runtimeOptions = new RuntimeOptions(argv); - - List featurePaths = new ArrayList(); - List gluePaths = new ArrayList(); - List filters = new ArrayList(); - Stack format = new Stack(); - List args = new ArrayList(asList(argv)); - String dotCucumber = null; - boolean isDryRun = false; - - FormatterFactory formatterFactory = new FormatterFactory(classLoader); - MultiFormatter multiFormatter = new MultiFormatter(classLoader); - - while (!args.isEmpty()) { - String arg = args.remove(0); - - if (arg.equals("--help") || arg.equals("-h")) { - System.out.println(USAGE); - System.exit(0); - } else if (arg.equals("--version") || arg.equals("-v")) { - System.out.println(VERSION); - System.exit(0); - } else if (arg.equals("--glue") || arg.equals("-g")) { - String gluePath = args.remove(0); - gluePaths.add(gluePath); - } else if (arg.equals("--tags") || arg.equals("-t")) { - filters.add(args.remove(0)); - } else if (arg.equals("--format") || arg.equals("-f")) { - format.push(args.remove(0)); - } else if (arg.equals("--out") || arg.equals("-o")) { - File out = new File(args.remove(0)); - Formatter formatter = formatterFactory.createFormatter(format.pop(), out); - multiFormatter.add(formatter); - } else if (arg.equals("--dotcucumber")) { - dotCucumber = args.remove(0); - } else if (arg.equals("--dry-run") || arg.equals("-d")) { - isDryRun = true; - } else { - // TODO: Use PathWithLines and add line filter if any - featurePaths.add(arg); - } - } - - //Grab any formatters left on the stack and create a multiformatter for them to stdout - // yes this will be ugly, but maybe people are crazy - if (!format.isEmpty()) { - multiFormatter.add(formatterFactory.createFormatter(format.pop(), System.out)); - } else { - //Default formatter is progress unless otherwise specified or if they have piped all their other formatters - // to an output thing - multiFormatter.add(formatterFactory.createFormatter("progress", System.out)); - } - - if (gluePaths.isEmpty()) { - System.out.println("Missing option: --glue"); - System.exit(1); - } Runtime runtime = new Runtime(new FileResourceLoader(), classLoader, runtimeOptions); - - if (dotCucumber != null) { - writeDotCucumber(featurePaths, dotCucumber, runtime); - } - Formatter formatter = multiFormatter.formatterProxy(); - Reporter reporter = multiFormatter.reporterProxy(); - runtime.run(featurePaths, filters, formatter, reporter); - formatter.done(); - printSummary(runtime); - formatter.close(); + runtime.writeStepdefsJson(); + runtime.run(); System.exit(runtime.exitStatus()); } - - private static void writeDotCucumber(List featurePaths, String dotCucumberPath, Runtime runtime) throws IOException { - File dotCucumber = new File(dotCucumberPath); - dotCucumber.mkdirs(); - runtime.writeStepdefsJson(featurePaths, dotCucumber); - } - - private static void printSummary(Runtime runtime) { - new SummaryPrinter(System.out).print(runtime); - } } diff --git a/core/src/main/java/cucumber/formatter/CucumberPrettyFormatter.java b/core/src/main/java/cucumber/formatter/CucumberPrettyFormatter.java new file mode 100644 index 0000000000..3278d487f2 --- /dev/null +++ b/core/src/main/java/cucumber/formatter/CucumberPrettyFormatter.java @@ -0,0 +1,9 @@ +package cucumber.formatter; + +import gherkin.formatter.PrettyFormatter; + +public class CucumberPrettyFormatter extends PrettyFormatter { + public CucumberPrettyFormatter(Appendable out) { + super(out, true, true); + } +} diff --git a/core/src/main/java/cucumber/formatter/FormatterConverter.java b/core/src/main/java/cucumber/formatter/FormatterConverter.java new file mode 100644 index 0000000000..6c92550c75 --- /dev/null +++ b/core/src/main/java/cucumber/formatter/FormatterConverter.java @@ -0,0 +1,126 @@ +package cucumber.formatter; + +import com.beust.jcommander.IStringConverter; +import cucumber.runtime.CucumberException; +import gherkin.formatter.Formatter; +import gherkin.formatter.JSONFormatter; +import gherkin.formatter.JSONPrettyFormatter; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.lang.reflect.Constructor; +import java.lang.reflect.InvocationTargetException; +import java.util.HashMap; +import java.util.Map; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import static java.util.Arrays.asList; + +public class FormatterConverter implements IStringConverter { + private Class[] CTOR_ARGS = new Class[]{Appendable.class, File.class}; + + private static final Map> FORMATTER_CLASSES = new HashMap>() {{ + put("junit", JUnitFormatter.class); + put("html", HTMLFormatter.class); + put("pretty", CucumberPrettyFormatter.class); + put("progress", ProgressFormatter.class); + put("json", JSONFormatter.class); + put("json-pretty", JSONPrettyFormatter.class); + }}; + private static final Pattern FORMATTER_WITH_FILE_PATTERN = Pattern.compile("([^:]+):(.*)"); + private Appendable defaultOut = System.out; + + @Override + public Formatter convert(String formatterString) { + Matcher formatterWithFile = FORMATTER_WITH_FILE_PATTERN.matcher(formatterString); + String formatterName; + Object ctorArg; + if(formatterWithFile.matches()) { + formatterName = formatterWithFile.group(1); + ctorArg = new File(formatterWithFile.group(2)); + } else { + formatterName = formatterString; + ctorArg = defaultOutIfAvailable(); + } + Class formatterClass = formatterClass(formatterName); + try { + return instantiate(formatterClass, ctorArg); + } catch (IOException e) { + throw new CucumberException(e); + } + } + + private Formatter instantiate(Class formatterClass, Object ctorArg) throws IOException { + Constructor constructor; + + for (Class ctorArgClass : CTOR_ARGS) { + constructor=findConstructor(formatterClass, ctorArgClass); + if(constructor != null) { + ctorArg = convert(ctorArg, ctorArgClass); + if(ctorArg != null) { + try { + return constructor.newInstance(ctorArg); + } catch (InstantiationException e) { + throw new CucumberException(e); + } catch (IllegalAccessException e) { + throw new CucumberException(e); + } catch (InvocationTargetException e) { + throw new CucumberException(e.getTargetException()); + } + } + } + } + throw new CucumberException(String.format("%s must have a single-argument constructor that takes one of the following: %s", formatterClass, asList(CTOR_ARGS))); + } + + private Object convert(Object ctorArg, Class ctorArgClass) throws IOException { + if(ctorArgClass.isAssignableFrom(ctorArg.getClass())) { + return ctorArg; + } + if(ctorArgClass.equals(File.class) && ctorArg instanceof File) { + return ctorArg; + } + if(ctorArgClass.equals(Appendable.class) && ctorArg instanceof File) { + return new FileWriter((File) ctorArg); + } + return null; + } + + private Constructor findConstructor(Class formatterClass, Class ctorArgClass) { + try { + return formatterClass.getConstructor(ctorArgClass); + } catch (NoSuchMethodException e) { + return null; + } + } + + private Class formatterClass(String formatterName) { + Class formatterClass = FORMATTER_CLASSES.get(formatterName); + if(formatterClass == null) { + formatterClass = loadClass(formatterName); + } + return formatterClass; + } + + private Class loadClass(String className) { + try { + return (Class) Thread.currentThread().getContextClassLoader().loadClass(className); + } catch (ClassNotFoundException e) { + throw new CucumberException("Couldn't load formatter class: " + className, e); + } + } + + private Appendable defaultOutIfAvailable() { + try { + if(defaultOut != null) { + return defaultOut; + } else { + throw new CucumberException("Only one formatter can use STDOUT. If you use more than one formatter you must specify output path with FORMAT:PATH"); + } + } finally { + defaultOut = null; + } + } +} diff --git a/core/src/main/java/cucumber/formatter/FormatterFactory.java b/core/src/main/java/cucumber/formatter/FormatterFactory.java deleted file mode 100644 index 8727715fd4..0000000000 --- a/core/src/main/java/cucumber/formatter/FormatterFactory.java +++ /dev/null @@ -1,66 +0,0 @@ -package cucumber.formatter; - -import cucumber.runtime.CucumberException; -import gherkin.formatter.Formatter; -import gherkin.formatter.JSONFormatter; -import gherkin.formatter.JSONPrettyFormatter; -import gherkin.formatter.PrettyFormatter; - -import java.io.File; -import java.util.HashMap; -import java.util.Map; - -public class FormatterFactory { - - private final ClassLoader classLoader; - - private static final Map BUILTIN_FORMATTERS = new HashMap() {{ - put("progress", ProgressFormatter.class.getName()); - put("html", HTMLFormatter.class.getName()); - put("json", JSONFormatter.class.getName()); - put("json-pretty", JSONPrettyFormatter.class.getName()); - put("pretty", PrettyFormatter.class.getName()); - put("junit", JUnitFormatter.class.getName()); - }}; - - public FormatterFactory(ClassLoader classLoader) { - this.classLoader = classLoader; - } - - public Formatter createFormatter(String formatterName, Object out) { - String className = BUILTIN_FORMATTERS.containsKey(formatterName) ? BUILTIN_FORMATTERS.get(formatterName) : formatterName; - return createFormatterFromClassName(className, out); - } - - private Formatter createFormatterFromClassName(String className, Object out) { - try { - Class ctorArgClass = Appendable.class; - if (out instanceof File) { - File file = (File) out; - out = file; - ctorArgClass = File.class; - } - - Class formatterClass = getFormatterClass(className); - // TODO: Remove these if statements. We should fix PrettyFormatter and ProgressFormatter to only take a single Appendable arg. - // Whether or not to use Monochrome is tricky. Maybe always enforce another 2nd argument for that - if (PrettyFormatter.class.isAssignableFrom(formatterClass)) { - return formatterClass.getConstructor(ctorArgClass, Boolean.TYPE, Boolean.TYPE).newInstance(out, false, true); - } else if (ProgressFormatter.class.isAssignableFrom(formatterClass)) { - return formatterClass.getConstructor(ctorArgClass, Boolean.TYPE).newInstance(out, false); - } else { - return formatterClass.getConstructor(ctorArgClass).newInstance(out); - } - } catch (Exception e) { - throw new CucumberException(String.format("Error creating instance of: %s outputting to %s", className, out), e); - } - } - - private Class getFormatterClass(String className) { - try { - return (Class) classLoader.loadClass(className); - } catch (ClassNotFoundException e) { - throw new CucumberException("Formatter class not found: " + className, e); - } - } -} diff --git a/core/src/main/java/cucumber/formatter/HTMLFormatter.java b/core/src/main/java/cucumber/formatter/HTMLFormatter.java index 878bb46626..586be3166d 100644 --- a/core/src/main/java/cucumber/formatter/HTMLFormatter.java +++ b/core/src/main/java/cucumber/formatter/HTMLFormatter.java @@ -7,23 +7,9 @@ import gherkin.formatter.Mappable; import gherkin.formatter.NiceAppendable; import gherkin.formatter.Reporter; -import gherkin.formatter.model.Background; -import gherkin.formatter.model.Examples; -import gherkin.formatter.model.Feature; -import gherkin.formatter.model.Match; -import gherkin.formatter.model.Result; -import gherkin.formatter.model.Scenario; -import gherkin.formatter.model.ScenarioOutline; -import gherkin.formatter.model.Step; - -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.io.OutputStreamWriter; -import java.io.UnsupportedEncodingException; +import gherkin.formatter.model.*; + +import java.io.*; import java.util.HashMap; import java.util.List; import java.util.Map; diff --git a/core/src/main/java/cucumber/formatter/JUnitFormatter.java b/core/src/main/java/cucumber/formatter/JUnitFormatter.java index c0ad0248e8..d650448c6e 100644 --- a/core/src/main/java/cucumber/formatter/JUnitFormatter.java +++ b/core/src/main/java/cucumber/formatter/JUnitFormatter.java @@ -3,14 +3,7 @@ import cucumber.runtime.CucumberException; import gherkin.formatter.Formatter; import gherkin.formatter.Reporter; -import gherkin.formatter.model.Background; -import gherkin.formatter.model.Examples; -import gherkin.formatter.model.Feature; -import gherkin.formatter.model.Match; -import gherkin.formatter.model.Result; -import gherkin.formatter.model.Scenario; -import gherkin.formatter.model.ScenarioOutline; -import gherkin.formatter.model.Step; +import gherkin.formatter.model.*; import org.w3c.dom.Document; import org.w3c.dom.Element; diff --git a/core/src/main/java/cucumber/formatter/MultiFormatter.java b/core/src/main/java/cucumber/formatter/MultiFormatter.java deleted file mode 100644 index e5bd8b5804..0000000000 --- a/core/src/main/java/cucumber/formatter/MultiFormatter.java +++ /dev/null @@ -1,52 +0,0 @@ -package cucumber.formatter; - -import gherkin.formatter.Formatter; -import gherkin.formatter.Reporter; - -import java.lang.reflect.InvocationHandler; -import java.lang.reflect.Method; -import java.lang.reflect.Proxy; -import java.util.ArrayList; -import java.util.List; - -/** - * Utility for creating a formatter that delegates to multiple underlying formatters. - */ -public class MultiFormatter { - private final List formatters = new ArrayList(); - private final ClassLoader classLoader; - - public MultiFormatter(ClassLoader classLoader) { - this.classLoader = classLoader; - } - - public void add(Formatter formatter) { - formatters.add(formatter); - } - - public Formatter formatterProxy() { - return (Formatter) Proxy.newProxyInstance(classLoader, new Class[]{Formatter.class}, new InvocationHandler() { - @Override - public Object invoke(Object target, Method method, Object[] args) throws Throwable { - for (Formatter formatter : formatters) { - method.invoke(formatter, args); - } - return null; - } - }); - } - - public Reporter reporterProxy() { - return (Reporter) Proxy.newProxyInstance(classLoader, new Class[]{Reporter.class}, new InvocationHandler() { - @Override - public Object invoke(Object target, Method method, Object[] args) throws Throwable { - for (Formatter formatter : formatters) { - if (formatter instanceof Reporter) { - method.invoke(formatter, args); - } - } - return null; - } - }); - } -} diff --git a/core/src/main/java/cucumber/formatter/NullReporter.java b/core/src/main/java/cucumber/formatter/NullReporter.java deleted file mode 100644 index aaa7523146..0000000000 --- a/core/src/main/java/cucumber/formatter/NullReporter.java +++ /dev/null @@ -1,77 +0,0 @@ -package cucumber.formatter; - -import gherkin.formatter.Formatter; -import gherkin.formatter.Reporter; -import gherkin.formatter.model.Background; -import gherkin.formatter.model.Examples; -import gherkin.formatter.model.Feature; -import gherkin.formatter.model.Match; -import gherkin.formatter.model.Result; -import gherkin.formatter.model.Scenario; -import gherkin.formatter.model.ScenarioOutline; -import gherkin.formatter.model.Step; - -import java.io.InputStream; -import java.util.List; - -public class NullReporter implements Reporter, Formatter { - @Override - public void uri(String s) { - } - - @Override - public void feature(Feature feature) { - } - - @Override - public void background(Background background) { - } - - @Override - public void scenario(Scenario scenario) { - } - - @Override - public void scenarioOutline(ScenarioOutline scenarioOutline) { - } - - @Override - public void examples(Examples examples) { - } - - @Override - public void step(Step step) { - } - - @Override - public void eof() { - } - - @Override - public void syntaxError(String state, String event, List legalEvents, String uri, int line) { - } - - @Override - public void done() { - } - - @Override - public void close() { - } - - @Override - public void result(Result result) { - } - - @Override - public void match(Match match) { - } - - @Override - public void embedding(String mimeType, InputStream data) { - } - - @Override - public void write(String text) { - } -} diff --git a/core/src/main/java/cucumber/formatter/ProgressFormatter.java b/core/src/main/java/cucumber/formatter/ProgressFormatter.java index 4e61a1d3b7..c131629e7c 100644 --- a/core/src/main/java/cucumber/formatter/ProgressFormatter.java +++ b/core/src/main/java/cucumber/formatter/ProgressFormatter.java @@ -4,14 +4,7 @@ import gherkin.formatter.NiceAppendable; import gherkin.formatter.Reporter; import gherkin.formatter.ansi.AnsiEscapes; -import gherkin.formatter.model.Background; -import gherkin.formatter.model.Examples; -import gherkin.formatter.model.Feature; -import gherkin.formatter.model.Match; -import gherkin.formatter.model.Result; -import gherkin.formatter.model.Scenario; -import gherkin.formatter.model.ScenarioOutline; -import gherkin.formatter.model.Step; +import gherkin.formatter.model.*; import java.io.InputStream; import java.util.HashMap; @@ -37,8 +30,8 @@ public class ProgressFormatter implements Formatter, Reporter { private final NiceAppendable out; private final boolean monochrome; - public ProgressFormatter(Appendable appendable, boolean monochrome) { - this.monochrome = monochrome; + public ProgressFormatter(Appendable appendable) { + this.monochrome = false; out = new NiceAppendable(appendable); } diff --git a/core/src/main/java/cucumber/runtime/FeatureBuilder.java b/core/src/main/java/cucumber/runtime/FeatureBuilder.java index 9770f7cd54..4890f17ec1 100644 --- a/core/src/main/java/cucumber/runtime/FeatureBuilder.java +++ b/core/src/main/java/cucumber/runtime/FeatureBuilder.java @@ -5,12 +5,7 @@ import gherkin.I18n; import gherkin.formatter.FilterFormatter; import gherkin.formatter.Formatter; -import gherkin.formatter.model.Background; -import gherkin.formatter.model.Examples; -import gherkin.formatter.model.Feature; -import gherkin.formatter.model.Scenario; -import gherkin.formatter.model.ScenarioOutline; -import gherkin.formatter.model.Step; +import gherkin.formatter.model.*; import gherkin.parser.Parser; import gherkin.util.FixJava; diff --git a/core/src/main/java/cucumber/runtime/Runtime.java b/core/src/main/java/cucumber/runtime/Runtime.java index e14b31212b..007e48001b 100644 --- a/core/src/main/java/cucumber/runtime/Runtime.java +++ b/core/src/main/java/cucumber/runtime/Runtime.java @@ -4,27 +4,14 @@ import cucumber.io.ResourceLoader; import cucumber.runtime.converters.LocalizedXStreams; import cucumber.runtime.model.CucumberFeature; -import cucumber.runtime.model.CucumberTagStatement; +import cucumber.runtime.snippets.SummaryPrinter; import gherkin.I18n; import gherkin.formatter.Formatter; import gherkin.formatter.Reporter; -import gherkin.formatter.model.Comment; -import gherkin.formatter.model.DataTableRow; -import gherkin.formatter.model.DocString; -import gherkin.formatter.model.Match; -import gherkin.formatter.model.Result; -import gherkin.formatter.model.Step; -import gherkin.formatter.model.Tag; - -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; -import java.util.Set; +import gherkin.formatter.model.*; -import static cucumber.runtime.model.CucumberFeature.load; +import java.io.IOException; +import java.util.*; /** * This is the main entry point for running Cucumber features. @@ -35,7 +22,9 @@ public class Runtime implements UnreportedStepExecutor { private static final byte ERRORS = 0x1; private final UndefinedStepsTracker undefinedStepsTracker = new UndefinedStepsTracker(); + private final Glue glue; + private final RuntimeOptions runtimeOptions; private final List errors = new ArrayList(); private final Collection backends; @@ -45,18 +34,19 @@ public class Runtime implements UnreportedStepExecutor { //They really should be created each time a scenario is run, not in here private boolean skipNextStep = false; private ScenarioResultImpl scenarioResult = null; - private final RuntimeOptions runtimeOptions; + private ClassLoader classLoader; public Runtime(ResourceLoader resourceLoader, ClassLoader classLoader, RuntimeOptions runtimeOptions) { this(resourceLoader, classLoader, loadBackends(resourceLoader, classLoader), runtimeOptions); } public Runtime(ResourceLoader resourceLoader, ClassLoader classLoader, Collection backends, RuntimeOptions runtimeOptions) { + this.resourceLoader = resourceLoader; + this.classLoader = classLoader; if (backends.isEmpty()) { throw new CucumberException("No backends were found. Please make sure you have a backend module on your CLASSPATH."); } this.backends = backends; - this.resourceLoader = resourceLoader; glue = new RuntimeGlue(undefinedStepsTracker, new LocalizedXStreams(classLoader)); for (Backend backend : backends) { @@ -77,32 +67,27 @@ public void addError(Throwable error) { /** * This is the main entry point. Used from CLI, but not from JUnit. * - * @param featurePaths - * @param filters - * @param formatter - * @param reporter */ - public void run(List featurePaths, final List filters, Formatter formatter, Reporter reporter) { - for (CucumberFeature cucumberFeature : load(resourceLoader, featurePaths, filters)) { - run(cucumberFeature, formatter, reporter); + public void run() { + for (CucumberFeature cucumberFeature : runtimeOptions.cucumberFeatures(resourceLoader)) { + run(cucumberFeature); } + Formatter formatter = runtimeOptions.formatter(classLoader); + + formatter.done(); + printSummary(); + formatter.close(); } - /** - * Runs an individual feature, not all the features. Used from CLI, but not from JUnit. - * - * @param cucumberFeature - * @param formatter - * @param reporter - */ - public void run(CucumberFeature cucumberFeature, Formatter formatter, Reporter reporter) { - formatter.uri(cucumberFeature.getUri()); - formatter.feature(cucumberFeature.getFeature()); - for (CucumberTagStatement cucumberTagStatement : cucumberFeature.getFeatureElements()) { - //Run the scenario, it should handle before and after hooks - cucumberTagStatement.run(formatter, reporter, this); - } - formatter.eof(); + private void run(CucumberFeature cucumberFeature) { + Formatter formatter = runtimeOptions.formatter(classLoader); + Reporter reporter = runtimeOptions.reporter(classLoader); + cucumberFeature.run(formatter, reporter, this); + } + + private void printSummary() { + // TODO: inject a SummaryPrinter in the ctor + new SummaryPrinter(System.out).print(this); } public void buildBackendWorlds(Reporter reporter) { @@ -241,7 +226,7 @@ public void runStep(String uri, Step step, Reporter reporter, I18n i18n) { } } - public void writeStepdefsJson(List featurePaths, File dotCucumber) throws IOException { - glue.writeStepdefsJson(featurePaths, dotCucumber); + public void writeStepdefsJson() throws IOException { + glue.writeStepdefsJson(runtimeOptions.featurePaths, runtimeOptions.dotCucumber); } } diff --git a/core/src/main/java/cucumber/runtime/RuntimeGlue.java b/core/src/main/java/cucumber/runtime/RuntimeGlue.java index 39d2eb2a4b..4a1ba7fdd8 100644 --- a/core/src/main/java/cucumber/runtime/RuntimeGlue.java +++ b/core/src/main/java/cucumber/runtime/RuntimeGlue.java @@ -14,11 +14,7 @@ import java.io.File; import java.io.FileWriter; import java.io.IOException; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.TreeMap; +import java.util.*; import static cucumber.runtime.model.CucumberFeature.load; import static java.util.Collections.emptyList; @@ -100,13 +96,15 @@ private List stepDefinitionMatches(String uri, Step step) { @Override public void writeStepdefsJson(List featurePaths, File dotCucumber) throws IOException { - List features = load(new FileResourceLoader(), featurePaths, NO_FILTERS); - List metaStepdefs = new StepdefGenerator().generate(stepDefinitionsByPattern.values(), features); - Gson gson = new GsonBuilder().setPrettyPrinting().create(); - String json = gson.toJson(metaStepdefs); - - FileWriter stepdefsJson = new FileWriter(new File(dotCucumber, "stepdefs.json")); - stepdefsJson.append(json); - stepdefsJson.close(); + if(dotCucumber != null) { + List features = load(new FileResourceLoader(), featurePaths, NO_FILTERS); + List metaStepdefs = new StepdefGenerator().generate(stepDefinitionsByPattern.values(), features); + Gson gson = new GsonBuilder().setPrettyPrinting().create(); + String json = gson.toJson(metaStepdefs); + + FileWriter stepdefsJson = new FileWriter(new File(dotCucumber, "stepdefs.json")); + stepdefsJson.append(json); + stepdefsJson.close(); + } } } diff --git a/core/src/main/java/cucumber/runtime/RuntimeOptions.java b/core/src/main/java/cucumber/runtime/RuntimeOptions.java index 3da8034add..da6b3d7939 100644 --- a/core/src/main/java/cucumber/runtime/RuntimeOptions.java +++ b/core/src/main/java/cucumber/runtime/RuntimeOptions.java @@ -4,16 +4,22 @@ import com.beust.jcommander.IStringConverterFactory; import com.beust.jcommander.JCommander; import com.beust.jcommander.Parameter; -import cucumber.formatter.HTMLFormatter; +import cucumber.formatter.FormatterConverter; +import cucumber.formatter.ProgressFormatter; import cucumber.io.ResourceLoader; import cucumber.runtime.model.CucumberFeature; import gherkin.formatter.Formatter; +import gherkin.formatter.Reporter; import java.io.File; +import java.lang.reflect.InvocationHandler; +import java.lang.reflect.Method; +import java.lang.reflect.Proxy; import java.util.ArrayList; import java.util.List; import static cucumber.runtime.model.CucumberFeature.load; +import static java.util.Arrays.asList; public class RuntimeOptions { @Parameter(names = {"-g", "--glue"}, description = "Where cucumber looks for step definitions and hooks.") @@ -32,7 +38,7 @@ public class RuntimeOptions { public boolean strict; @Parameter(names = {"--format"}, description = "Formatter to use.") - public List formatters; + public List formatters = new ArrayList(); @Parameter(description = "Feature paths") public List featurePaths = new ArrayList(); @@ -42,12 +48,42 @@ public RuntimeOptions(String... args) { cmd.addConverterFactory(new FormatterFactory()); cmd.setProgramName("cucumber"); cmd.parse(args); + + if(formatters.isEmpty()) { + formatters.add(new ProgressFormatter(System.out)); + } } public List cucumberFeatures(ResourceLoader resourceLoader) { return load(resourceLoader, featurePaths, filters()); } + public Formatter formatter(ClassLoader classLoader) { + return (Formatter) Proxy.newProxyInstance(classLoader, new Class[]{Formatter.class}, new InvocationHandler() { + @Override + public Object invoke(Object target, Method method, Object[] args) throws Throwable { + for (Formatter formatter : formatters) { + method.invoke(formatter, args); + } + return null; + } + }); + } + + public Reporter reporter(ClassLoader classLoader) { + return (Reporter) Proxy.newProxyInstance(classLoader, new Class[]{Reporter.class}, new InvocationHandler() { + @Override + public Object invoke(Object target, Method method, Object[] args) throws Throwable { + for (Formatter formatter : formatters) { + if (formatter instanceof Reporter) { + method.invoke(formatter, args); + } + } + return null; + } + }); + } + private List filters() { List filters = new ArrayList(); filters.addAll(tags); @@ -58,15 +94,11 @@ private List filters() { public static class FormatterFactory implements IStringConverterFactory { @Override public Class> getConverter(Class forType) { - if (forType.equals(Formatter.class)) return FormatterConverter.class; + if (forType.equals(Formatter.class)) { + return FormatterConverter.class; + } else return null; } } - public static class FormatterConverter implements IStringConverter { - @Override - public Formatter convert(String value) { - return new HTMLFormatter(new File("target")); - } - } } diff --git a/core/src/main/java/cucumber/runtime/autocomplete/StepdefGenerator.java b/core/src/main/java/cucumber/runtime/autocomplete/StepdefGenerator.java index b64adeac57..25c2a7df8f 100644 --- a/core/src/main/java/cucumber/runtime/autocomplete/StepdefGenerator.java +++ b/core/src/main/java/cucumber/runtime/autocomplete/StepdefGenerator.java @@ -6,11 +6,7 @@ import gherkin.formatter.Argument; import gherkin.formatter.model.Step; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.Comparator; -import java.util.List; +import java.util.*; /** * Generates metadata to be used for Code Completion: https://github.com/cucumber/gherkin/wiki/Code-Completion diff --git a/core/src/main/java/cucumber/runtime/converters/LocalizedXStreams.java b/core/src/main/java/cucumber/runtime/converters/LocalizedXStreams.java index a9090aa650..798a5c9532 100644 --- a/core/src/main/java/cucumber/runtime/converters/LocalizedXStreams.java +++ b/core/src/main/java/cucumber/runtime/converters/LocalizedXStreams.java @@ -5,11 +5,7 @@ import com.thoughtworks.xstream.core.DefaultConverterLookup; import gherkin.I18n; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Locale; -import java.util.Map; +import java.util.*; public class LocalizedXStreams { private final Map xStreams = new HashMap(); diff --git a/core/src/main/java/cucumber/runtime/converters/TimeConverter.java b/core/src/main/java/cucumber/runtime/converters/TimeConverter.java index 8336b70512..3abba71f51 100644 --- a/core/src/main/java/cucumber/runtime/converters/TimeConverter.java +++ b/core/src/main/java/cucumber/runtime/converters/TimeConverter.java @@ -6,12 +6,7 @@ import java.text.DateFormat; import java.text.Format; import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Calendar; -import java.util.Date; -import java.util.List; -import java.util.Locale; -import java.util.TimeZone; +import java.util.*; import static java.util.Arrays.asList; diff --git a/core/src/main/java/cucumber/runtime/model/CucumberFeature.java b/core/src/main/java/cucumber/runtime/model/CucumberFeature.java index 0692f3b217..afb8e699db 100644 --- a/core/src/main/java/cucumber/runtime/model/CucumberFeature.java +++ b/core/src/main/java/cucumber/runtime/model/CucumberFeature.java @@ -4,13 +4,11 @@ import cucumber.io.ResourceLoader; import cucumber.runtime.CucumberException; import cucumber.runtime.FeatureBuilder; +import cucumber.runtime.Runtime; import gherkin.I18n; -import gherkin.formatter.model.Background; -import gherkin.formatter.model.Examples; -import gherkin.formatter.model.Feature; -import gherkin.formatter.model.Scenario; -import gherkin.formatter.model.ScenarioOutline; -import gherkin.formatter.model.Step; +import gherkin.formatter.Formatter; +import gherkin.formatter.Reporter; +import gherkin.formatter.model.*; import java.util.ArrayList; import java.util.Collections; @@ -94,6 +92,18 @@ public String getUri() { return uri; } + public void run(Formatter formatter, Reporter reporter, Runtime runtime) { + formatter.uri(getUri()); + formatter.feature(getFeature()); + + for (CucumberTagStatement cucumberTagStatement : getFeatureElements()) { + //Run the scenario, it should handle before and after hooks + cucumberTagStatement.run(formatter, reporter, runtime); + } + formatter.eof(); + + } + private static class CucumberFeatureUriComparator implements Comparator { @Override public int compare(CucumberFeature a, CucumberFeature b) { diff --git a/core/src/main/java/cucumber/runtime/model/CucumberScenarioOutline.java b/core/src/main/java/cucumber/runtime/model/CucumberScenarioOutline.java index 46c0968635..6203570310 100644 --- a/core/src/main/java/cucumber/runtime/model/CucumberScenarioOutline.java +++ b/core/src/main/java/cucumber/runtime/model/CucumberScenarioOutline.java @@ -3,15 +3,7 @@ import cucumber.runtime.Runtime; import gherkin.formatter.Formatter; import gherkin.formatter.Reporter; -import gherkin.formatter.model.DataTableRow; -import gherkin.formatter.model.DocString; -import gherkin.formatter.model.Examples; -import gherkin.formatter.model.ExamplesTableRow; -import gherkin.formatter.model.Row; -import gherkin.formatter.model.Scenario; -import gherkin.formatter.model.ScenarioOutline; -import gherkin.formatter.model.Step; -import gherkin.formatter.model.Tag; +import gherkin.formatter.model.*; import java.util.ArrayList; import java.util.HashSet; diff --git a/core/src/main/java/cucumber/table/TableConverter.java b/core/src/main/java/cucumber/table/TableConverter.java index ddde80e8d6..cb38fff365 100644 --- a/core/src/main/java/cucumber/table/TableConverter.java +++ b/core/src/main/java/cucumber/table/TableConverter.java @@ -5,12 +5,7 @@ import com.thoughtworks.xstream.converters.SingleValueConverter; import com.thoughtworks.xstream.io.HierarchicalStreamReader; import cucumber.runtime.CucumberException; -import cucumber.table.xstream.DataTableWriter; -import cucumber.table.xstream.ListOfListOfSingleValueReader; -import cucumber.table.xstream.ListOfListOfSingleValueWriter; -import cucumber.table.xstream.ListOfMapReader; -import cucumber.table.xstream.ListOfObjectReader; -import cucumber.table.xstream.ListOfObjectWriter; +import cucumber.table.xstream.*; import gherkin.util.Mapper; import java.lang.reflect.ParameterizedType; diff --git a/core/src/test/java/cucumber/formatter/FormatterConverterTest.java b/core/src/test/java/cucumber/formatter/FormatterConverterTest.java new file mode 100644 index 0000000000..44d635e9b2 --- /dev/null +++ b/core/src/test/java/cucumber/formatter/FormatterConverterTest.java @@ -0,0 +1,38 @@ +package cucumber.formatter; + +import gherkin.formatter.Formatter; +import org.junit.Test; + +import java.io.IOException; + +import static cucumber.formatter.TempDir.createTempDirectory; +import static cucumber.formatter.TempDir.createTempFile; +import static org.junit.Assert.assertEquals; + +public class FormatterConverterTest { + private FormatterConverter fc = new FormatterConverter(); + + @Test + public void instantiates_junit_formatter_with_file_arg() { + Formatter formatter = fc.convert("junit:some_file.xml"); + assertEquals(JUnitFormatter.class, formatter.getClass()); + } + + @Test + public void instantiates_html_formatter_with_dir_arg() throws IOException { + Formatter formatter = fc.convert("html:" + createTempDirectory().getAbsolutePath()); + assertEquals(HTMLFormatter.class, formatter.getClass()); + } + + @Test + public void instantiates_pretty_formatter_with_file_arg() throws IOException { + Formatter formatter = fc.convert("pretty:" + createTempFile().getAbsolutePath()); + assertEquals(CucumberPrettyFormatter.class, formatter.getClass()); + } + + @Test + public void instantiates_pretty_formatter_without_file_arg() { + Formatter formatter = fc.convert("pretty"); + assertEquals(CucumberPrettyFormatter.class, formatter.getClass()); + } +} diff --git a/core/src/test/java/cucumber/formatter/FormatterFactoryTest.java b/core/src/test/java/cucumber/formatter/FormatterFactoryTest.java deleted file mode 100644 index d5a1b70f1f..0000000000 --- a/core/src/test/java/cucumber/formatter/FormatterFactoryTest.java +++ /dev/null @@ -1,67 +0,0 @@ -package cucumber.formatter; - -import gherkin.formatter.Formatter; -import gherkin.formatter.JSONFormatter; -import gherkin.formatter.JSONPrettyFormatter; -import gherkin.formatter.PrettyFormatter; -import org.junit.Test; - -import java.io.File; -import java.io.IOException; -import java.io.StringWriter; - -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertThat; - -public class FormatterFactoryTest { - - private final FormatterFactory formatterFactory = new FormatterFactory(Thread.currentThread().getContextClassLoader()); - - @Test - public void shouldInstantiateJsonFormatter() { - assertThat(formatterFactory.createFormatter("json", System.out), is(JSONFormatter.class)); - } - - @Test - public void shouldInstantiateJsonPrettyFormatter() { - assertThat(formatterFactory.createFormatter("json-pretty", System.out), is(JSONPrettyFormatter.class)); - } - - @Test - public void shouldInstantiatePrettyFormatter() { - assertThat(formatterFactory.createFormatter("pretty", System.out), is(PrettyFormatter.class)); - } - - @Test - public void shouldInstantiateProgressFormatter() { - assertThat(formatterFactory.createFormatter("progress", System.out), is(ProgressFormatter.class)); - } - - @Test - public void shouldInstantiateHtmlFormatter() { - assertThat(formatterFactory.createFormatter("html", new File(System.getProperty("user.dir"))), is(HTMLFormatter.class)); - } - - @Test - public void shouldInstantiateJUnitFormatter() throws IOException { - assertThat(formatterFactory.createFormatter("junit", File.createTempFile("cucumber-jvm", "report.xml")), is(JUnitFormatter.class)); - } - - @Test - public void shouldInstantiateCustomFormatterFromClassNameWithAppender() { - StringWriter writer = new StringWriter(); - Formatter formatter = formatterFactory.createFormatter(TestFormatter.class.getName(), writer); - assertThat(formatter, is(TestFormatter.class)); - assertSame(writer, ((TestFormatter) formatter).appendable); - } - - @Test - public void shouldInstantiateCustomFormatterFromClassNameWithDirFile() { - File dir = new File(System.getProperty("user.dir")); - Formatter formatter = formatterFactory.createFormatter(TestFormatter.class.getName(), dir); - assertThat(formatter, is(TestFormatter.class)); - assertSame(dir, ((TestFormatter) formatter).dir); - } - -} diff --git a/core/src/test/java/cucumber/formatter/HTMLFormatterTest.java b/core/src/test/java/cucumber/formatter/HTMLFormatterTest.java index 164afab171..d82b226abd 100644 --- a/core/src/test/java/cucumber/formatter/HTMLFormatterTest.java +++ b/core/src/test/java/cucumber/formatter/HTMLFormatterTest.java @@ -1,9 +1,5 @@ package cucumber.formatter; -import cucumber.io.ClasspathResourceLoader; -import cucumber.runtime.Backend; -import cucumber.runtime.Runtime; -import cucumber.runtime.RuntimeOptions; import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.nodes.Element; @@ -16,14 +12,8 @@ import java.io.File; import java.io.FileReader; import java.io.IOException; -import java.util.List; -import static java.util.Arrays.asList; -import static java.util.Collections.emptyList; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; -import static org.mockito.Mockito.mock; +import static org.junit.Assert.*; public class HTMLFormatterTest { @@ -31,8 +21,8 @@ public class HTMLFormatterTest { @Before public void writeReport() throws IOException { - outputDir = createTempDirectory(); - runFeaturesWithFormatter(asList("cucumber/formatter/HTMLFormatterTest.feature"), outputDir); + outputDir = TempDir.createTempDirectory(); + runFeaturesWithFormatter(outputDir); } @Test @@ -56,31 +46,10 @@ public void writes_valid_report_js() throws IOException { } } - private void runFeaturesWithFormatter(final List featurePaths, File outputDir) throws IOException { + private void runFeaturesWithFormatter(File outputDir) throws IOException { final HTMLFormatter f = new HTMLFormatter(outputDir); - final ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); - final ClasspathResourceLoader resourceLoader = new ClasspathResourceLoader(classLoader); - final List gluePaths = emptyList(); - RuntimeOptions runtimeOptions = new RuntimeOptions(); - final Runtime runtime = new Runtime(resourceLoader, classLoader, asList(mock(Backend.class)), runtimeOptions); - runtime.run(featurePaths, emptyList(), f, f); + f.uri("some.feature"); f.done(); f.close(); } - - private static File createTempDirectory() throws IOException { - File temp = File.createTempFile("temp", Long.toString(System.nanoTime())); - - if (!(temp.delete())) { - throw new IOException("Could not delete temp file: " + temp.getAbsolutePath()); - } - - if (!(temp.mkdir())) { - throw new IOException("Could not create temp directory: " + temp.getAbsolutePath()); - } - - temp.deleteOnExit(); - - return temp; - } } diff --git a/core/src/test/java/cucumber/formatter/JUnitFormatterTest.java b/core/src/test/java/cucumber/formatter/JUnitFormatterTest.java index f6c56bac18..ce3986bfff 100644 --- a/core/src/test/java/cucumber/formatter/JUnitFormatterTest.java +++ b/core/src/test/java/cucumber/formatter/JUnitFormatterTest.java @@ -10,56 +10,56 @@ import org.xml.sax.SAXException; import javax.xml.parsers.ParserConfigurationException; -import java.io.*; +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.ArrayList; import java.util.List; import static java.util.Arrays.asList; -import static java.util.Collections.emptyList; import static junit.framework.Assert.assertTrue; import static org.mockito.Mockito.mock; -/** - * @author Uladzimir Mihura - * Date: 2/25/12 - * Time: 8:39 PM - */ public class JUnitFormatterTest { @Test public void featureSimpleTest() throws Exception { - runFeaturesWithFormatter(asList("cucumber/formatter/JUnitFormatterTest_1.feature")); - compareXML("cucumber/formatter/JUnitFormatterTest_1.report.xml", "report.xml"); + File report = runFeaturesWithJunitFormatter(asList("cucumber/formatter/JUnitFormatterTest_1.feature")); + assertXmlEqual("cucumber/formatter/JUnitFormatterTest_1.report.xml", report); } @Test public void featureWithBackgroundTest() throws Exception { - runFeaturesWithFormatter(asList("cucumber/formatter/JUnitFormatterTest_2.feature")); - compareXML("cucumber/formatter/JUnitFormatterTest_2.report.xml", "report.xml"); + File report = runFeaturesWithJunitFormatter(asList("cucumber/formatter/JUnitFormatterTest_2.feature")); + assertXmlEqual("cucumber/formatter/JUnitFormatterTest_2.report.xml", report); } @Test public void featureWithOutlineTest() throws Exception { - runFeaturesWithFormatter(asList("cucumber/formatter/JUnitFormatterTest_3.feature")); - compareXML("cucumber/formatter/JUnitFormatterTest_3.report.xml", "report.xml"); + File report = runFeaturesWithJunitFormatter(asList("cucumber/formatter/JUnitFormatterTest_3.feature")); + assertXmlEqual("cucumber/formatter/JUnitFormatterTest_3.report.xml", report); } - private void runFeaturesWithFormatter(final List featurePaths) throws IOException { - File report = new File("report.xml"); -// report.deleteOnExit(); - final JUnitFormatter f = new JUnitFormatter(report); + private File runFeaturesWithJunitFormatter(final List featurePaths) throws IOException { + File report = File.createTempFile("cucumber-jvm-junit", "xml"); final ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); final ClasspathResourceLoader resourceLoader = new ClasspathResourceLoader(classLoader); - final List gluePaths = emptyList(); - RuntimeOptions runtimeOptions = new RuntimeOptions(); + + List args = new ArrayList(); + args.add("--format"); + args.add("junit:" + report.getAbsolutePath()); + args.addAll(featurePaths); + + RuntimeOptions runtimeOptions = new RuntimeOptions(args.toArray(new String[args.size()])); final cucumber.runtime.Runtime runtime = new Runtime(resourceLoader, classLoader, asList(mock(Backend.class)), runtimeOptions); - runtime.run(featurePaths, emptyList(), f, f); - f.done(); - f.close(); + runtime.run(); + return report; } - private void compareXML(String expected, String received) throws IOException, ParserConfigurationException, SAXException { + private void assertXmlEqual(String expected, File actual) throws IOException, ParserConfigurationException, SAXException { XMLUnit.setIgnoreWhitespace(true); - Diff diff = new Diff(new InputStreamReader(Thread.currentThread().getContextClassLoader().getResourceAsStream(expected)), new FileReader(received)); + Diff diff = new Diff(new InputStreamReader(Thread.currentThread().getContextClassLoader().getResourceAsStream(expected)), new FileReader(actual)); assertTrue("XML files are similar " + diff, diff.identical()); } diff --git a/core/src/test/java/cucumber/formatter/TempDir.java b/core/src/test/java/cucumber/formatter/TempDir.java new file mode 100644 index 0000000000..f033642ecf --- /dev/null +++ b/core/src/test/java/cucumber/formatter/TempDir.java @@ -0,0 +1,26 @@ +package cucumber.formatter; + +import java.io.File; +import java.io.IOException; + +public class TempDir { + public static File createTempDirectory() throws IOException { + File temp = createTempFile(); + + if (!(temp.delete())) { + throw new IOException("Could not delete temp file: " + temp.getAbsolutePath()); + } + + if (!(temp.mkdir())) { + throw new IOException("Could not create temp directory: " + temp.getAbsolutePath()); + } + + temp.deleteOnExit(); + + return temp; + } + + public static File createTempFile() throws IOException { + return File.createTempFile("temp", Long.toString(System.nanoTime())); + } +} diff --git a/core/src/test/java/cucumber/formatter/TestFormatter.java b/core/src/test/java/cucumber/formatter/TestFormatter.java index c8cdd91b60..4efa1b2ece 100644 --- a/core/src/test/java/cucumber/formatter/TestFormatter.java +++ b/core/src/test/java/cucumber/formatter/TestFormatter.java @@ -1,12 +1,7 @@ package cucumber.formatter; import gherkin.formatter.Formatter; -import gherkin.formatter.model.Background; -import gherkin.formatter.model.Examples; -import gherkin.formatter.model.Feature; -import gherkin.formatter.model.Scenario; -import gherkin.formatter.model.ScenarioOutline; -import gherkin.formatter.model.Step; +import gherkin.formatter.model.*; import org.junit.Ignore; import java.io.File; diff --git a/core/src/test/java/cucumber/runtime/BackgroundTest.java b/core/src/test/java/cucumber/runtime/BackgroundTest.java index 39bef90c78..92f713c934 100644 --- a/core/src/test/java/cucumber/runtime/BackgroundTest.java +++ b/core/src/test/java/cucumber/runtime/BackgroundTest.java @@ -27,7 +27,7 @@ public void should_run_background() throws IOException { StringBuilder out = new StringBuilder(); PrettyFormatter pretty = new PrettyFormatter(out, true, true); - runtime.run(feature, pretty, pretty); + feature.run(pretty, pretty, runtime); String expectedOutput = "" + "Feature: \n" + "\n" + diff --git a/core/src/test/java/cucumber/runtime/HookOrderTest.java b/core/src/test/java/cucumber/runtime/HookOrderTest.java index 75906421a9..8268864d00 100644 --- a/core/src/test/java/cucumber/runtime/HookOrderTest.java +++ b/core/src/test/java/cucumber/runtime/HookOrderTest.java @@ -14,10 +14,7 @@ import static java.util.Arrays.asList; import static org.mockito.Matchers.anyListOf; -import static org.mockito.Mockito.inOrder; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; +import static org.mockito.Mockito.*; public class HookOrderTest { diff --git a/core/src/test/java/cucumber/runtime/HookTest.java b/core/src/test/java/cucumber/runtime/HookTest.java index 25b524ff4a..0d7f16e8ef 100644 --- a/core/src/test/java/cucumber/runtime/HookTest.java +++ b/core/src/test/java/cucumber/runtime/HookTest.java @@ -17,9 +17,7 @@ import static java.util.Arrays.asList; import static org.mockito.Matchers.anyListOf; -import static org.mockito.Mockito.inOrder; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; +import static org.mockito.Mockito.*; public class HookTest { diff --git a/core/src/test/java/cucumber/runtime/RuntimeTest.java b/core/src/test/java/cucumber/runtime/RuntimeTest.java index ac6965038e..67384ba97a 100644 --- a/core/src/test/java/cucumber/runtime/RuntimeTest.java +++ b/core/src/test/java/cucumber/runtime/RuntimeTest.java @@ -26,7 +26,8 @@ public void runs_feature_with_json_formatter() throws Exception { List backends = asList(mock(Backend.class)); ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); RuntimeOptions runtimeOptions = new RuntimeOptions(); - new Runtime(new ClasspathResourceLoader(classLoader), classLoader, backends, runtimeOptions).run(feature, jsonFormatter, jsonFormatter); + Runtime runtime = new Runtime(new ClasspathResourceLoader(classLoader), classLoader, backends, runtimeOptions); + feature.run(jsonFormatter, jsonFormatter, runtime); jsonFormatter.done(); String expected = "" + "[\n" + diff --git a/core/src/test/java/cucumber/runtime/StepDefinitionMatchTest.java b/core/src/test/java/cucumber/runtime/StepDefinitionMatchTest.java index 3be49ef9b1..f5c1ec95eb 100644 --- a/core/src/test/java/cucumber/runtime/StepDefinitionMatchTest.java +++ b/core/src/test/java/cucumber/runtime/StepDefinitionMatchTest.java @@ -13,9 +13,7 @@ import java.util.List; import static java.util.Arrays.asList; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; +import static org.mockito.Mockito.*; public class StepDefinitionMatchTest { private final ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); diff --git a/core/src/test/java/cucumber/runtime/UtilsTest.java b/core/src/test/java/cucumber/runtime/UtilsTest.java index aa72516f74..f69fd4d66d 100644 --- a/core/src/test/java/cucumber/runtime/UtilsTest.java +++ b/core/src/test/java/cucumber/runtime/UtilsTest.java @@ -2,12 +2,8 @@ import org.junit.Test; -import static cucumber.runtime.Utils.isInstantiable; -import static cucumber.runtime.Utils.packageName; -import static cucumber.runtime.Utils.packagePath; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static cucumber.runtime.Utils.*; +import static org.junit.Assert.*; public class UtilsTest { @Test diff --git a/core/src/test/java/cucumber/runtime/model/CucumberExamplesTest.java b/core/src/test/java/cucumber/runtime/model/CucumberExamplesTest.java index d7c7941056..b14c198a83 100644 --- a/core/src/test/java/cucumber/runtime/model/CucumberExamplesTest.java +++ b/core/src/test/java/cucumber/runtime/model/CucumberExamplesTest.java @@ -1,12 +1,6 @@ package cucumber.runtime.model; -import gherkin.formatter.model.Comment; -import gherkin.formatter.model.Examples; -import gherkin.formatter.model.ExamplesTableRow; -import gherkin.formatter.model.Feature; -import gherkin.formatter.model.ScenarioOutline; -import gherkin.formatter.model.Step; -import gherkin.formatter.model.Tag; +import gherkin.formatter.model.*; import org.junit.Test; import java.util.HashSet; diff --git a/core/src/test/java/cucumber/runtime/model/CucumberScenarioOutlineTest.java b/core/src/test/java/cucumber/runtime/model/CucumberScenarioOutlineTest.java index addee5077c..796b628d31 100644 --- a/core/src/test/java/cucumber/runtime/model/CucumberScenarioOutlineTest.java +++ b/core/src/test/java/cucumber/runtime/model/CucumberScenarioOutlineTest.java @@ -1,10 +1,6 @@ package cucumber.runtime.model; -import gherkin.formatter.model.Comment; -import gherkin.formatter.model.DataTableRow; -import gherkin.formatter.model.DocString; -import gherkin.formatter.model.ExamplesTableRow; -import gherkin.formatter.model.Step; +import gherkin.formatter.model.*; import org.junit.Test; import java.util.ArrayList; diff --git a/core/src/test/java/cucumber/table/FromDataTableTest.java b/core/src/test/java/cucumber/table/FromDataTableTest.java index 9d6ab696f8..ca0c248caa 100644 --- a/core/src/test/java/cucumber/table/FromDataTableTest.java +++ b/core/src/test/java/cucumber/table/FromDataTableTest.java @@ -23,12 +23,7 @@ import org.junit.rules.ExpectedException; import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.Calendar; -import java.util.Date; -import java.util.List; -import java.util.Map; -import java.util.TimeZone; +import java.util.*; import static java.util.Arrays.asList; import static java.util.Collections.emptyList; diff --git a/guice/src/test/java/cucumber/runtime/java/guice/GuiceFactoryTest.java b/guice/src/test/java/cucumber/runtime/java/guice/GuiceFactoryTest.java index 4fa9fdaa86..e1b92aae70 100644 --- a/guice/src/test/java/cucumber/runtime/java/guice/GuiceFactoryTest.java +++ b/guice/src/test/java/cucumber/runtime/java/guice/GuiceFactoryTest.java @@ -5,9 +5,7 @@ import java.io.IOException; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNotSame; -import static org.junit.Assert.assertSame; +import static org.junit.Assert.*; public class GuiceFactoryTest { @Test diff --git a/java/src/main/java/cucumber/runtime/java/JavaStepDefinition.java b/java/src/main/java/cucumber/runtime/java/JavaStepDefinition.java index aecc2439fc..ff03a05dec 100644 --- a/java/src/main/java/cucumber/runtime/java/JavaStepDefinition.java +++ b/java/src/main/java/cucumber/runtime/java/JavaStepDefinition.java @@ -1,11 +1,7 @@ package cucumber.runtime.java; import cucumber.annotation.Pending; -import cucumber.runtime.CucumberException; -import cucumber.runtime.JdkPatternArgumentMatcher; -import cucumber.runtime.ParameterType; -import cucumber.runtime.PendingException; -import cucumber.runtime.StepDefinition; +import cucumber.runtime.*; import gherkin.I18n; import gherkin.formatter.Argument; import gherkin.formatter.model.Step; diff --git a/java/src/test/java/cucumber/runtime/java/ClasspathMethodScannerTest.java b/java/src/test/java/cucumber/runtime/java/ClasspathMethodScannerTest.java index 92c4cc41dc..eb59768fce 100644 --- a/java/src/test/java/cucumber/runtime/java/ClasspathMethodScannerTest.java +++ b/java/src/test/java/cucumber/runtime/java/ClasspathMethodScannerTest.java @@ -9,9 +9,7 @@ import org.mockito.internal.util.reflection.Whitebox; import static java.util.Arrays.asList; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyNoMoreInteractions; +import static org.mockito.Mockito.*; public class ClasspathMethodScannerTest { diff --git a/java/src/test/java/cucumber/runtime/java/JavaHookTest.java b/java/src/test/java/cucumber/runtime/java/JavaHookTest.java index 916f18edb2..401ec172fc 100644 --- a/java/src/test/java/cucumber/runtime/java/JavaHookTest.java +++ b/java/src/test/java/cucumber/runtime/java/JavaHookTest.java @@ -15,9 +15,7 @@ import java.util.Collections; import static java.util.Arrays.asList; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.*; import static org.mockito.Mockito.mock; public class JavaHookTest { diff --git a/java/src/test/java/cucumber/runtime/java/JavaStepDefinitionTest.java b/java/src/test/java/cucumber/runtime/java/JavaStepDefinitionTest.java index f8cdc9db3a..eb77008290 100644 --- a/java/src/test/java/cucumber/runtime/java/JavaStepDefinitionTest.java +++ b/java/src/test/java/cucumber/runtime/java/JavaStepDefinitionTest.java @@ -22,9 +22,7 @@ import java.util.Set; import static java.util.Arrays.asList; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.*; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; diff --git a/jruby/src/main/java/cucumber/runtime/jruby/JRubyBackend.java b/jruby/src/main/java/cucumber/runtime/jruby/JRubyBackend.java index ddbcfc15c7..c83f2feb86 100644 --- a/jruby/src/main/java/cucumber/runtime/jruby/JRubyBackend.java +++ b/jruby/src/main/java/cucumber/runtime/jruby/JRubyBackend.java @@ -2,11 +2,7 @@ import cucumber.io.Resource; import cucumber.io.ResourceLoader; -import cucumber.runtime.Backend; -import cucumber.runtime.CucumberException; -import cucumber.runtime.Glue; -import cucumber.runtime.PendingException; -import cucumber.runtime.UnreportedStepExecutor; +import cucumber.runtime.*; import cucumber.runtime.snippets.SnippetGenerator; import cucumber.table.DataTable; import gherkin.I18n; @@ -20,11 +16,7 @@ import java.io.IOException; import java.io.InputStreamReader; import java.io.UnsupportedEncodingException; -import java.util.HashSet; -import java.util.List; -import java.util.MissingResourceException; -import java.util.ResourceBundle; -import java.util.Set; +import java.util.*; public class JRubyBackend implements Backend { private static final String DSL = "/cucumber/runtime/jruby/dsl.rb"; diff --git a/junit/src/main/java/cucumber/junit/Cucumber.java b/junit/src/main/java/cucumber/junit/Cucumber.java index f4c620e556..0ccf4466c6 100644 --- a/junit/src/main/java/cucumber/junit/Cucumber.java +++ b/junit/src/main/java/cucumber/junit/Cucumber.java @@ -1,6 +1,5 @@ package cucumber.junit; -import cucumber.formatter.NullReporter; import cucumber.io.ClasspathResourceLoader; import cucumber.io.ResourceLoader; import cucumber.runtime.CucumberException; @@ -14,7 +13,10 @@ import org.junit.runners.model.InitializationError; import java.io.IOException; -import java.lang.annotation.*; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; import java.util.ArrayList; import java.util.List; @@ -53,7 +55,7 @@ public Cucumber(Class clazz) throws InitializationError, IOException { runtime = new Runtime(resourceLoader, classLoader, runtimeOptions); // TODO: Create formatter(s) based on Annotations. Use same technique as in cli.Main for MultiFormatter - jUnitReporter = new JUnitReporter(new NullReporter(), new NullReporter()); + jUnitReporter = new JUnitReporter(runtimeOptions.reporter(classLoader), runtimeOptions.formatter(classLoader)); addChildren(runtimeOptions.cucumberFeatures(resourceLoader)); } diff --git a/junit/src/main/java/cucumber/junit/JUnitReporter.java b/junit/src/main/java/cucumber/junit/JUnitReporter.java index 60958cc635..8fa6cb4efd 100644 --- a/junit/src/main/java/cucumber/junit/JUnitReporter.java +++ b/junit/src/main/java/cucumber/junit/JUnitReporter.java @@ -3,13 +3,7 @@ import cucumber.runtime.PendingException; import gherkin.formatter.Formatter; import gherkin.formatter.Reporter; -import gherkin.formatter.model.Background; -import gherkin.formatter.model.Examples; -import gherkin.formatter.model.Match; -import gherkin.formatter.model.Result; -import gherkin.formatter.model.Scenario; -import gherkin.formatter.model.ScenarioOutline; -import gherkin.formatter.model.Step; +import gherkin.formatter.model.*; import org.junit.internal.runners.model.EachTestNotifier; import org.junit.runner.Description; import org.junit.runner.notification.RunNotifier; diff --git a/junit/src/test/java/cucumber/junit/JUnitReporterTest.java b/junit/src/test/java/cucumber/junit/JUnitReporterTest.java index 68d2c48170..a539187c1b 100644 --- a/junit/src/test/java/cucumber/junit/JUnitReporterTest.java +++ b/junit/src/test/java/cucumber/junit/JUnitReporterTest.java @@ -11,9 +11,7 @@ import org.mockito.ArgumentCaptor; import static org.junit.Assert.assertEquals; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; +import static org.mockito.Mockito.*; public class JUnitReporterTest { diff --git a/openejb/src/main/java/cucumber/runtime/java/openejb/OpenEJBObjectFactory.java b/openejb/src/main/java/cucumber/runtime/java/openejb/OpenEJBObjectFactory.java index 5e2c16cd68..98e06be2aa 100644 --- a/openejb/src/main/java/cucumber/runtime/java/openejb/OpenEJBObjectFactory.java +++ b/openejb/src/main/java/cucumber/runtime/java/openejb/OpenEJBObjectFactory.java @@ -5,12 +5,7 @@ import org.apache.openejb.OpenEjbContainer; import javax.ejb.embeddable.EJBContainer; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Properties; +import java.util.*; public class OpenEJBObjectFactory implements ObjectFactory { static { diff --git a/spring/src/test/java/cucumber/runtime/java/spring/SpringFactoryTest.java b/spring/src/test/java/cucumber/runtime/java/spring/SpringFactoryTest.java index 179b830f6c..58bee8c53b 100644 --- a/spring/src/test/java/cucumber/runtime/java/spring/SpringFactoryTest.java +++ b/spring/src/test/java/cucumber/runtime/java/spring/SpringFactoryTest.java @@ -3,11 +3,7 @@ import cucumber.runtime.java.ObjectFactory; import org.junit.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNotSame; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.*; public class SpringFactoryTest { diff --git a/spring/src/test/java/cucumber/runtime/java/spring/hooks/SpringTransactionHooksTest.java b/spring/src/test/java/cucumber/runtime/java/spring/hooks/SpringTransactionHooksTest.java index 4e375f933d..d71a65ba2c 100644 --- a/spring/src/test/java/cucumber/runtime/java/spring/hooks/SpringTransactionHooksTest.java +++ b/spring/src/test/java/cucumber/runtime/java/spring/hooks/SpringTransactionHooksTest.java @@ -11,9 +11,7 @@ import org.springframework.transaction.support.SimpleTransactionStatus; import static org.junit.Assert.assertSame; -import static org.mockito.Mockito.isA; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; +import static org.mockito.Mockito.*; @RunWith(MockitoJUnitRunner.class) public class SpringTransactionHooksTest { diff --git a/spring/src/test/resources/applicationContext.xml b/spring/src/test/resources/applicationContext.xml index 5fbce27c49..28ebcee442 100644 --- a/spring/src/test/resources/applicationContext.xml +++ b/spring/src/test/resources/applicationContext.xml @@ -1,8 +1,7 @@ + xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"> From 783433c44f34c5cea48ad63399a3b0e7d15cc696 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aslak=20Helles=C3=B8y?= Date: Sat, 17 Mar 2012 11:09:23 +0000 Subject: [PATCH 10/10] Optimise imports --- core/pom.xml | 3 ++- .../formatter/FormatterConverter.java | 22 +++++++++---------- .../cucumber/formatter/HTMLFormatter.java | 20 ++++++++++++++--- .../cucumber/formatter/JUnitFormatter.java | 9 +++++++- .../cucumber/formatter/ProgressFormatter.java | 9 +++++++- .../java/cucumber/runtime/FeatureBuilder.java | 7 +++++- .../main/java/cucumber/runtime/Runtime.java | 15 ++++++++++--- .../java/cucumber/runtime/RuntimeGlue.java | 8 +++++-- .../java/cucumber/runtime/RuntimeOptions.java | 6 ++--- .../autocomplete/StepdefGenerator.java | 6 ++++- .../runtime/converters/LocalizedXStreams.java | 6 ++++- .../runtime/converters/TimeConverter.java | 7 +++++- .../runtime/model/CucumberFeature.java | 7 +++++- .../model/CucumberScenarioOutline.java | 10 ++++++++- .../java/cucumber/table/TableConverter.java | 7 +++++- .../cucumber/formatter/HTMLFormatterTest.java | 4 +++- .../formatter/JUnitFormatterTest.java | 2 +- .../cucumber/formatter/TestFormatter.java | 7 +++++- .../java/cucumber/runtime/HookOrderTest.java | 5 ++++- .../test/java/cucumber/runtime/HookTest.java | 4 +++- .../runtime/StepDefinitionMatchTest.java | 4 +++- .../test/java/cucumber/runtime/UtilsTest.java | 8 +++++-- .../runtime/model/CucumberExamplesTest.java | 8 ++++++- .../model/CucumberScenarioOutlineTest.java | 6 ++++- .../cucumber/table/FromDataTableTest.java | 7 +++++- java/pom.xml | 6 +++-- .../runtime/java/JavaStepDefinition.java | 6 ++++- .../java/ClasspathMethodScannerTest.java | 4 +++- .../cucumber/runtime/java/JavaHookTest.java | 4 +++- .../runtime/java/JavaStepDefinitionTest.java | 4 +++- junit/pom.xml | 3 ++- .../java/cucumber/junit/JUnitReporter.java | 8 ++++++- .../cucumber/junit/RuntimeOptionsFactory.java | 16 ++++++-------- .../java/cucumber/junit/CucumberTest.java | 4 ++-- .../cucumber/junit/JUnitReporterTest.java | 4 +++- picocontainer/pom.xml | 22 ++++++++++--------- pom.xml | 2 +- 37 files changed, 205 insertions(+), 75 deletions(-) diff --git a/core/pom.xml b/core/pom.xml index a8c01517d4..9d21f0e7bb 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -1,4 +1,5 @@ - + 4.0.0 diff --git a/core/src/main/java/cucumber/formatter/FormatterConverter.java b/core/src/main/java/cucumber/formatter/FormatterConverter.java index 6c92550c75..e6ff62ecd1 100644 --- a/core/src/main/java/cucumber/formatter/FormatterConverter.java +++ b/core/src/main/java/cucumber/formatter/FormatterConverter.java @@ -20,8 +20,8 @@ public class FormatterConverter implements IStringConverter { private Class[] CTOR_ARGS = new Class[]{Appendable.class, File.class}; - - private static final Map> FORMATTER_CLASSES = new HashMap>() {{ + + private static final Map> FORMATTER_CLASSES = new HashMap>() {{ put("junit", JUnitFormatter.class); put("html", HTMLFormatter.class); put("pretty", CucumberPrettyFormatter.class); @@ -37,7 +37,7 @@ public Formatter convert(String formatterString) { Matcher formatterWithFile = FORMATTER_WITH_FILE_PATTERN.matcher(formatterString); String formatterName; Object ctorArg; - if(formatterWithFile.matches()) { + if (formatterWithFile.matches()) { formatterName = formatterWithFile.group(1); ctorArg = new File(formatterWithFile.group(2)); } else { @@ -56,10 +56,10 @@ private Formatter instantiate(Class formatterClass, Object Constructor constructor; for (Class ctorArgClass : CTOR_ARGS) { - constructor=findConstructor(formatterClass, ctorArgClass); - if(constructor != null) { + constructor = findConstructor(formatterClass, ctorArgClass); + if (constructor != null) { ctorArg = convert(ctorArg, ctorArgClass); - if(ctorArg != null) { + if (ctorArg != null) { try { return constructor.newInstance(ctorArg); } catch (InstantiationException e) { @@ -76,13 +76,13 @@ private Formatter instantiate(Class formatterClass, Object } private Object convert(Object ctorArg, Class ctorArgClass) throws IOException { - if(ctorArgClass.isAssignableFrom(ctorArg.getClass())) { + if (ctorArgClass.isAssignableFrom(ctorArg.getClass())) { return ctorArg; } - if(ctorArgClass.equals(File.class) && ctorArg instanceof File) { + if (ctorArgClass.equals(File.class) && ctorArg instanceof File) { return ctorArg; } - if(ctorArgClass.equals(Appendable.class) && ctorArg instanceof File) { + if (ctorArgClass.equals(Appendable.class) && ctorArg instanceof File) { return new FileWriter((File) ctorArg); } return null; @@ -98,7 +98,7 @@ private Constructor findConstructor(Class formatterClass(String formatterName) { Class formatterClass = FORMATTER_CLASSES.get(formatterName); - if(formatterClass == null) { + if (formatterClass == null) { formatterClass = loadClass(formatterName); } return formatterClass; @@ -114,7 +114,7 @@ private Class loadClass(String className) { private Appendable defaultOutIfAvailable() { try { - if(defaultOut != null) { + if (defaultOut != null) { return defaultOut; } else { throw new CucumberException("Only one formatter can use STDOUT. If you use more than one formatter you must specify output path with FORMAT:PATH"); diff --git a/core/src/main/java/cucumber/formatter/HTMLFormatter.java b/core/src/main/java/cucumber/formatter/HTMLFormatter.java index 586be3166d..878bb46626 100644 --- a/core/src/main/java/cucumber/formatter/HTMLFormatter.java +++ b/core/src/main/java/cucumber/formatter/HTMLFormatter.java @@ -7,9 +7,23 @@ import gherkin.formatter.Mappable; import gherkin.formatter.NiceAppendable; import gherkin.formatter.Reporter; -import gherkin.formatter.model.*; - -import java.io.*; +import gherkin.formatter.model.Background; +import gherkin.formatter.model.Examples; +import gherkin.formatter.model.Feature; +import gherkin.formatter.model.Match; +import gherkin.formatter.model.Result; +import gherkin.formatter.model.Scenario; +import gherkin.formatter.model.ScenarioOutline; +import gherkin.formatter.model.Step; + +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.OutputStreamWriter; +import java.io.UnsupportedEncodingException; import java.util.HashMap; import java.util.List; import java.util.Map; diff --git a/core/src/main/java/cucumber/formatter/JUnitFormatter.java b/core/src/main/java/cucumber/formatter/JUnitFormatter.java index d650448c6e..c0ad0248e8 100644 --- a/core/src/main/java/cucumber/formatter/JUnitFormatter.java +++ b/core/src/main/java/cucumber/formatter/JUnitFormatter.java @@ -3,7 +3,14 @@ import cucumber.runtime.CucumberException; import gherkin.formatter.Formatter; import gherkin.formatter.Reporter; -import gherkin.formatter.model.*; +import gherkin.formatter.model.Background; +import gherkin.formatter.model.Examples; +import gherkin.formatter.model.Feature; +import gherkin.formatter.model.Match; +import gherkin.formatter.model.Result; +import gherkin.formatter.model.Scenario; +import gherkin.formatter.model.ScenarioOutline; +import gherkin.formatter.model.Step; import org.w3c.dom.Document; import org.w3c.dom.Element; diff --git a/core/src/main/java/cucumber/formatter/ProgressFormatter.java b/core/src/main/java/cucumber/formatter/ProgressFormatter.java index c131629e7c..4a2ac4d3e1 100644 --- a/core/src/main/java/cucumber/formatter/ProgressFormatter.java +++ b/core/src/main/java/cucumber/formatter/ProgressFormatter.java @@ -4,7 +4,14 @@ import gherkin.formatter.NiceAppendable; import gherkin.formatter.Reporter; import gherkin.formatter.ansi.AnsiEscapes; -import gherkin.formatter.model.*; +import gherkin.formatter.model.Background; +import gherkin.formatter.model.Examples; +import gherkin.formatter.model.Feature; +import gherkin.formatter.model.Match; +import gherkin.formatter.model.Result; +import gherkin.formatter.model.Scenario; +import gherkin.formatter.model.ScenarioOutline; +import gherkin.formatter.model.Step; import java.io.InputStream; import java.util.HashMap; diff --git a/core/src/main/java/cucumber/runtime/FeatureBuilder.java b/core/src/main/java/cucumber/runtime/FeatureBuilder.java index 4890f17ec1..9770f7cd54 100644 --- a/core/src/main/java/cucumber/runtime/FeatureBuilder.java +++ b/core/src/main/java/cucumber/runtime/FeatureBuilder.java @@ -5,7 +5,12 @@ import gherkin.I18n; import gherkin.formatter.FilterFormatter; import gherkin.formatter.Formatter; -import gherkin.formatter.model.*; +import gherkin.formatter.model.Background; +import gherkin.formatter.model.Examples; +import gherkin.formatter.model.Feature; +import gherkin.formatter.model.Scenario; +import gherkin.formatter.model.ScenarioOutline; +import gherkin.formatter.model.Step; import gherkin.parser.Parser; import gherkin.util.FixJava; diff --git a/core/src/main/java/cucumber/runtime/Runtime.java b/core/src/main/java/cucumber/runtime/Runtime.java index 007e48001b..7c671cfad4 100644 --- a/core/src/main/java/cucumber/runtime/Runtime.java +++ b/core/src/main/java/cucumber/runtime/Runtime.java @@ -8,10 +8,20 @@ import gherkin.I18n; import gherkin.formatter.Formatter; import gherkin.formatter.Reporter; -import gherkin.formatter.model.*; +import gherkin.formatter.model.Comment; +import gherkin.formatter.model.DataTableRow; +import gherkin.formatter.model.DocString; +import gherkin.formatter.model.Match; +import gherkin.formatter.model.Result; +import gherkin.formatter.model.Step; +import gherkin.formatter.model.Tag; import java.io.IOException; -import java.util.*; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.Set; /** * This is the main entry point for running Cucumber features. @@ -66,7 +76,6 @@ public void addError(Throwable error) { /** * This is the main entry point. Used from CLI, but not from JUnit. - * */ public void run() { for (CucumberFeature cucumberFeature : runtimeOptions.cucumberFeatures(resourceLoader)) { diff --git a/core/src/main/java/cucumber/runtime/RuntimeGlue.java b/core/src/main/java/cucumber/runtime/RuntimeGlue.java index 4a1ba7fdd8..0b4c03cba9 100644 --- a/core/src/main/java/cucumber/runtime/RuntimeGlue.java +++ b/core/src/main/java/cucumber/runtime/RuntimeGlue.java @@ -14,7 +14,11 @@ import java.io.File; import java.io.FileWriter; import java.io.IOException; -import java.util.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.TreeMap; import static cucumber.runtime.model.CucumberFeature.load; import static java.util.Collections.emptyList; @@ -96,7 +100,7 @@ private List stepDefinitionMatches(String uri, Step step) { @Override public void writeStepdefsJson(List featurePaths, File dotCucumber) throws IOException { - if(dotCucumber != null) { + if (dotCucumber != null) { List features = load(new FileResourceLoader(), featurePaths, NO_FILTERS); List metaStepdefs = new StepdefGenerator().generate(stepDefinitionsByPattern.values(), features); Gson gson = new GsonBuilder().setPrettyPrinting().create(); diff --git a/core/src/main/java/cucumber/runtime/RuntimeOptions.java b/core/src/main/java/cucumber/runtime/RuntimeOptions.java index da6b3d7939..91e7ff1a41 100644 --- a/core/src/main/java/cucumber/runtime/RuntimeOptions.java +++ b/core/src/main/java/cucumber/runtime/RuntimeOptions.java @@ -19,7 +19,6 @@ import java.util.List; import static cucumber.runtime.model.CucumberFeature.load; -import static java.util.Arrays.asList; public class RuntimeOptions { @Parameter(names = {"-g", "--glue"}, description = "Where cucumber looks for step definitions and hooks.") @@ -49,7 +48,7 @@ public RuntimeOptions(String... args) { cmd.setProgramName("cucumber"); cmd.parse(args); - if(formatters.isEmpty()) { + if (formatters.isEmpty()) { formatters.add(new ProgressFormatter(System.out)); } } @@ -96,8 +95,7 @@ public static class FormatterFactory implements IStringConverterFactory { public Class> getConverter(Class forType) { if (forType.equals(Formatter.class)) { return FormatterConverter.class; - } - else return null; + } else return null; } } diff --git a/core/src/main/java/cucumber/runtime/autocomplete/StepdefGenerator.java b/core/src/main/java/cucumber/runtime/autocomplete/StepdefGenerator.java index 25c2a7df8f..b64adeac57 100644 --- a/core/src/main/java/cucumber/runtime/autocomplete/StepdefGenerator.java +++ b/core/src/main/java/cucumber/runtime/autocomplete/StepdefGenerator.java @@ -6,7 +6,11 @@ import gherkin.formatter.Argument; import gherkin.formatter.model.Step; -import java.util.*; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; /** * Generates metadata to be used for Code Completion: https://github.com/cucumber/gherkin/wiki/Code-Completion diff --git a/core/src/main/java/cucumber/runtime/converters/LocalizedXStreams.java b/core/src/main/java/cucumber/runtime/converters/LocalizedXStreams.java index 798a5c9532..a9090aa650 100644 --- a/core/src/main/java/cucumber/runtime/converters/LocalizedXStreams.java +++ b/core/src/main/java/cucumber/runtime/converters/LocalizedXStreams.java @@ -5,7 +5,11 @@ import com.thoughtworks.xstream.core.DefaultConverterLookup; import gherkin.I18n; -import java.util.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Locale; +import java.util.Map; public class LocalizedXStreams { private final Map xStreams = new HashMap(); diff --git a/core/src/main/java/cucumber/runtime/converters/TimeConverter.java b/core/src/main/java/cucumber/runtime/converters/TimeConverter.java index 3abba71f51..8336b70512 100644 --- a/core/src/main/java/cucumber/runtime/converters/TimeConverter.java +++ b/core/src/main/java/cucumber/runtime/converters/TimeConverter.java @@ -6,7 +6,12 @@ import java.text.DateFormat; import java.text.Format; import java.text.SimpleDateFormat; -import java.util.*; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Date; +import java.util.List; +import java.util.Locale; +import java.util.TimeZone; import static java.util.Arrays.asList; diff --git a/core/src/main/java/cucumber/runtime/model/CucumberFeature.java b/core/src/main/java/cucumber/runtime/model/CucumberFeature.java index afb8e699db..13dded52a0 100644 --- a/core/src/main/java/cucumber/runtime/model/CucumberFeature.java +++ b/core/src/main/java/cucumber/runtime/model/CucumberFeature.java @@ -8,7 +8,12 @@ import gherkin.I18n; import gherkin.formatter.Formatter; import gherkin.formatter.Reporter; -import gherkin.formatter.model.*; +import gherkin.formatter.model.Background; +import gherkin.formatter.model.Examples; +import gherkin.formatter.model.Feature; +import gherkin.formatter.model.Scenario; +import gherkin.formatter.model.ScenarioOutline; +import gherkin.formatter.model.Step; import java.util.ArrayList; import java.util.Collections; diff --git a/core/src/main/java/cucumber/runtime/model/CucumberScenarioOutline.java b/core/src/main/java/cucumber/runtime/model/CucumberScenarioOutline.java index 6203570310..46c0968635 100644 --- a/core/src/main/java/cucumber/runtime/model/CucumberScenarioOutline.java +++ b/core/src/main/java/cucumber/runtime/model/CucumberScenarioOutline.java @@ -3,7 +3,15 @@ import cucumber.runtime.Runtime; import gherkin.formatter.Formatter; import gherkin.formatter.Reporter; -import gherkin.formatter.model.*; +import gherkin.formatter.model.DataTableRow; +import gherkin.formatter.model.DocString; +import gherkin.formatter.model.Examples; +import gherkin.formatter.model.ExamplesTableRow; +import gherkin.formatter.model.Row; +import gherkin.formatter.model.Scenario; +import gherkin.formatter.model.ScenarioOutline; +import gherkin.formatter.model.Step; +import gherkin.formatter.model.Tag; import java.util.ArrayList; import java.util.HashSet; diff --git a/core/src/main/java/cucumber/table/TableConverter.java b/core/src/main/java/cucumber/table/TableConverter.java index cb38fff365..ddde80e8d6 100644 --- a/core/src/main/java/cucumber/table/TableConverter.java +++ b/core/src/main/java/cucumber/table/TableConverter.java @@ -5,7 +5,12 @@ import com.thoughtworks.xstream.converters.SingleValueConverter; import com.thoughtworks.xstream.io.HierarchicalStreamReader; import cucumber.runtime.CucumberException; -import cucumber.table.xstream.*; +import cucumber.table.xstream.DataTableWriter; +import cucumber.table.xstream.ListOfListOfSingleValueReader; +import cucumber.table.xstream.ListOfListOfSingleValueWriter; +import cucumber.table.xstream.ListOfMapReader; +import cucumber.table.xstream.ListOfObjectReader; +import cucumber.table.xstream.ListOfObjectWriter; import gherkin.util.Mapper; import java.lang.reflect.ParameterizedType; diff --git a/core/src/test/java/cucumber/formatter/HTMLFormatterTest.java b/core/src/test/java/cucumber/formatter/HTMLFormatterTest.java index d82b226abd..a07faab9de 100644 --- a/core/src/test/java/cucumber/formatter/HTMLFormatterTest.java +++ b/core/src/test/java/cucumber/formatter/HTMLFormatterTest.java @@ -13,7 +13,9 @@ import java.io.FileReader; import java.io.IOException; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; public class HTMLFormatterTest { diff --git a/core/src/test/java/cucumber/formatter/JUnitFormatterTest.java b/core/src/test/java/cucumber/formatter/JUnitFormatterTest.java index ce3986bfff..66c1c9381b 100644 --- a/core/src/test/java/cucumber/formatter/JUnitFormatterTest.java +++ b/core/src/test/java/cucumber/formatter/JUnitFormatterTest.java @@ -45,7 +45,7 @@ private File runFeaturesWithJunitFormatter(final List featurePaths) thro File report = File.createTempFile("cucumber-jvm-junit", "xml"); final ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); final ClasspathResourceLoader resourceLoader = new ClasspathResourceLoader(classLoader); - + List args = new ArrayList(); args.add("--format"); args.add("junit:" + report.getAbsolutePath()); diff --git a/core/src/test/java/cucumber/formatter/TestFormatter.java b/core/src/test/java/cucumber/formatter/TestFormatter.java index 4efa1b2ece..c8cdd91b60 100644 --- a/core/src/test/java/cucumber/formatter/TestFormatter.java +++ b/core/src/test/java/cucumber/formatter/TestFormatter.java @@ -1,7 +1,12 @@ package cucumber.formatter; import gherkin.formatter.Formatter; -import gherkin.formatter.model.*; +import gherkin.formatter.model.Background; +import gherkin.formatter.model.Examples; +import gherkin.formatter.model.Feature; +import gherkin.formatter.model.Scenario; +import gherkin.formatter.model.ScenarioOutline; +import gherkin.formatter.model.Step; import org.junit.Ignore; import java.io.File; diff --git a/core/src/test/java/cucumber/runtime/HookOrderTest.java b/core/src/test/java/cucumber/runtime/HookOrderTest.java index 8268864d00..75906421a9 100644 --- a/core/src/test/java/cucumber/runtime/HookOrderTest.java +++ b/core/src/test/java/cucumber/runtime/HookOrderTest.java @@ -14,7 +14,10 @@ import static java.util.Arrays.asList; import static org.mockito.Matchers.anyListOf; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.inOrder; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; public class HookOrderTest { diff --git a/core/src/test/java/cucumber/runtime/HookTest.java b/core/src/test/java/cucumber/runtime/HookTest.java index 0d7f16e8ef..25b524ff4a 100644 --- a/core/src/test/java/cucumber/runtime/HookTest.java +++ b/core/src/test/java/cucumber/runtime/HookTest.java @@ -17,7 +17,9 @@ import static java.util.Arrays.asList; import static org.mockito.Matchers.anyListOf; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.inOrder; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; public class HookTest { diff --git a/core/src/test/java/cucumber/runtime/StepDefinitionMatchTest.java b/core/src/test/java/cucumber/runtime/StepDefinitionMatchTest.java index f5c1ec95eb..3be49ef9b1 100644 --- a/core/src/test/java/cucumber/runtime/StepDefinitionMatchTest.java +++ b/core/src/test/java/cucumber/runtime/StepDefinitionMatchTest.java @@ -13,7 +13,9 @@ import java.util.List; import static java.util.Arrays.asList; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; public class StepDefinitionMatchTest { private final ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); diff --git a/core/src/test/java/cucumber/runtime/UtilsTest.java b/core/src/test/java/cucumber/runtime/UtilsTest.java index f69fd4d66d..aa72516f74 100644 --- a/core/src/test/java/cucumber/runtime/UtilsTest.java +++ b/core/src/test/java/cucumber/runtime/UtilsTest.java @@ -2,8 +2,12 @@ import org.junit.Test; -import static cucumber.runtime.Utils.*; -import static org.junit.Assert.*; +import static cucumber.runtime.Utils.isInstantiable; +import static cucumber.runtime.Utils.packageName; +import static cucumber.runtime.Utils.packagePath; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; public class UtilsTest { @Test diff --git a/core/src/test/java/cucumber/runtime/model/CucumberExamplesTest.java b/core/src/test/java/cucumber/runtime/model/CucumberExamplesTest.java index b14c198a83..d7c7941056 100644 --- a/core/src/test/java/cucumber/runtime/model/CucumberExamplesTest.java +++ b/core/src/test/java/cucumber/runtime/model/CucumberExamplesTest.java @@ -1,6 +1,12 @@ package cucumber.runtime.model; -import gherkin.formatter.model.*; +import gherkin.formatter.model.Comment; +import gherkin.formatter.model.Examples; +import gherkin.formatter.model.ExamplesTableRow; +import gherkin.formatter.model.Feature; +import gherkin.formatter.model.ScenarioOutline; +import gherkin.formatter.model.Step; +import gherkin.formatter.model.Tag; import org.junit.Test; import java.util.HashSet; diff --git a/core/src/test/java/cucumber/runtime/model/CucumberScenarioOutlineTest.java b/core/src/test/java/cucumber/runtime/model/CucumberScenarioOutlineTest.java index 796b628d31..addee5077c 100644 --- a/core/src/test/java/cucumber/runtime/model/CucumberScenarioOutlineTest.java +++ b/core/src/test/java/cucumber/runtime/model/CucumberScenarioOutlineTest.java @@ -1,6 +1,10 @@ package cucumber.runtime.model; -import gherkin.formatter.model.*; +import gherkin.formatter.model.Comment; +import gherkin.formatter.model.DataTableRow; +import gherkin.formatter.model.DocString; +import gherkin.formatter.model.ExamplesTableRow; +import gherkin.formatter.model.Step; import org.junit.Test; import java.util.ArrayList; diff --git a/core/src/test/java/cucumber/table/FromDataTableTest.java b/core/src/test/java/cucumber/table/FromDataTableTest.java index ca0c248caa..9d6ab696f8 100644 --- a/core/src/test/java/cucumber/table/FromDataTableTest.java +++ b/core/src/test/java/cucumber/table/FromDataTableTest.java @@ -23,7 +23,12 @@ import org.junit.rules.ExpectedException; import java.lang.reflect.Method; -import java.util.*; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Date; +import java.util.List; +import java.util.Map; +import java.util.TimeZone; import static java.util.Arrays.asList; import static java.util.Collections.emptyList; diff --git a/java/pom.xml b/java/pom.xml index a63e614cbf..0da1b91760 100644 --- a/java/pom.xml +++ b/java/pom.xml @@ -1,4 +1,5 @@ - + 4.0.0 @@ -54,7 +55,8 @@ generate-sources - + + 4.0.0 diff --git a/junit/src/main/java/cucumber/junit/JUnitReporter.java b/junit/src/main/java/cucumber/junit/JUnitReporter.java index 8fa6cb4efd..60958cc635 100644 --- a/junit/src/main/java/cucumber/junit/JUnitReporter.java +++ b/junit/src/main/java/cucumber/junit/JUnitReporter.java @@ -3,7 +3,13 @@ import cucumber.runtime.PendingException; import gherkin.formatter.Formatter; import gherkin.formatter.Reporter; -import gherkin.formatter.model.*; +import gherkin.formatter.model.Background; +import gherkin.formatter.model.Examples; +import gherkin.formatter.model.Match; +import gherkin.formatter.model.Result; +import gherkin.formatter.model.Scenario; +import gherkin.formatter.model.ScenarioOutline; +import gherkin.formatter.model.Step; import org.junit.internal.runners.model.EachTestNotifier; import org.junit.runner.Description; import org.junit.runner.notification.RunNotifier; diff --git a/junit/src/main/java/cucumber/junit/RuntimeOptionsFactory.java b/junit/src/main/java/cucumber/junit/RuntimeOptionsFactory.java index a2706bc416..457c253419 100644 --- a/junit/src/main/java/cucumber/junit/RuntimeOptionsFactory.java +++ b/junit/src/main/java/cucumber/junit/RuntimeOptionsFactory.java @@ -2,7 +2,6 @@ import cucumber.runtime.RuntimeOptions; -import java.lang.annotation.Annotation; import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -29,21 +28,20 @@ public RuntimeOptions create() { } - private Cucumber.Options getFeatureAnnotation(Class clazz) { - Annotation annotation = clazz.getAnnotation(Cucumber.Options.class); - return Cucumber.Options.class.cast(annotation); + private Cucumber.Options getFeatureAnnotation(Class clazz) { + return clazz.getAnnotation(Cucumber.Options.class); } private void addDryRun(Cucumber.Options options, List args) { - if(options != null) { - if(options.dryRun()) { + if (options != null) { + if (options.dryRun()) { args.add("--dry-run"); } } } private void addGlue(Cucumber.Options options, Class clazz, List args) { - if(options != null && options.glue().length != 0) { + if (options != null && options.glue().length != 0) { for (String glue : options.glue()) { args.add("--glue"); args.add(glue); @@ -55,7 +53,7 @@ private void addGlue(Cucumber.Options options, Class clazz, List args) { } private void addFeatures(Cucumber.Options options, Class clazz, List args) { - if(options != null && options.features().length != 0) { + if (options != null && options.features().length != 0) { Collections.addAll(args, options.features()); } else { args.add(packagePath(clazz)); @@ -63,7 +61,7 @@ private void addFeatures(Cucumber.Options options, Class clazz, List arg } private void addTags(Cucumber.Options options, List args) { - if(options != null) { + if (options != null) { for (String tags : options.tags()) { args.add("--tags"); args.add(tags); diff --git a/junit/src/test/java/cucumber/junit/CucumberTest.java b/junit/src/test/java/cucumber/junit/CucumberTest.java index d42ebb9bde..5b39000ae4 100644 --- a/junit/src/test/java/cucumber/junit/CucumberTest.java +++ b/junit/src/test/java/cucumber/junit/CucumberTest.java @@ -52,11 +52,11 @@ public void finds_no_features_when_explicit_package_has_nothnig() throws IOExcep private class ImplicitPackage { } - @Cucumber.Options(features={"cucumber/junit"}) + @Cucumber.Options(features = {"cucumber/junit"}) private class ExplicitPackage { } - @Cucumber.Options(features={"gibber/ish"}) + @Cucumber.Options(features = {"gibber/ish"}) private class ExplicitPackageWithNoFeatures { } } diff --git a/junit/src/test/java/cucumber/junit/JUnitReporterTest.java b/junit/src/test/java/cucumber/junit/JUnitReporterTest.java index a539187c1b..68d2c48170 100644 --- a/junit/src/test/java/cucumber/junit/JUnitReporterTest.java +++ b/junit/src/test/java/cucumber/junit/JUnitReporterTest.java @@ -11,7 +11,9 @@ import org.mockito.ArgumentCaptor; import static org.junit.Assert.assertEquals; -import static org.mockito.Mockito.*; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; public class JUnitReporterTest { diff --git a/picocontainer/pom.xml b/picocontainer/pom.xml index a60d01e604..c49de2aa19 100644 --- a/picocontainer/pom.xml +++ b/picocontainer/pom.xml @@ -1,4 +1,5 @@ - + 4.0.0 @@ -73,15 +74,16 @@ - - - - - - - - - + + + + + + + + + diff --git a/pom.xml b/pom.xml index 9c60f6ad92..6b605be52b 100644 --- a/pom.xml +++ b/pom.xml @@ -17,7 +17,7 @@ UTF-8 ${project.build.directory} - 2.9.0 + 2.9.1 2.0.0-beta-2