• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2007 Mockito contributors
3  * This program is made available under the terms of the MIT License.
4  */
5 package org.mockitousage.annotation;
6 
7 import static org.junit.Assert.assertTrue;
8 import static org.mockito.internal.util.MockUtil.isMock;
9 
10 import java.util.LinkedList;
11 import java.util.List;
12 
13 import org.junit.Before;
14 import org.junit.Test;
15 import org.mockito.MockitoAnnotations;
16 import org.mockito.Spy;
17 import org.mockito.internal.util.MockUtil;
18 import org.mockitoutil.TestBase;
19 
20 @SuppressWarnings("unchecked")
21 public class SpyAnnotationInitializedInBaseClassTest extends TestBase {
22 
23     class BaseClass {
24 
25         @Spy List list = new LinkedList();
26     }
27 
28     class SubClass extends BaseClass {}
29 
30     @Test
shouldInitSpiesInBaseClass()31     public void shouldInitSpiesInBaseClass() throws Exception {
32         // given
33         SubClass subClass = new SubClass();
34         // when
35         MockitoAnnotations.openMocks(subClass);
36         // then
37         assertTrue(MockUtil.isMock(subClass.list));
38     }
39 
40     @Before
41     @Override
init()42     public void init() {
43         // we need to get rid of parent implementation this time
44     }
45 
46     @Before
before()47     public void before() {
48         MockitoAnnotations.openMocks(this);
49     }
50 
51     @Spy List spyInBaseclass = new LinkedList();
52 
53     public static class SubTest extends SpyAnnotationInitializedInBaseClassTest {
54 
55         @Spy List spyInSubclass = new LinkedList();
56 
57         @Test
shouldInitSpiesInHierarchy()58         public void shouldInitSpiesInHierarchy() throws Exception {
59             assertTrue(isMock(spyInSubclass));
60             assertTrue(isMock(spyInBaseclass));
61         }
62     }
63 }
64