Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Implemented a plugin for Cucumber

  • Loading branch information...
commit 2faa915903229b14e4f1079c92ddf0fa4d257273 1 parent e5cc8a2
@vasiliygagin vasiliygagin authored
Showing with 788 additions and 80 deletions.
  1. +4 −0 junitrunner-cucumber/.gitignore
  2. +29 −0 junitrunner-cucumber/pom.xml
  3. +32 −0 junitrunner-cucumber/src/main/java/com/github/junitrunner/cucumber/CucumberExamplesSuite.java
  4. +44 −0 junitrunner-cucumber/src/main/java/com/github/junitrunner/cucumber/CucumberFeatureSuite.java
  5. +79 −0 junitrunner-cucumber/src/main/java/com/github/junitrunner/cucumber/CucumberPlugin.java
  6. +33 −0 junitrunner-cucumber/src/main/java/com/github/junitrunner/cucumber/CucumberRunner.java
  7. +45 −0 junitrunner-cucumber/src/main/java/com/github/junitrunner/cucumber/CucumberRunnerListener.java
  8. +30 −0 junitrunner-cucumber/src/main/java/com/github/junitrunner/cucumber/CucumberScenarioOutlineSuite.java
  9. +146 −0 junitrunner-cucumber/src/main/java/com/github/junitrunner/cucumber/CucumberScenarioTest.java
  10. +61 −0 junitrunner-cucumber/src/main/java/com/github/junitrunner/cucumber/CucumberStep.java
  11. +64 −0 junitrunner-cucumber/src/main/java/com/github/junitrunner/cucumber/FormatterDelegate.java
  12. +38 −0 junitrunner-cucumber/src/main/java/com/github/junitrunner/cucumber/ReporterDelegate.java
  13. +11 −0 junitrunner-cucumber/src/test/java/com/github/junitrunner/cucumber/Cucumber_Runner_Test.java
  14. +38 −0 junitrunner-cucumber/src/test/java/com/github/junitrunner/cucumber/TestStepDefs.java
  15. +18 −0 junitrunner-cucumber/src/test/resources/com/github/junitrunner/cucumber/test.feature
  16. +1 −1  junitrunner-mockito/pom.xml
  17. +1 −1  junitrunner-spring/pom.xml
  18. +1 −1  junitrunner-unitils/pom.xml
  19. +5 −3 junitrunner/src/main/java/com/github/junitrunner/JUnitRunner.java
  20. +0 −5 junitrunner/src/main/java/com/github/junitrunner/JUnitStep.java
  21. +1 −20 junitrunner/src/main/java/com/github/junitrunner/JUnitTask.java
  22. +22 −17 junitrunner/src/main/java/com/github/junitrunner/RunNotifierWrapper.java
  23. +24 −0 junitrunner/src/main/java/com/github/junitrunner/StepRunnerListenerDelegate.java
  24. +26 −0 junitrunner/src/main/java/com/github/junitrunner/Task.java
  25. +6 −5 junitrunner/src/main/java/com/github/junitrunner/listener/BaseRunnerListener.java
  26. +5 −5 junitrunner/src/main/java/com/github/junitrunner/listener/RunnerListener.java
  27. +11 −10 junitrunner/src/main/java/com/github/junitrunner/listener/RunnerListenerContainer.java
  28. +12 −12 junitrunner/src/main/java/com/github/junitrunner/plugin/annotation/AnnotationTestRuleFactory.java
  29. +1 −0  pom.xml
View
4 junitrunner-cucumber/.gitignore
@@ -0,0 +1,4 @@
+.settings
+.classpath
+.project
+target
View
29 junitrunner-cucumber/pom.xml
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <groupId>com.github.junitrunner</groupId>
+ <artifactId>junitrunner-cucumber</artifactId>
+ <version>0.0.2-SNAPSHOT</version>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>com.github.junitrunner</groupId>
+ <artifactId>junitrunner</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>info.cukes</groupId>
+ <artifactId>cucumber-junit</artifactId>
+ <version>1.1.5</version>
+ </dependency>
+ <dependency>
+ <groupId>info.cukes</groupId>
+ <artifactId>cucumber-java</artifactId>
+ <version>1.1.5</version>
+ </dependency>
+ </dependencies>
+
+</project>
View
32 ...trunner-cucumber/src/main/java/com/github/junitrunner/cucumber/CucumberExamplesSuite.java
@@ -0,0 +1,32 @@
+package com.github.junitrunner.cucumber;
+
+import java.util.List;
+
+import org.junit.runner.Description;
+
+import com.github.junitrunner.JUnitSuite;
+
+import cucumber.runtime.Runtime;
+import cucumber.runtime.model.CucumberExamples;
+import cucumber.runtime.model.CucumberScenario;
+
+public class CucumberExamplesSuite extends JUnitSuite {
+
+ private final CucumberExamples cucumberExamples;
+
+ public CucumberExamplesSuite(Class<?> testClass, Runtime runtime, CucumberExamples cucumberExamples, CucumberPlugin cucumberPlugin) {
+ super(testClass);
+ this.cucumberExamples = cucumberExamples;
+
+ List<CucumberScenario> exampleScenarios = cucumberExamples.createExampleScenarios();
+ for (CucumberScenario scenario : exampleScenarios) {
+ super.addTask(new CucumberScenarioTest(runtime, scenario, cucumberPlugin));
+ }
+ }
+
+ @Override
+ protected Description describeSelf() {
+ return Description.createSuiteDescription(cucumberExamples.getExamples().getKeyword() + ": " + cucumberExamples.getExamples().getName(),
+ cucumberExamples.getExamples());
+ }
+}
View
44 junitrunner-cucumber/src/main/java/com/github/junitrunner/cucumber/CucumberFeatureSuite.java
@@ -0,0 +1,44 @@
+package com.github.junitrunner.cucumber;
+
+import gherkin.formatter.model.Feature;
+
+import org.junit.runner.Description;
+
+import com.github.junitrunner.JUnitSuite;
+
+import cucumber.runtime.Runtime;
+import cucumber.runtime.model.CucumberFeature;
+import cucumber.runtime.model.CucumberScenario;
+import cucumber.runtime.model.CucumberScenarioOutline;
+import cucumber.runtime.model.CucumberTagStatement;
+
+public class CucumberFeatureSuite extends JUnitSuite {
+
+ final CucumberPlugin cucumberPlugin;
+
+ final CucumberFeature cucumberFeature;
+
+ public CucumberFeatureSuite(Class<?> testClass, CucumberPlugin cucumberPlugin, CucumberFeature cucumberFeature, Runtime runtime) {
+ super(testClass);
+ this.cucumberPlugin = cucumberPlugin;
+ this.cucumberFeature = cucumberFeature;
+
+ for (CucumberTagStatement cucumberTagStatement : cucumberFeature.getFeatureElements()) {
+ if (cucumberTagStatement instanceof CucumberScenario) {
+ addTask(new CucumberScenarioTest(runtime, (CucumberScenario)cucumberTagStatement, cucumberPlugin));
+ } else {
+ addTask(new CucumberScenarioOutlineSuite(testClass, runtime, (CucumberScenarioOutline)cucumberTagStatement, cucumberPlugin));
+ }
+ }
+ }
+
+ @Override
+ protected Description describeSelf() {
+ return Description.createSuiteDescription(getFeatureName(), cucumberFeature.getGherkinFeature());
+ }
+
+ private String getFeatureName() {
+ Feature feature = cucumberFeature.getGherkinFeature();
+ return feature.getKeyword() + ": " + feature.getName();
+ }
+}
View
79 junitrunner-cucumber/src/main/java/com/github/junitrunner/cucumber/CucumberPlugin.java
@@ -0,0 +1,79 @@
+package com.github.junitrunner.cucumber;
+
+import gherkin.formatter.Formatter;
+import gherkin.formatter.Reporter;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.runner.notification.RunNotifier;
+
+import com.github.junitrunner.JUnitBasePlugin;
+import com.github.junitrunner.JUnitRunner;
+import com.github.junitrunner.JUnitTask;
+import com.github.junitrunner.StepRunnerListenerDelegate;
+
+import cucumber.api.CucumberOptions;
+import cucumber.api.junit.Cucumber.Options;
+import cucumber.runtime.ClassFinder;
+import cucumber.runtime.Runtime;
+import cucumber.runtime.RuntimeOptions;
+import cucumber.runtime.RuntimeOptionsFactory;
+import cucumber.runtime.io.MultiLoader;
+import cucumber.runtime.io.ResourceLoader;
+import cucumber.runtime.io.ResourceLoaderClassFinder;
+import cucumber.runtime.junit.Assertions;
+import cucumber.runtime.model.CucumberFeature;
+
+public class CucumberPlugin extends JUnitBasePlugin {
+
+ private final Class<?> testClass;
+
+ Reporter reporter;
+ Formatter formatter;
+ boolean strict;
+
+ private Runtime runtime;
+ private List<CucumberFeature> cucumberFeatures;
+
+ // TODO remove notifier
+ RunNotifier notifier;
+
+ StepRunnerListenerDelegate stepRunnerListenerDelegate;
+
+ public CucumberPlugin(Class<?> testClass) {
+ this.testClass = testClass;
+ }
+
+ public void plug(JUnitRunner jUnitRunner) {
+
+ ClassLoader classLoader = testClass.getClassLoader();
+ Assertions.assertNoCucumberAnnotatedMethods(testClass);
+
+ RuntimeOptionsFactory runtimeOptionsFactory = new RuntimeOptionsFactory(testClass, new Class[] { CucumberOptions.class, Options.class });
+ RuntimeOptions runtimeOptions = runtimeOptionsFactory.create();
+
+ ResourceLoader resourceLoader = new MultiLoader(classLoader);
+ ClassFinder classFinder = new ResourceLoaderClassFinder(resourceLoader, classLoader);
+ runtime = new Runtime(resourceLoader, classFinder, classLoader, runtimeOptions);
+
+ reporter = runtimeOptions.reporter(classLoader);
+ formatter = runtimeOptions.formatter(classLoader);
+ strict = runtimeOptions.isStrict();
+
+ jUnitRunner.registerListener(new CucumberRunnerListener(formatter, runtime));
+
+ cucumberFeatures = runtimeOptions.cucumberFeatures(resourceLoader);
+
+ stepRunnerListenerDelegate = jUnitRunner.getStepRunnerListenerDelegate();
+ }
+
+ public List<JUnitTask> createTasks(List<Throwable> errors) {
+
+ List<JUnitTask> result = new ArrayList<JUnitTask>();
+ for (CucumberFeature cucumberFeature : cucumberFeatures) {
+ result.add(new CucumberFeatureSuite(testClass, this, cucumberFeature, runtime));
+ }
+ return result;
+ }
+}
View
33 junitrunner-cucumber/src/main/java/com/github/junitrunner/cucumber/CucumberRunner.java
@@ -0,0 +1,33 @@
+package com.github.junitrunner.cucumber;
+
+import java.util.List;
+
+import org.junit.runner.notification.RunNotifier;
+import org.junit.runners.model.InitializationError;
+
+import com.github.junitrunner.JUnitPlugin;
+import com.github.junitrunner.JUnitRunner;
+
+public class CucumberRunner extends JUnitRunner {
+
+ private CucumberPlugin cucumberPlugin;
+
+ public CucumberRunner(Class<?> clazz) throws InitializationError {
+ super(clazz);
+ }
+
+ @Override
+ protected List<JUnitPlugin> discoverPlugins() throws InitializationError {
+ List<JUnitPlugin> plugins = super.discoverPlugins();
+ cucumberPlugin = new CucumberPlugin(testClass);
+ plugins.add(cucumberPlugin);
+ return plugins;
+ }
+
+ // TODO remove
+ @Override
+ public void run(RunNotifier notifier) {
+ cucumberPlugin.notifier = notifier;
+ super.run(notifier);
+ }
+}
View
45 ...runner-cucumber/src/main/java/com/github/junitrunner/cucumber/CucumberRunnerListener.java
@@ -0,0 +1,45 @@
+package com.github.junitrunner.cucumber;
+
+import gherkin.formatter.Formatter;
+
+import org.junit.runner.Description;
+
+import com.github.junitrunner.Task;
+import com.github.junitrunner.listener.BaseRunnerListener;
+
+import cucumber.runtime.Runtime;
+import cucumber.runtime.snippets.SummaryPrinter;
+
+public class CucumberRunnerListener extends BaseRunnerListener {
+
+ private final Formatter formatter;
+ private final Runtime runtime;
+
+ public CucumberRunnerListener(Formatter formatter, Runtime runtime) {
+ this.formatter = formatter;
+ this.runtime = runtime;
+ }
+
+ @Override
+ public void testClassFinished(Description description) {
+ formatter.done();
+ formatter.close();
+ new SummaryPrinter(System.out).print(runtime);
+ }
+
+ @Override
+ public void taskStarted(Task task) {
+ if (task instanceof CucumberFeatureSuite) {
+ CucumberFeatureSuite feature = (CucumberFeatureSuite) task;
+ formatter.uri(feature.cucumberFeature.getUri());
+ formatter.feature(feature.cucumberFeature.getGherkinFeature());
+ }
+ }
+
+ @Override
+ public void taskFinished(Task task, Throwable failure) {
+ if (task instanceof CucumberFeatureSuite) {
+ formatter.eof();
+ }
+ }
+}
View
30 ...-cucumber/src/main/java/com/github/junitrunner/cucumber/CucumberScenarioOutlineSuite.java
@@ -0,0 +1,30 @@
+package com.github.junitrunner.cucumber;
+
+import org.junit.runner.Description;
+
+import com.github.junitrunner.JUnitSuite;
+
+import cucumber.runtime.Runtime;
+import cucumber.runtime.model.CucumberExamples;
+import cucumber.runtime.model.CucumberScenarioOutline;
+
+public class CucumberScenarioOutlineSuite extends JUnitSuite {
+
+ private final CucumberScenarioOutline cucumberScenarioOutline;
+
+ public CucumberScenarioOutlineSuite(Class<?> testClass, Runtime runtime, CucumberScenarioOutline cucumberScenarioOutline,
+ CucumberPlugin cucumberPlugin) {
+ super(testClass);
+ this.cucumberScenarioOutline = cucumberScenarioOutline;
+
+ for (CucumberExamples cucumberExamples : cucumberScenarioOutline.getCucumberExamplesList()) {
+ CucumberExamplesSuite examplesSuite = new CucumberExamplesSuite(testClass, runtime, cucumberExamples, cucumberPlugin);
+ super.addTask(examplesSuite);
+ }
+ }
+
+ @Override
+ protected Description describeSelf() {
+ return Description.createSuiteDescription(cucumberScenarioOutline.getVisualName(), cucumberScenarioOutline.getGherkinModel());
+ }
+}
View
146 junitrunner-cucumber/src/main/java/com/github/junitrunner/cucumber/CucumberScenarioTest.java
@@ -0,0 +1,146 @@
+package com.github.junitrunner.cucumber;
+
+import static cucumber.runtime.Runtime.*;
+import gherkin.formatter.Formatter;
+import gherkin.formatter.Reporter;
+import gherkin.formatter.model.Match;
+import gherkin.formatter.model.Result;
+import gherkin.formatter.model.Step;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.junit.internal.runners.model.EachTestNotifier;
+import org.junit.runner.Description;
+
+import com.github.junitrunner.JUnitTest;
+import com.github.junitrunner.StepRunnerListenerDelegate;
+
+import cucumber.api.PendingException;
+import cucumber.runtime.Runtime;
+import cucumber.runtime.model.CucumberBackground;
+import cucumber.runtime.model.CucumberScenario;
+
+public class CucumberScenarioTest extends JUnitTest {
+
+ private final CucumberPlugin cucumberPlugin;
+
+ private final Runtime runtime;
+ private final CucumberScenario cucumberScenario;
+ private final CucumberBackground cucumberBackground;
+ private final List<Step> backgroundSteps;
+ private final Map<Step, CucumberStep> stepsMap = new HashMap<Step, CucumberStep>();
+
+ private final List<CucumberStep> steps = new ArrayList<CucumberStep>();
+ private final List<CucumberStep> stepsQueue = new ArrayList<CucumberStep>();
+
+ private String scenarioName;
+ private StepRunnerListenerDelegate stepRunnerListenerContainer;
+ private Throwable stepFailure = null;
+
+ public CucumberScenarioTest(Runtime runtime, CucumberScenario scenario, CucumberPlugin cucumberPlugin) {
+ this.cucumberPlugin = cucumberPlugin;
+
+ this.runtime = runtime;
+ this.cucumberScenario = scenario;
+ this.cucumberBackground = scenario.getCucumberBackground();
+ stepRunnerListenerContainer = cucumberPlugin.stepRunnerListenerDelegate;
+ if (cucumberBackground != null) {
+ backgroundSteps = cucumberBackground.getSteps();
+ for (Step step : backgroundSteps) {
+ registerStep(step);
+ }
+ } else {
+ backgroundSteps = new ArrayList<Step>(0);
+ }
+ for (Step step : cucumberScenario.getSteps()) {
+ registerStep(step);
+ }
+ scenarioName = cucumberScenario.getVisualName();
+ }
+
+ private void registerStep(Step step) {
+ CucumberStep cucumberStep = new CucumberStep(step, scenarioName, cucumberPlugin.strict, stepRunnerListenerContainer);
+ steps.add(cucumberStep);
+ stepsMap.put(step, cucumberStep);
+ }
+
+ @Override
+ public Description createDescription() {
+ Description description = Description.createSuiteDescription(scenarioName, cucumberScenario.getGherkinModel());
+
+ for (CucumberStep step : steps) {
+ description.addChild(step.describe());
+ }
+ return description;
+ }
+
+ @Override
+ protected void invoke(Object testObject) throws Throwable {
+
+ Formatter formatter = new FormatterDelegate(cucumberPlugin.formatter) {
+
+ @Override
+ public void step(Step step) {
+ stepsQueue.add(stepsMap.get(step));
+ super.step(step);
+ }
+ };
+
+ Reporter reporter = new ReporterDelegate(cucumberPlugin.reporter) {
+
+ public void result(Result result) {
+ CucumberStep currentStep = stepsQueue.remove(0);
+ currentStep.stepRun(result);
+ stepRun(result);
+ super.result(result);
+ }
+
+ public void before(Match match, Result result) {
+ handleHook(result);
+ super.before(match, result);
+ }
+
+ public void after(Match match, Result result) {
+ handleHook(result);
+ super.after(match, result);
+ }
+ };
+
+ cucumberScenario.run(formatter, reporter, runtime);
+
+ if (stepFailure != null) {
+ throw stepFailure;
+ }
+ }
+
+ private void stepRun(Result result) {
+
+ Throwable error = getFailure(result);
+ if (error != null) {
+ stepFailure = error;
+ }
+ }
+
+ private Throwable getFailure(Result result) {
+ Throwable error = result.getError();
+ if (Result.SKIPPED == result) {
+ } else if (Result.UNDEFINED == result || isPending(error)) {
+ if (CucumberScenarioTest.this.cucumberPlugin.strict) {
+ if (error == null) {
+ error = new PendingException();
+ }
+ }
+ }
+ return error;
+ }
+
+ private void handleHook(Result result) {
+ if (result.getStatus().equals(Result.FAILED)) {
+ EachTestNotifier executionUnitNotifier = new EachTestNotifier(cucumberPlugin.notifier, describe());
+ executionUnitNotifier.addFailure(result.getError());
+ }
+ }
+}
View
61 junitrunner-cucumber/src/main/java/com/github/junitrunner/cucumber/CucumberStep.java
@@ -0,0 +1,61 @@
+package com.github.junitrunner.cucumber;
+
+import static cucumber.runtime.Runtime.*;
+import gherkin.formatter.model.Result;
+import gherkin.formatter.model.Step;
+
+import java.io.Serializable;
+
+import org.junit.runner.Description;
+
+import com.github.junitrunner.Task;
+import com.github.junitrunner.StepRunnerListenerDelegate;
+
+import cucumber.api.PendingException;
+
+public class CucumberStep extends Task implements Serializable {
+
+ private static final long serialVersionUID = 1L;
+
+ private final Step step;
+ private final String scenarioName;
+ private final boolean strict;
+ private final StepRunnerListenerDelegate stepRunnerListenerContainer;
+
+ public CucumberStep(Step step, String scenarioName, boolean strict, StepRunnerListenerDelegate stepRunnerListenerContainer) {
+ this.step = step;
+ this.scenarioName = scenarioName;
+ this.strict = strict;
+ this.stepRunnerListenerContainer = stepRunnerListenerContainer;
+ }
+
+ @Override
+ public Description createDescription() {
+ return Description.createTestDescription(scenarioName, step.getKeyword() + step.getName(), this);
+ }
+
+ public void stepRun(Result result) {
+
+ Description currentStepDescription = describe();
+ Throwable error = result.getError();
+ if (Result.SKIPPED == result) {
+ stepRunnerListenerContainer.stepIgnored(this);
+ } else if (Result.UNDEFINED == result || isPending(error)) {
+ if (strict) {
+ if (error == null) {
+ error = new PendingException();
+ }
+ stepRunnerListenerContainer.stepStarted(this);
+ stepRunnerListenerContainer.stepFinished(this, error); // finish not fired
+ } else {
+ ignore();
+ stepRunnerListenerContainer.stepIgnored(this);
+ }
+ } else {
+ if (currentStepDescription != null) {
+ stepRunnerListenerContainer.stepStarted(this);
+ stepRunnerListenerContainer.stepFinished(this, error);
+ }
+ }
+ }
+}
View
64 junitrunner-cucumber/src/main/java/com/github/junitrunner/cucumber/FormatterDelegate.java
@@ -0,0 +1,64 @@
+package com.github.junitrunner.cucumber;
+
+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 java.util.List;
+
+public class FormatterDelegate implements Formatter {
+
+ private Formatter delegate;
+
+ public FormatterDelegate(Formatter delegate) {
+ this.delegate = delegate;
+ }
+
+ public void uri(String uri) {
+ delegate.uri(uri);
+ }
+
+ public void feature(Feature feature) {
+ delegate.feature(feature);
+ }
+
+ public void background(Background background) {
+ delegate.background(background);
+ }
+
+ public void scenario(Scenario scenario) {
+ delegate.scenario(scenario);
+ }
+
+ public void scenarioOutline(ScenarioOutline scenarioOutline) {
+ delegate.scenarioOutline(scenarioOutline);
+ }
+
+ public void examples(Examples examples) {
+ delegate.examples(examples);
+ }
+
+ public void step(Step step) {
+ delegate.step(step);
+ }
+
+ public void eof() {
+ delegate.eof();
+ }
+
+ public void syntaxError(String state, String event, List<String> legalEvents, String uri, Integer line) {
+ delegate.syntaxError(state, event, legalEvents, uri, line);
+ }
+
+ public void done() {
+ delegate.done();
+ }
+
+ public void close() {
+ delegate.close();
+ }
+}
View
38 junitrunner-cucumber/src/main/java/com/github/junitrunner/cucumber/ReporterDelegate.java
@@ -0,0 +1,38 @@
+package com.github.junitrunner.cucumber;
+
+import gherkin.formatter.Reporter;
+import gherkin.formatter.model.Match;
+import gherkin.formatter.model.Result;
+
+public class ReporterDelegate implements Reporter {
+
+ private final Reporter delegate;
+
+ public ReporterDelegate(Reporter delegate) {
+ this.delegate = delegate;
+ }
+
+ public void before(Match match, Result result) {
+ delegate.before(match, result);
+ }
+
+ public void result(Result result) {
+ delegate.result(result);
+ }
+
+ public void after(Match match, Result result) {
+ delegate.after(match, result);
+ }
+
+ public void match(Match match) {
+ delegate.match(match);
+ }
+
+ public void embedding(String mimeType, byte[] data) {
+ delegate.embedding(mimeType, data);
+ }
+
+ public void write(String text) {
+ delegate.write(text);
+ }
+}
View
11 junitrunner-cucumber/src/test/java/com/github/junitrunner/cucumber/Cucumber_Runner_Test.java
@@ -0,0 +1,11 @@
+package com.github.junitrunner.cucumber;
+
+import org.junit.runner.RunWith;
+
+import cucumber.api.CucumberOptions;
+
+@RunWith(CucumberRunner.class)
+@CucumberOptions(format = "pretty")
+public class Cucumber_Runner_Test {
+
+}
View
38 junitrunner-cucumber/src/test/java/com/github/junitrunner/cucumber/TestStepDefs.java
@@ -0,0 +1,38 @@
+package com.github.junitrunner.cucumber;
+
+import cucumber.api.java.en.Given;
+import cucumber.api.java.en.Then;
+import cucumber.api.java.en.When;
+
+public class TestStepDefs {
+
+ @Given("^background$")
+ public void background() throws Throwable {
+ // do background
+ }
+
+ @Given("^step 1$")
+ public void step1() throws Throwable {
+ // Express the Regexp above with the code you wish you had
+ }
+
+ @Then("^step 2$")
+ public void step2() throws Throwable {
+ // Express the Regexp above with the code you wish you had
+ }
+
+ @Given("^there are (\\d+) cucumbers$")
+ public void there_are_cucumbers(int arg1) throws Throwable {
+ // Express the Regexp above with the code you wish you had
+ }
+
+ @When("^I eat (\\d+) cucumbers$")
+ public void I_eat_cucumbers(int arg1) throws Throwable {
+ // Express the Regexp above with the code you wish you had
+ }
+
+ @Then("^I should have (\\d+) cucumbers$")
+ public void I_should_have_cucumbers(int arg1) throws Throwable {
+ // Express the Regexp above with the code you wish you had
+ }
+}
View
18 junitrunner-cucumber/src/test/resources/com/github/junitrunner/cucumber/test.feature
@@ -0,0 +1,18 @@
+Feature: Test
+
+ Background:
+ Given background
+
+ Scenario: Simple
+ Given step 1
+ Then step 2
+
+ Scenario Outline: outline
+ Given there are <start> cucumbers
+ When I eat <eat> cucumbers
+ Then I should have <left> cucumbers
+
+ Examples:
+ | start | eat | left |
+ | 12 | 5 | 7 |
+ | 20 | 5 | 15 |
View
2  junitrunner-mockito/pom.xml
@@ -18,7 +18,7 @@
<dependency>
<groupId>com.github.junitrunner</groupId>
<artifactId>junitrunner</artifactId>
- <version>0.0.2-SNAPSHOT</version>
+ <version>${project.version}</version>
</dependency>
<dependency>
View
2  junitrunner-spring/pom.xml
@@ -18,7 +18,7 @@
<dependency>
<groupId>com.github.junitrunner</groupId>
<artifactId>junitrunner</artifactId>
- <version>0.0.2-SNAPSHOT</version>
+ <version>${project.version}</version>
</dependency>
<dependency>
View
2  junitrunner-unitils/pom.xml
@@ -18,7 +18,7 @@
<dependency>
<groupId>com.github.junitrunner</groupId>
<artifactId>junitrunner</artifactId>
- <version>0.0.2-SNAPSHOT</version>
+ <version>${project.version}</version>
</dependency>
<dependency>
View
8 junitrunner/src/main/java/com/github/junitrunner/JUnitRunner.java
@@ -114,9 +114,7 @@ private void processPlugins() throws InitializationError {
private void computeClassStatement(List<Throwable> errors) {
- /*
- * children are not registered yet, calling getDescription() will cache incomplete description
- */
+ /* children are not registered yet, calling getDescription() will cache incomplete description */
Description description = suite.describeSelf();
Statement statement = suite.constructInvokeStatement(this);
@@ -253,4 +251,8 @@ public void evaluate() throws Throwable {
}
};
}
+
+ public StepRunnerListenerDelegate getStepRunnerListenerDelegate() {
+ return new StepRunnerListenerDelegate(listenerContainer);
+ }
}
View
5 junitrunner/src/main/java/com/github/junitrunner/JUnitStep.java
@@ -1,5 +0,0 @@
-package com.github.junitrunner;
-
-public class JUnitStep {
-
-}
View
21 junitrunner/src/main/java/com/github/junitrunner/JUnitTask.java
@@ -6,23 +6,13 @@
import org.junit.runner.manipulation.Filter;
import org.junit.runners.model.Statement;
-public abstract class JUnitTask {
+public abstract class JUnitTask extends Task {
- private boolean ignored;
private boolean filteredOut;
- protected Description description;
protected JUnitTask() {
}
- public boolean isIgnored() {
- return ignored;
- }
-
- public void ignore() {
- ignored = true;
- }
-
public boolean isFilteredOut() {
return filteredOut;
}
@@ -31,15 +21,6 @@ protected void filterOut() {
filteredOut = true;
}
- public final Description describe() {
- if (description == null) {
- description = createDescription();
- }
- return description;
- }
-
- public abstract Description createDescription();
-
protected abstract Statement constructInvokeStatement(JUnitRunner jUnitRunner);
protected void filterTask(Filter filter) {
View
39 junitrunner/src/main/java/com/github/junitrunner/RunNotifierWrapper.java
@@ -4,6 +4,7 @@
import org.junit.runner.Description;
import org.junit.runner.notification.Failure;
import org.junit.runner.notification.RunNotifier;
+import org.junit.runners.model.MultipleFailureException;
import com.github.junitrunner.listener.BaseRunnerListener;
@@ -16,30 +17,34 @@ public RunNotifierWrapper(RunNotifier runNotifier) {
}
@Override
- public void testIgnored(JUnitTask test) {
- runNotifier.fireTestIgnored(test.describe());
+ public void taskIgnored(Task task) {
+ runNotifier.fireTestIgnored(task.describe());
}
@Override
- public void taskStarted(JUnitTask task) {
- if (task instanceof JUnitTest) {
- runNotifier.fireTestStarted(task.describe());
- }
+ public void taskStarted(Task task) {
+ runNotifier.fireTestStarted(task.describe());
}
@Override
- public void taskFinished(JUnitTask task, Throwable failure) {
- if (task instanceof JUnitTest) {
- if (failure != null) {
- Description description = task.describe();
- if (failure instanceof AssumptionViolatedException) {
- runNotifier.fireTestAssumptionFailed(new Failure(description, failure));
- } else {
- runNotifier.fireTestFailure(new Failure(description, failure));
- }
- }
+ public void taskFinished(Task task, Throwable failure) {
+ if (failure != null) {
+ fireFailure(task, failure);
+ }
+ runNotifier.fireTestFinished(task.describe());
+ }
+
+ private void fireFailure(Task task, Throwable failure) {
- runNotifier.fireTestFinished(task.describe());
+ Description description = task.describe();
+ if (failure instanceof MultipleFailureException) {
+ for (Throwable each : ((MultipleFailureException) failure).getFailures()) {
+ fireFailure(task, each);
+ }
+ } else if (failure instanceof AssumptionViolatedException) {
+ runNotifier.fireTestAssumptionFailed(new Failure(description, failure));
+ } else {
+ runNotifier.fireTestFailure(new Failure(description, failure));
}
}
}
View
24 junitrunner/src/main/java/com/github/junitrunner/StepRunnerListenerDelegate.java
@@ -0,0 +1,24 @@
+package com.github.junitrunner;
+
+import com.github.junitrunner.listener.RunnerListenerContainer;
+
+public class StepRunnerListenerDelegate {
+
+ private final RunnerListenerContainer listenerContainer;
+
+ public StepRunnerListenerDelegate(RunnerListenerContainer listenerContainer) {
+ this.listenerContainer = listenerContainer;
+ }
+
+ public void stepIgnored(Task step) {
+ listenerContainer.taskIgnored(step);
+ }
+
+ public void stepStarted(Task step) {
+ listenerContainer.taskStarted(step);
+ }
+
+ public void stepFinished(Task step, Throwable failure) {
+ listenerContainer.taskFinished(step, failure);
+ }
+}
View
26 junitrunner/src/main/java/com/github/junitrunner/Task.java
@@ -0,0 +1,26 @@
+package com.github.junitrunner;
+
+import org.junit.runner.Description;
+
+public abstract class Task {
+
+ protected Description description;
+ private boolean ignored;
+
+ public final Description describe() {
+ if (description == null) {
+ description = createDescription();
+ }
+ return description;
+ }
+
+ public abstract Description createDescription();
+
+ public boolean isIgnored() {
+ return ignored;
+ }
+
+ public void ignore() {
+ ignored = true;
+ }
+}
View
11 junitrunner/src/main/java/com/github/junitrunner/listener/BaseRunnerListener.java
@@ -3,6 +3,7 @@
import org.junit.runner.Description;
import com.github.junitrunner.JUnitTask;
+import com.github.junitrunner.Task;
public class BaseRunnerListener implements RunnerListener {
@@ -15,22 +16,22 @@ public void testClassFinished(Description description) {
}
@Override
- public void taskStarted(JUnitTask task) {
+ public void testCoreStarted(JUnitTask test, Object testObject) {
}
@Override
- public void taskFinished(JUnitTask task, Throwable failure) {
+ public void testCoreFinished(JUnitTask test, Object testObject, Throwable error) {
}
@Override
- public void testIgnored(JUnitTask test) {
+ public void taskStarted(Task task) {
}
@Override
- public void testCoreStarted(JUnitTask test, Object testObject) {
+ public void taskFinished(Task task, Throwable failure) {
}
@Override
- public void testCoreFinished(JUnitTask test, Object testObject, Throwable error) {
+ public void taskIgnored(Task task) {
}
}
View
10 junitrunner/src/main/java/com/github/junitrunner/listener/RunnerListener.java
@@ -3,6 +3,7 @@
import org.junit.runner.Description;
import com.github.junitrunner.JUnitTask;
+import com.github.junitrunner.Task;
public interface RunnerListener {
@@ -10,14 +11,13 @@
void testClassFinished(Description description);
- void taskStarted(JUnitTask task);
-
- void taskFinished(JUnitTask task, Throwable failure);
-
void testCoreStarted(JUnitTask test, Object testObject);
void testCoreFinished(JUnitTask test, Object testObject, Throwable error);
- void testIgnored(JUnitTask test);
+ void taskStarted(Task task);
+
+ void taskFinished(Task task, Throwable failure);
+ void taskIgnored(Task task);
}
View
21 junitrunner/src/main/java/com/github/junitrunner/listener/RunnerListenerContainer.java
@@ -5,6 +5,7 @@
import org.junit.runner.Description;
+import com.github.junitrunner.Task;
import com.github.junitrunner.JUnitTask;
public class RunnerListenerContainer {// implements RunnerListener {
@@ -27,33 +28,33 @@ public void testClassFinished(Description description) {
}
}
- public void taskIgnored(JUnitTask test) {
+ public void testCoreStarted(JUnitTask test, Object testObject) {
for (RunnerListener listener : listeners) {
- listener.testIgnored(test);
+ listener.testCoreStarted(test, testObject);
}
}
- public void taskStarted(JUnitTask task) {
+ public void testCoreFinished(JUnitTask test, Object testObject, Throwable error) {
for (RunnerListener listener : listeners) {
- listener.taskStarted(task);
+ listener.testCoreFinished(test, testObject, error);
}
}
- public void taskFinished(JUnitTask task, Throwable failure) {
+ public void taskIgnored(Task task) {
for (RunnerListener listener : listeners) {
- listener.taskFinished(task, failure);
+ listener.taskIgnored(task);
}
}
- public void testCoreStarted(JUnitTask test, Object testObject) {
+ public void taskStarted(Task task) {
for (RunnerListener listener : listeners) {
- listener.testCoreStarted(test, testObject);
+ listener.taskStarted(task);
}
}
- public void testCoreFinished(JUnitTask test, Object testObject, Throwable error) {
+ public void taskFinished(Task task, Throwable failure) {
for (RunnerListener listener : listeners) {
- listener.testCoreFinished(test, testObject, error);
+ listener.taskFinished(task, failure);
}
}
}
View
24 ...ner/src/main/java/com/github/junitrunner/plugin/annotation/AnnotationTestRuleFactory.java
@@ -30,17 +30,15 @@
public Statement addTestParts(JUnitTest test, Object testObject, Statement statement) {
Test annotation = test.getAnnotation(Test.class);
- statement = withTimeout(statement, annotation);
- statement = withExpectedException(statement, annotation);
+ if (annotation != null) {
+ statement = withTimeout(statement, annotation);
+ statement = withExpectedException(statement, annotation);
+ }
return statement;
}
Statement withTimeout(Statement statement, Test annotation) {
- long timeout = 0;
- if (annotation != null) {
- timeout = annotation.timeout();
- }
-
+ long timeout = annotation.timeout();
if (timeout > 0) {
statement = new FailOnTimeout(statement, timeout);
}
@@ -83,11 +81,13 @@ public Statement addTestInterceptors(JUnitTest test, final Object testObject, St
List<TestRule> testRules = testHelper.getAnnotatedMethodValues(testObject, Rule.class, TestRule.class);
testRules.addAll(testHelper.getAnnotatedFieldValues(testObject, Rule.class, TestRule.class));
- FrameworkMethod frameworkMethod = new FrameworkMethod(((JUnitJavaMethodTest) test).getMethod());
- List<MethodRule> methodRules = testHelper.getAnnotatedFieldValues(testObject, Rule.class, org.junit.rules.MethodRule.class);
- methodRules.removeAll(testRules);
- for (final MethodRule each : methodRules) {
- statement = each.apply(statement, frameworkMethod, testObject);
+ if (test instanceof JUnitJavaMethodTest) {
+ FrameworkMethod frameworkMethod = new FrameworkMethod(((JUnitJavaMethodTest) test).getMethod());
+ List<MethodRule> methodRules = testHelper.getAnnotatedFieldValues(testObject, Rule.class, org.junit.rules.MethodRule.class);
+ methodRules.removeAll(testRules);
+ for (final MethodRule each : methodRules) {
+ statement = each.apply(statement, frameworkMethod, testObject);
+ }
}
for (TestRule rule : testRules) {
View
1  pom.xml
@@ -21,6 +21,7 @@
<module>junitrunner-spring</module>
<module>junitrunner-unitils</module>
<module>junitrunner-mockito</module>
+ <module>junitrunner-cucumber</module>
</modules>
<licenses>
Please sign in to comment.
Something went wrong with that request. Please try again.