|
| 1 | +package org.javaee8.cdi.events; |
| 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.inject.Inject; |
| 12 | + |
| 13 | +import static org.hamcrest.CoreMatchers.instanceOf; |
| 14 | +import static org.hamcrest.CoreMatchers.is; |
| 15 | +import static org.hamcrest.CoreMatchers.notNullValue; |
| 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 | + |
| 25 | + @Deployment |
| 26 | + public static Archive<?> deploy() { |
| 27 | + return ShrinkWrap.create(JavaArchive.class) |
| 28 | + .addClasses(EventReceiver.class, EventSender.class, GreetingReceiver.class, GreetingSender.class) |
| 29 | + .addAsManifestResource("beans.xml"); |
| 30 | + } |
| 31 | + |
| 32 | + @Inject |
| 33 | + private EventSender sender; |
| 34 | + |
| 35 | + @Inject |
| 36 | + private EventReceiver receiver; |
| 37 | + |
| 38 | + @Test |
| 39 | + public void test() throws Exception { |
| 40 | + assertThat(sender, is(notNullValue())); |
| 41 | + assertThat(sender, instanceOf(GreetingSender.class)); |
| 42 | + |
| 43 | + assertThat(receiver, is(notNullValue())); |
| 44 | + assertThat(receiver, instanceOf(GreetingReceiver.class)); |
| 45 | + |
| 46 | + // default greet |
| 47 | + assertEquals("Willkommen", receiver.getGreet()); |
| 48 | + // send a new greet |
| 49 | + sender.send("Welcome"); |
| 50 | + // receiver must not belongs to the dependent pseudo-scope since we are checking the result |
| 51 | + assertEquals("Welcome", receiver.getGreet()); |
| 52 | + } |
| 53 | +} |
0 commit comments