Skip to content

Commit

Permalink
Running with JUnit uses a null formatter by default (instead of a pro…
Browse files Browse the repository at this point in the history
…gress formatter).
  • Loading branch information
aslakhellesoy committed Mar 22, 2012
1 parent dcec2a1 commit 5db40e6
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 18 deletions.
5 changes: 3 additions & 2 deletions History.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
## [Git master](https://github.com/cucumber/cucumber-jvm/compare/v1.0.0.RC23...master)

* Fix release artifacts so cucumber-clojure can be released. ([#270](https://github.com/cucumber/cucumber-jvm/issues/270) Aslak Hellesøy)
* The @Pending annotation no longer exists. Throw a PendingException instead ([#271](https://github.com/cucumber/cucumber-jvm/issues/271) Aslak Hellesøy)
* [JUnit] Running with JUnit uses a null formatter by default (instead of a progress formatter). Aslak Hellesøy.
* [Clojure] Fix release artifacts so cucumber-clojure can be released. ([#270](https://github.com/cucumber/cucumber-jvm/issues/270) Aslak Hellesøy)
* [Java] The @Pending annotation no longer exists. Throw a PendingException instead ([#271](https://github.com/cucumber/cucumber-jvm/issues/271) Aslak Hellesøy)

## [1.0.0.RC23](https://github.com/cucumber/cucumber-jvm/compare/v1.0.0.RC22...v1.0.0.RC23)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class FormatterConverter {
private Class[] CTOR_ARGS = new Class[]{Appendable.class, File.class};

private static final Map<String, Class<? extends Formatter>> FORMATTER_CLASSES = new HashMap<String, Class<? extends Formatter>>() {{
put("null", NullFormatter.class);
put("junit", JUnitFormatter.class);
put("html", HTMLFormatter.class);
put("pretty", CucumberPrettyFormatter.class);
Expand Down
60 changes: 60 additions & 0 deletions core/src/main/java/cucumber/formatter/NullFormatter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
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 java.util.List;

public class NullFormatter implements Formatter {
public NullFormatter(Appendable ignore) {
}

@Override
public void uri(String uri) {
}

@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<String> legalEvents, String uri, int line) {
}

@Override
public void done() {
}

@Override
public void close() {
}
}
35 changes: 19 additions & 16 deletions junit/src/main/java/cucumber/junit/RuntimeOptionsFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@ public RuntimeOptionsFactory(Class clazz) {

public RuntimeOptions create() {
List<String> args = new ArrayList<String>();
Cucumber.Options cucumberOptions = getFeatureAnnotation(clazz);
Cucumber.Options options = getOptions(clazz);

addDryRun(cucumberOptions, args);
addGlue(cucumberOptions, clazz, args);
addFeatures(cucumberOptions, clazz, args);
addTags(cucumberOptions, args);
addFormats(cucumberOptions, args);
addDryRun(options, args);
addGlue(options, clazz, args);
addTags(options, args);
addFormats(options, args);
addFeatures(options, clazz, args);

return new RuntimeOptions(args.toArray(new String[args.size()]));

}

private Cucumber.Options getFeatureAnnotation(Class<?> clazz) {
private Cucumber.Options getOptions(Class<?> clazz) {
return clazz.getAnnotation(Cucumber.Options.class);
}

Expand All @@ -53,14 +53,6 @@ private void addGlue(Cucumber.Options options, Class clazz, List<String> args) {
}
}

private void addFeatures(Cucumber.Options options, Class clazz, List<String> args) {
if (options != null && options.features().length != 0) {
Collections.addAll(args, options.features());
} else {
args.add(packagePath(clazz));
}
}

private void addTags(Cucumber.Options options, List<String> args) {
if (options != null) {
for (String tags : options.tags()) {
Expand All @@ -71,11 +63,22 @@ private void addTags(Cucumber.Options options, List<String> args) {
}

private void addFormats(Cucumber.Options options, List<String> args) {
if (options != null) {
if (options != null && options.format().length != 0) {
for (String format : options.format()) {
args.add("--format");
args.add(format);
}
} else {
args.add("--format");
args.add("null");
}
}

private void addFeatures(Cucumber.Options options, Class clazz, List<String> args) {
if (options != null && options.features().length != 0) {
Collections.addAll(args, options.features());
} else {
args.add(packagePath(clazz));
}
}
}

0 comments on commit 5db40e6

Please sign in to comment.