Details
-
New Feature
-
Status: Resolved
-
Major
-
Resolution: Fixed
-
1.8.1
-
None
Description
based on DELTASPIKE-1337 it should be possible to define a class-filter per test.
it allows type-safe isolation for tests and with cdi 1.1+ e.g. to build labeled-alternatives without text-based config.
a possible approach looks like:
@Retention(RUNTIME) @Target(TYPE) public @interface Labeled { Class<? extends TestControl.Label> value(); } public abstract class AbstractLabeledAlternativeFilter implements ClassFilter { private final Class<? extends TestControl.Label> activeLabel; protected AbstractLabeledAlternativeFilter(Class<? extends TestControl.Label> activeLabel) { this.activeLabel = activeLabel; } @Override public boolean isFiltered(Class<?> targetClass) { if (!targetClass.isAnnotationPresent(Alternative.class)) { return false; } Labeled labeled = targetClass.getAnnotation(Labeled.class); if (labeled == null) { return false; } if (labeled.value().equals(activeLabel)) { return false; } return true; } }
@Labeled(Label1Test.Label1.class) @Alternative @Priority(1) public class MyLabeledAlternativeBean1 extends MyBean { /*...*/ } @RunWith(CdiTestRunner.class) @TestControl(activeAlternativeLabel = Label1Test.Label1.class, classFilter = Label1Test.Label1Filter.class) public class Label1Test { @Inject private MyBean myBean; //tests public static class Label1 implements TestControl.Label { } public static class Label1Filter extends AbstractLabeledAlternativeFilter { public Label1Filter() { super(Label1.class); } } }
besides that other custom concepts are possible as well (not even bound to alternative-beans).