1 package org.apache.onami.test;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.util.ArrayList;
23 import java.util.List;
24
25 import org.apache.onami.test.OnamiRunner;
26 import org.apache.onami.test.annotation.Mock;
27 import org.apache.onami.test.data.HelloWorld;
28 import org.apache.onami.test.data.Service;
29 import org.easymock.EasyMock;
30 import org.junit.Assert;
31 import org.junit.Before;
32 import org.junit.Test;
33 import org.junit.runner.RunWith;
34
35 import com.google.inject.AbstractModule;
36 import com.google.inject.Inject;
37 import com.google.inject.Injector;
38 import com.google.inject.TypeLiteral;
39
40 @RunWith( OnamiRunner.class )
41 public class InjectDependingMockObjectTestCase
42 {
43
44 @Mock
45 static private Service service;
46
47 @Inject
48 Injector injector;
49
50 private HelloWorld helloWorld;
51
52 @Before
53 public void setUp()
54 {
55 final List<Service> list = new ArrayList<Service>();
56 list.add( service );
57
58 AbstractModule listAbstractModule = new AbstractModule()
59 {
60 @Override
61 protected void configure()
62 {
63 bind( new TypeLiteral<List<Service>>()
64 {
65 } ).toInstance( list );
66 }
67 };
68
69 Injector cInjector = injector.createChildInjector( listAbstractModule );
70 helloWorld = cInjector.getInstance( HelloWorld.class );
71
72 cInjector.injectMembers( helloWorld );
73 }
74
75 @Test
76 public void testMock()
77 {
78 Assert.assertNotNull( helloWorld );
79 Assert.assertNotNull( service );
80 EasyMock.expect( service.go() ).andReturn( "Ciao" );
81 EasyMock.expectLastCall().once();
82
83 EasyMock.replay( service );
84 helloWorld.sayHalloByServiceLists();
85 EasyMock.verify( service );
86 }
87
88 }