Skip to content

Commit ad609b5

Browse files
committed
Issue javaee-samples#20 Added asserts for injected beans
- if injection is not supported by the container, shows meanungful error, not NPE
1 parent 8acfbc6 commit ad609b5

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

cdi/dynamic-bean/src/test/java/org/javaee8/cdi/dynamic/bean/DynamicBeanTest.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
import static org.jboss.shrinkwrap.api.ShrinkWrap.create;
44
import static org.junit.Assert.assertEquals;
5+
import static org.junit.Assert.assertThat;
56

67
import javax.inject.Inject;
78

9+
import org.hamcrest.Matchers;
810
import org.jboss.arquillian.container.test.api.Deployment;
911
import org.jboss.arquillian.junit.Arquillian;
1012
import org.jboss.shrinkwrap.api.spec.JavaArchive;
@@ -13,13 +15,13 @@
1315
import org.junit.runner.RunWith;
1416

1517
/**
16-
*
18+
*
1719
* @author Arjan Tijms
1820
*
1921
*/
2022
@RunWith(Arquillian.class)
2123
public class DynamicBeanTest {
22-
24+
2325
@Deployment
2426
public static WebArchive deploy() {
2527
return create(WebArchive.class)
@@ -35,6 +37,7 @@ public static WebArchive deploy() {
3537

3638
@Test
3739
public void test() {
40+
assertThat("myBean", myBean, Matchers.notNullValue());
3841
assertEquals("Hi!", myBean.sayHi());
3942
}
4043
}

jpa/dynamic-tx/src/test/java/org/javaee8/jpa/dynamic/tx/DynamicTXTest.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
import static org.jboss.shrinkwrap.api.ShrinkWrap.create;
44
import static org.junit.Assert.assertEquals;
5+
import static org.junit.Assert.assertThat;
56

67
import javax.inject.Inject;
78

9+
import org.hamcrest.Matchers;
810
import org.javaee8.jpa.dynamic.tx.ApplicationInit;
911
import org.javaee8.jpa.dynamic.tx.Employee;
1012
import org.javaee8.jpa.dynamic.tx.EmployeeService;
@@ -41,11 +43,12 @@ public static WebArchive createDeployment() {
4143
public void testPersist() throws Exception {
4244
Employee employee = new Employee();
4345
employee.setName("reza");
44-
46+
47+
assertThat("employeeService", employeeService, Matchers.notNullValue());
4548
employeeService.persist(employee);
46-
49+
4750
Employee persistedEmployee = employeeService.getById(employee.getId());
48-
51+
4952
assertEquals("reza", persistedEmployee.getName());
5053
}
5154

0 commit comments

Comments
 (0)