View Javadoc

1   package org.apache.onami.test.guice;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  import org.apache.onami.test.OnamiRunner;
23  import org.apache.onami.test.annotation.Mock;
24  import org.apache.onami.test.data.HelloWordAnnotated;
25  import org.apache.onami.test.data.Service;
26  import org.apache.onami.test.data.TestAnnotation;
27  import org.easymock.EasyMock;
28  import org.junit.Assert;
29  import org.junit.Test;
30  import org.junit.runner.RunWith;
31  
32  import com.google.inject.Inject;
33  
34  @RunWith( OnamiRunner.class )
35  public class MockAnnotatedWithTestCase
36  {
37  
38      @Mock( annotatedWith = TestAnnotation.class )
39      private Service service2;
40  
41      @Mock
42      private Service service;
43  
44      @Mock( namedWith = "test.named" )
45      private Service serviceNamed;
46  
47      @Inject
48      private HelloWordAnnotated seviceImplAnnotated;
49  
50      @Test
51      public void test()
52          throws Exception
53      {
54          Assert.assertNotNull( service2 );
55          Assert.assertNotNull( service );
56          Assert.assertNotNull( serviceNamed );
57      }
58  
59      @Test
60      public void test3()
61          throws Exception
62      {
63          Assert.assertNotNull( service2 );
64          Assert.assertNotNull( serviceNamed );
65  
66          EasyMock.expect( service2.go() ).andReturn( "Mocked injected class annotated" ).anyTimes();
67          EasyMock.expect( serviceNamed.go() ).andReturn( "Mocked injected class named" ).anyTimes();
68          EasyMock.replay( service2, serviceNamed );
69  
70          Assert.assertEquals( "Mocked injected class annotated", service2.go() );
71          Assert.assertEquals( "Mocked injected class annotated", seviceImplAnnotated.go() );
72          Assert.assertEquals( "Mocked injected class named", seviceImplAnnotated.getNamed() );
73          EasyMock.verify( service2 );
74      }
75  
76  }