|
| 1 | +package org.javaee7.cdi.instance; |
| 2 | + |
| 3 | +import org.jboss.arquillian.container.test.api.Deployment; |
| 4 | +import org.jboss.arquillian.junit.Arquillian; |
| 5 | +import org.jboss.shrinkwrap.api.Archive; |
| 6 | +import org.jboss.shrinkwrap.api.ShrinkWrap; |
| 7 | +import org.jboss.shrinkwrap.api.spec.JavaArchive; |
| 8 | +import org.junit.Test; |
| 9 | +import org.junit.runner.RunWith; |
| 10 | + |
| 11 | +import javax.enterprise.inject.Instance; |
| 12 | +import javax.inject.Inject; |
| 13 | + |
| 14 | +import static org.hamcrest.CoreMatchers.either; |
| 15 | +import static org.hamcrest.CoreMatchers.instanceOf; |
| 16 | +import static org.junit.Assert.assertEquals; |
| 17 | +import static org.junit.Assert.assertThat; |
| 18 | + |
| 19 | +/** |
| 20 | + * @author Radim Hanus |
| 21 | + */ |
| 22 | +@RunWith(Arquillian.class) |
| 23 | +public class GreetingTest { |
| 24 | + @Deployment |
| 25 | + public static Archive<?> deploy() { |
| 26 | + return ShrinkWrap.create(JavaArchive.class) |
| 27 | + .addClasses(Greeting.class, SimpleGreeting.class, FancyGreeting.class) |
| 28 | + .addAsManifestResource("beans.xml"); |
| 29 | + } |
| 30 | + |
| 31 | + @Inject |
| 32 | + private Instance<Greeting> instance; |
| 33 | + |
| 34 | + @Test |
| 35 | + public void test() throws Exception { |
| 36 | + int instanceCount = 0; |
| 37 | + for (Greeting greeting : instance) { |
| 38 | + assertThat(greeting, either(instanceOf(SimpleGreeting.class)).or(instanceOf(FancyGreeting.class))); |
| 39 | + instanceCount++; |
| 40 | + } |
| 41 | + assertEquals(instanceCount, 2); |
| 42 | + } |
| 43 | +} |
| 44 | + |
0 commit comments