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.Logger;
20  import atunit.example.subjects.User;
21  import atunit.example.subjects.UserDao;
22  import atunit.example.subjects.UserManagerImpl;
23  import atunit.spring.Bean;
24  import com.mycila.testing.core.TestSetup;
25  import com.mycila.testing.plugin.atunit.container.SpringContainer;
26  import com.mycila.testing.plugin.atunit.mocker.EasyMockFramework;
27  import static org.easymock.EasyMock.*;
28  import static org.testng.Assert.*;
29  import org.testng.annotations.BeforeClass;
30  import org.testng.annotations.Test;
31  
32  /**
33   * @author Mathieu Carbou (mathieu.carbou@gmail.com)
34   */
35  @ContainerClass(SpringContainer.class)
36  @MockFrameworkClass(EasyMockFramework.class)
37  public class ExampleSpringEasyMockTest {
38  
39      @Bean
40      @Unit
41      UserManagerImpl manager;
42  
43      @Bean("fred")
44      User fred;
45  
46      @Bean("userDao")
47      @Mock
48      UserDao dao;
49      @Bean("log")
50      @Stub
51      Logger log;
52  
53      @BeforeClass
54      public void setup() {
55          TestSetup.setup(this);
56      }
57      
58      @Test
59      public void testGetUser() {
60          expect(dao.load(1)).andReturn(fred);
61          replay(dao);
62          assertSame(fred, manager.getUser(1));
63          verify(dao);
64      }
65  }