Skip to content
This repository has been archived by the owner on May 28, 2019. It is now read-only.

Commit

Permalink
Fix the java JSONFormatter to handle calls to write() correctly
Browse files Browse the repository at this point in the history
Fix the java JSONFormatter so that it can handle calls to write() after
the call to match() but before the call to result().
  • Loading branch information
brasmusson committed Jul 31, 2013
1 parent 0744839 commit 9ad154a
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions java/src/main/java/gherkin/formatter/JSONFormatter.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,52 +25,46 @@ public class JSONFormatter implements Reporter, Formatter {
private String uri;
private List<Map> beforeHooks = new ArrayList<Map>();

private enum Phase {step, match, embedding, result, output};
private enum Phase {step, match, embedding, output, result};

/**
* In order to handle steps being added all at once, this method determines allows methods to
* opperator correctly if
*
* step
* match
* result
* embedding
* output
* result
* step
* match
* result
* embedding
* output
* result
*
* or if
*
* step
* step
* match
* result
* embedding
* output
* match
* result
* match
* embedding
* output
* result
*
* is called
*
* @return the correct step for the current operation based on past method calls to the formatter interface
*/
private Map getCurrentStep(Phase phase) {
String target = phase.ordinal() <= Phase.match.ordinal()?Phase.match.name():Phase.result.name();
boolean lastWith = false;
lastWith = (phase.ordinal() > Phase.result.ordinal());
Map lastWithValue = null;
for (Map stepOrHook : getSteps()) {
if (stepOrHook.get(target) == null) {
if (lastWith) {
return lastWithValue;
} else {
return stepOrHook;
}
return stepOrHook;
} else {
lastWithValue = stepOrHook;
}
Expand Down

0 comments on commit 9ad154a

Please sign in to comment.