This repository has been archived by the owner on Jun 23, 2020. It is now read-only.
/
BasicObjectServiceTest.java
89 lines (74 loc) · 2.7 KB
/
BasicObjectServiceTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package pl.softwaremill.cdiext.objectservice;
import org.jboss.arquillian.api.Deployment;
import org.jboss.arquillian.testng.Arquillian;
import org.jboss.shrinkwrap.api.Archives;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.testng.Assert;
import org.testng.annotations.Test;
import pl.softwaremill.cdiext.objectservice.extension.ObjectServiceExtension;
import pl.softwaremill.cdiext.util.ArquillianUtil;
import javax.inject.Inject;
/**
* @author Adam Warski (adam at warski dot org)
*/
public class BasicObjectServiceTest extends Arquillian {
@Deployment
public static JavaArchive createTestArchive() {
JavaArchive ar = Archives.create("test.jar", JavaArchive.class)
.addPackage(A.class.getPackage())
.addPackage(OS.class.getPackage())
.addPackage(ObjectServiceExtension.class.getPackage());
ar = ArquillianUtil.addEmptyBeansXml(ar);
ar = ArquillianUtil.addExtensionsFromApp(ar);
return ar;
}
@Inject
private OSP<A, Service1<A>> service1;
@Inject
private OSP<A, Service2<A>> service2;
@Inject
private OSP<A, Service3<A>> service3;
@Test
public void testService1WithB() {
Assert.assertEquals(service1.f(new B(10)).get(), 10);
}
@Test
public void testService1WithC() {
Assert.assertEquals(service1.f(new C("x")).get(), "x");
}
@Test
public void testService1WithAnonymousB() {
Assert.assertEquals(service1.f(new B(11) {
@Override
public Integer getValue() {
return 12;
}
}).get(), 12);
}
@Test
public void testNewServiceInstances2WithB() {
// On each invocation of f() there should be a new bean created.
int instancesStart = Service2B.instanceCount();
Assert.assertEquals(service2.f(new B(10)).get(), 10);
Assert.assertEquals(service2.f(new B(12)).get(), 12);
int instancesEnd = Service2B.instanceCount();
Assert.assertEquals(instancesEnd - instancesStart, 2);
}
@Test
public void testNewServiceInstances2WithC() {
// On each invocation of f() there should be a new bean created.
int instancesStart = Service2C.instanceCount();
Assert.assertEquals(service2.f(new C("x")).get(), "x");
Assert.assertEquals(service2.f(new C("y")).get(), "y");
int instancesEnd = Service2C.instanceCount();
Assert.assertEquals(instancesEnd - instancesStart, 2);
}
@Test
public void testService3WithB() {
Assert.assertEquals(service3.f(new B(10)).get(), 10);
}
@Test
public void testService3WithC() {
Assert.assertEquals(service3.f(new C("x")).get(), "x");
}
}