Skip to content

Commit

Permalink
Updated to JUnit 4.11. Relates to #255. Might also relate to #322. In…
Browse files Browse the repository at this point in the history
…telliJ IDEA reports features with Background and Scenario Outline incorrect.y. Might be the case on master too.
  • Loading branch information
aslakhellesoy committed Oct 16, 2012
1 parent 79446ad commit 98d804d
Show file tree
Hide file tree
Showing 17 changed files with 33 additions and 87 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ in your [POM](http://maven.apache.org/pom.html):
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
<version>4.11-beta-1</version>
<scope>test</scope>
</dependency>
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public void step(Step step) {
currentStepContainer.step(step);
}

public Feature getFeature() {
public Feature getGherkinFeature() {
return feature;
}

Expand All @@ -105,7 +105,7 @@ public String getUri() {

public void run(Formatter formatter, Reporter reporter, Runtime runtime) {
formatter.uri(getUri());
formatter.feature(getFeature());
formatter.feature(getGherkinFeature());

for (CucumberTagStatement cucumberTagStatement : getFeatureElements()) {
//Run the scenario, it should handle before and after hooks
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void run(Formatter formatter, Reporter reporter, Runtime runtime) {
}

CucumberScenario createExampleScenario(ExamplesTableRow header, ExamplesTableRow example, List<Tag> examplesTags) {
Scenario exampleScenario = new Scenario(example.getComments(), examplesTags, tagStatement.getKeyword(), tagStatement.getName(), "", example.getLine(), example.getId());
Scenario exampleScenario = new Scenario(example.getComments(), examplesTags, getGherkinModel().getKeyword(), getGherkinModel().getName(), "", example.getLine(), example.getId());
CucumberScenario cucumberScenario = new CucumberScenario(cucumberFeature, cucumberBackground, exampleScenario, example);
for (Step step : getSteps()) {
cucumberScenario.step(createExampleStep(step, header, example));
Expand Down
23 changes: 13 additions & 10 deletions core/src/main/java/cucumber/runtime/model/CucumberTagStatement.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,35 @@
import static gherkin.util.FixJava.join;

public abstract class CucumberTagStatement extends StepContainer {
final TagStatement tagStatement;
private final TagStatement gherkinModel;
private final String visualName;

CucumberTagStatement(CucumberFeature cucumberFeature, TagStatement tagStatement) {
super(cucumberFeature, tagStatement);
this.tagStatement = tagStatement;
this.visualName = tagStatement.getKeyword() + ": " + tagStatement.getName();
CucumberTagStatement(CucumberFeature cucumberFeature, TagStatement gherkinModel) {
super(cucumberFeature, gherkinModel);
this.gherkinModel = gherkinModel;
this.visualName = gherkinModel.getKeyword() + ": " + gherkinModel.getName();
}

CucumberTagStatement(CucumberFeature cucumberFeature, TagStatement tagStatement, Row example) {
super(cucumberFeature, tagStatement);
this.tagStatement = tagStatement;
CucumberTagStatement(CucumberFeature cucumberFeature, TagStatement gherkinModel, Row example) {
super(cucumberFeature, gherkinModel);
this.gherkinModel = gherkinModel;
this.visualName = "| " + join(example.getCells(), " | ") + " |";
}

protected Set<Tag> tagsAndInheritedTags() {
Set<Tag> tags = new HashSet<Tag>();
tags.addAll(cucumberFeature.getFeature().getTags());
tags.addAll(tagStatement.getTags());
tags.addAll(cucumberFeature.getGherkinFeature().getTags());
tags.addAll(gherkinModel.getTags());
return tags;
}

public String getVisualName() {
return visualName;
}

public TagStatement getGherkinModel() {
return gherkinModel;
}

public abstract void run(Formatter formatter, Reporter reporter, Runtime runtime);
}
2 changes: 1 addition & 1 deletion core/src/test/java/cucumber/runtime/HookTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void after_hooks_execute_before_objects_are_disposed() throws Throwable {
CucumberFeature feature = mock(CucumberFeature.class);
Feature gherkinFeature = mock(Feature.class);

when(feature.getFeature()).thenReturn(gherkinFeature);
when(feature.getGherkinFeature()).thenReturn(gherkinFeature);
when(gherkinFeature.getTags()).thenReturn(new ArrayList<Tag>());

CucumberScenario scenario = new CucumberScenario(feature, null, gherkinScenario);
Expand Down
2 changes: 1 addition & 1 deletion examples/java-helloworld/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<property name="cucumber-jvm.version" value="1.0.14"/>
<property name="cucumber-html.version" value="0.2.1"/>
<property name="jchronic.version" value="0.2.6"/>
<property name="junit.version" value="4.10"/>
<property name="junit.version" value="4.11-beta-1"/>

<property name="jars" value="lib"/>

Expand Down
2 changes: 1 addition & 1 deletion examples/java-helloworld/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
<version>4.11-beta-1</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def write_build_files
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
<version>4.11-beta-1</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
52 changes: 0 additions & 52 deletions junit/src/main/java/cucumber/junit/DescriptionFactory.java

This file was deleted.

5 changes: 2 additions & 3 deletions junit/src/main/java/cucumber/junit/ExamplesRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@
import org.junit.runners.Suite;
import org.junit.runners.model.InitializationError;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import static cucumber.junit.DescriptionFactory.createDescription;

class ExamplesRunner extends Suite {
private final CucumberExamples cucumberExamples;
private Description description;
Expand Down Expand Up @@ -40,7 +39,7 @@ protected String getName() {
@Override
public Description getDescription() {
if (description == null) {
description = createDescription(getName(), cucumberExamples);
description = Description.createSuiteDescription(getName(), cucumberExamples.getExamples());
for (Runner child : getChildren()) {
description.addChild(describeChild(child));
}
Expand Down
6 changes: 2 additions & 4 deletions junit/src/main/java/cucumber/junit/ExecutionUnitRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
import java.util.List;
import java.util.Map;

import static cucumber.junit.DescriptionFactory.createDescription;

/**
* Runs a scenario, or a "synthetic" scenario derived from an Examples row.
*/
Expand Down Expand Up @@ -44,7 +42,7 @@ public String getName() {
@Override
public Description getDescription() {
if (description == null) {
description = createDescription(getName(), cucumberScenario);
description = Description.createSuiteDescription(getName(), cucumberScenario.getGherkinModel());

if (cucumberScenario.getCucumberBackground() != null) {
for (Step backgroundStep : cucumberScenario.getCucumberBackground().getSteps()) {
Expand All @@ -63,7 +61,7 @@ public Description getDescription() {
protected Description describeChild(Step step) {
Description description = stepDescriptions.get(step);
if (description == null) {
description = createDescription(step.getKeyword() + step.getName(), step);
description = Description.createSuiteDescription(step.getKeyword() + step.getName(), step);
stepDescriptions.put(step, description);
}
return description;
Expand Down
8 changes: 3 additions & 5 deletions junit/src/main/java/cucumber/junit/FeatureRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
import java.util.ArrayList;
import java.util.List;

import static cucumber.junit.DescriptionFactory.createDescription;

class FeatureRunner extends ParentRunner<ParentRunner> {
private final List<ParentRunner> children = new ArrayList<ParentRunner>();

Expand All @@ -35,14 +33,14 @@ protected FeatureRunner(CucumberFeature cucumberFeature, Runtime runtime, JUnitR

@Override
public String getName() {
Feature feature = cucumberFeature.getFeature();
Feature feature = cucumberFeature.getGherkinFeature();
return feature.getKeyword() + ": " + feature.getName();
}

@Override
public Description getDescription() {
if (description == null) {
description = createDescription(getName(), cucumberFeature);
description = Description.createSuiteDescription(getName(), cucumberFeature.getGherkinFeature());
for (ParentRunner child : getChildren()) {
description.addChild(describeChild(child));
}
Expand All @@ -68,7 +66,7 @@ protected void runChild(ParentRunner child, RunNotifier notifier) {
@Override
public void run(RunNotifier notifier) {
jUnitReporter.uri(cucumberFeature.getUri());
jUnitReporter.feature(cucumberFeature.getFeature());
jUnitReporter.feature(cucumberFeature.getGherkinFeature());
super.run(notifier);
jUnitReporter.eof();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@

import java.util.ArrayList;

import static cucumber.junit.DescriptionFactory.createDescription;

class ScenarioOutlineRunner extends Suite {
private final CucumberScenarioOutline cucumberScenarioOutline;
private Description description;
Expand All @@ -32,7 +30,7 @@ public String getName() {
@Override
public Description getDescription() {
if (description == null) {
description = createDescription(getName(), cucumberScenarioOutline);
description = Description.createSuiteDescription(getName(), cucumberScenarioOutline.getGherkinModel());
for (Runner child : getChildren()) {
description.addChild(describeChild(child));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@

@RunWith(Cucumber.class)
//@Cucumber.Options(features = "classpath:cucumber/runtime/java/picocontainer/dates.feature:3:11")
@Cucumber.Options(tags = "@enums")
public class RunCukesTest {
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
@enums
Feature: Java Enums

Background:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Feature:
Feature: Issue 225

Scenario Outline: Outline 1
When foo
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
<version>4.11-beta-1</version>
</dependency>
<dependency>
<groupId>org.python</groupId>
Expand Down

0 comments on commit 98d804d

Please sign in to comment.