forked from cucumber/cucumber-jvm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b5c0164
commit 71b300a
Showing
11 changed files
with
97 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 27 additions & 21 deletions
48
examples/java-helloworld/src/test/java/cucumber/examples/java/helloworld/TimeStepdefs.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,41 @@ | ||
package cucumber.examples.java.helloworld; | ||
|
||
import com.mdimension.jchronic.Chronic; | ||
import com.mdimension.jchronic.Options; | ||
import com.mdimension.jchronic.utils.Span; | ||
import cucumber.annotation.en.Given; | ||
import cucumber.runtime.xstream.converters.Converter; | ||
import cucumber.runtime.xstream.converters.MarshallingContext; | ||
import cucumber.runtime.xstream.converters.UnmarshallingContext; | ||
import cucumber.runtime.xstream.io.HierarchicalStreamReader; | ||
import cucumber.runtime.xstream.io.HierarchicalStreamWriter; | ||
import cucumber.annotation.en.Then; | ||
import cucumber.api.Transform; | ||
import cucumber.api.Transformer; | ||
|
||
import java.util.Calendar; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
public class TimeStepdefs { | ||
@Given("^I did laundry (.*) ago$") | ||
public void I_did_laundry_time_ago(HumanTime time) throws Throwable { | ||
} | ||
private static Options options = new Options(); | ||
private Calendar laundryDate; | ||
|
||
@cucumber.runtime.xstream.annotations.XStreamConverter(HumanTimeConverter.class) | ||
public static class HumanTime { | ||
@Given("^today is \"([^\"]*)\"$") | ||
public void today_is(Calendar today) throws Throwable { | ||
options.setNow(today); | ||
} | ||
|
||
public static class HumanTimeConverter implements Converter { | ||
@Override | ||
public boolean canConvert(Class aClass) { | ||
return aClass.equals(HumanTime.class); | ||
} | ||
|
||
@Override | ||
public void marshal(Object o, HierarchicalStreamWriter hierarchicalStreamWriter, MarshallingContext marshallingContext) { | ||
@Given("^I did laundry (.*)") | ||
public void I_did_laundry_time_ago(@Transform(ChronicConverter.class) Calendar laundryDate) throws Throwable { | ||
this.laundryDate = laundryDate; | ||
} | ||
|
||
} | ||
@Then("^my laundry day must have been \"([^\"]*)\"$") | ||
public void my_laundry_day_must_have_been(Calendar day) throws Throwable { | ||
assertEquals(day, laundryDate); | ||
} | ||
|
||
public static class ChronicConverter extends Transformer<Calendar> { | ||
@Override | ||
public Object unmarshal(HierarchicalStreamReader hierarchicalStreamReader, UnmarshallingContext unmarshallingContext) { | ||
return null; | ||
public Calendar transform(String value) { | ||
Span span = Chronic.parse(value, options); | ||
return span.getEndCalendar(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters