1   /**
2    * Copyright (C) 2008 Mathieu Carbou <mathieu.carbou@gmail.com>
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *         http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package com.mycila.testing.plugin.atunit;
17  
18  import atunit.*;
19  import atunit.example.subjects.GuiceUserManager;
20  import atunit.example.subjects.Logger;
21  import atunit.example.subjects.User;
22  import atunit.example.subjects.UserDao;
23  import com.google.inject.Inject;
24  import com.mycila.testing.core.TestSetup;
25  import com.mycila.testing.plugin.atunit.container.GuiceContainer;
26  import com.mycila.testing.plugin.atunit.mocker.JMockFramework;
27  import org.jmock.Expectations;
28  import org.jmock.Mockery;
29  import static org.testng.Assert.*;
30  import org.testng.annotations.BeforeClass;
31  import org.testng.annotations.Test;
32  
33  /**
34   * @author Mathieu Carbou (mathieu.carbou@gmail.com)
35   */
36  @ContainerClass(GuiceContainer.class)
37  @MockFrameworkClass(JMockFramework.class)
38  public class ExampleGuiceAndJMockTest {
39  
40      @Inject
41      @Unit
42      GuiceUserManager manager;
43  
44      @Inject
45      User emptyUser;
46  
47      Mockery mockery;
48  
49      @Mock
50      UserDao dao;
51      @Stub
52      Logger ignoredLogger;
53  
54      @BeforeClass
55      public void setup() {
56          TestSetup.setup(this);
57      }
58      
59      @Test
60      public void testGetUser() {
61          mockery.checking(new Expectations() {{
62              one(dao).load(with(equal(500)));
63              will(returnValue(emptyUser));
64          }});
65          assertSame(manager.getUser(500), emptyUser);
66          mockery.assertIsSatisfied();
67      }
68  }