Created
April 26, 2012 09:14
-
-
Save tknerr/2497953 to your computer and use it in GitHub Desktop.
cucumber-jvm: proposal for specifying default xstream converters
This file contains hidden or 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
package features.foo.alternative; | |
import org.apache.commons.collections.Bag; | |
import cucumber.annotation.en.Given; | |
import cucumber.runtime.xstream.converters.basic.AbstractSingleValueConverter; | |
import features.foo.alternative.DefaultConvertersAlternative2.Baz; | |
import features.foo.alternative.DefaultConvertersAlternative2.Foo; | |
import features.foo.alternative.DefaultConvertersAlternative2.FooConverter; | |
import features.foo.subclass.FooStepDefsWithExternalFooAndSubclassing.ExternalFooSubclass; | |
@StepDefOptions( | |
defaultConverters = { | |
@Mapping(type = Foo.class, converter = FooConverter.class), | |
@Mapping(type = Bag.class, converter = BarConverter.class), | |
@Mapping(type = Baz.class, converter = BazConverter.class), | |
}) | |
public class FooStepDefs { | |
@Given("^I have some foo named \"([^\"]*)\"$") | |
public void I_have_some_foo_named(Foo foo) { | |
Assert.assertNotNull(foo.getName()); | |
} | |
@Given("^I have some stuff in a data table:$") | |
public void I_have_some_stuff_in_a_data_table(List<StuffInTable> stuffInTable) { | |
for (StuffInTable stuff : stuffInTable) { | |
Assert.assertNotNull(stuff.foo.getName()); | |
Assert.assertNotNull(stuff.bar.getName()); | |
Assert.assertNotNull(stuff.baz.getName()); | |
} | |
} | |
public static class StuffInTable { | |
public Foo foo; | |
// override default converter if necessary | |
@XStreamConverter(AlternativeBarConverter.class) | |
public Bar bar; | |
public Baz baz; | |
} | |
} |
This file contains hidden or 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
package features.foo.alternative; | |
import java.lang.annotation.Retention; | |
import java.lang.annotation.RetentionPolicy; | |
@Retention(RetentionPolicy.RUNTIME) | |
public static @interface Mapping { | |
Class<?> type(); | |
Class<? extends ConverterMatcher> converter(); | |
} |
This file contains hidden or 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
package features.foo.alternative; | |
import java.lang.annotation.ElementType; | |
import java.lang.annotation.Retention; | |
import java.lang.annotation.RetentionPolicy; | |
import java.lang.annotation.Target; | |
@Retention(RetentionPolicy.RUNTIME) | |
@Target({ ElementType.TYPE }) | |
public static @interface StepDefOptions { | |
Mapping[] defaultConverters(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment