I'm having trouble with the ProjectStage in Test-Control. My tests run with
ProjectStage.Production instead of UnitTest.
I put together a simple project to demonstrate my problem:
Test class:
@RunWith(CdiTestRunner.class)
@TestControl(startScopes = ApplicationScoped.class)
public class UnitTest {
@Inject SampleClient sampleClient;
@Test
@TestControl(projectStage = ProjectStage.UnitTest.class)
public void go() {
sampleClient.init(new StartupEvent());
}
}
SampleClient:
@ApplicationScoped
public class SampleClient {
@Inject SampleAPI sampleAPI;
public void init(@Observes @Any StartupEvent event) {
System.out.println(sampleAPI.doSomething());
}
}
The API:
public interface SampleAPI {
public String doSomething();
}
The production implementation:
@ApplicationScoped
@Exclude(ifProjectStage = ProjectStage.UnitTest.class)
public class SampleImpl implements SampleAPI {
@Override
public String doSomething() {
return "Greetings from Impl";
}
}
And finally the mock bean:
@ApplicationScoped
@Exclude(exceptIfProjectStage = ProjectStage.UnitTest.class)
public class SampleMock implements SampleAPI {
@Override
public String doSomething() {
return "Greetings from Mock";
}
}
When I launch the app using CdiContainer, it loads the mock bean correctly,
but when I launch it using CdiTestRunner it loads SampleImpl.
Single stepping through OWB I see that the DeltaSpike ProjectStageProducer
sees projectStage == null and sets it to Production by default.
Am I missing something in my test config?
I put a zip of the project here:
https://www.dropbox.com/s/vg76rdapsl4yps9/ProjectStage.zip?dl=0
Sorry it isn't Maven!
"ant" will launch it normally and "ant test" will run the unit test.
Thanks!
Allen