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 org.junit.Before;
8 import org.junit.Test;
9 import org.mockito.MockitoAnnotations;
10 import org.mockito.Spy;
11 import org.mockito.internal.util.MockUtil;
12 import org.mockitoutil.TestBase;
13 
14 import java.util.LinkedList;
15 import java.util.List;
16 
17 import static org.junit.Assert.assertTrue;
18 import static org.mockito.internal.util.MockUtil.isMock;
19 
20 @SuppressWarnings("unchecked")
21 public class SpyAnnotationInitializedInBaseClassTest extends TestBase {
22 
23     class BaseClass {
24 
25         @Spy
26         List list = new LinkedList();
27     }
28 
29     class SubClass extends BaseClass {
30 
31     }
32 
33     @Test
shouldInitSpiesInBaseClass()34     public void shouldInitSpiesInBaseClass() throws Exception {
35         //given
36         SubClass subClass = new SubClass();
37         //when
38         MockitoAnnotations.initMocks(subClass);
39         //then
40         assertTrue(MockUtil.isMock(subClass.list));
41     }
42 
43     @Before
44     @Override
init()45     public void init() {
46         //we need to get rid of parent implementation this time
47     }
48 
49     @Before
before()50     public void before() {
51         MockitoAnnotations.initMocks(this);
52     }
53 
54     @Spy
55     List spyInBaseclass = new LinkedList();
56 
57     public static class SubTest extends SpyAnnotationInitializedInBaseClassTest {
58 
59         @Spy
60         List spyInSubclass = new LinkedList();
61 
62         @Test
shouldInitSpiesInHierarchy()63         public void shouldInitSpiesInHierarchy() throws Exception {
64             assertTrue(isMock(spyInSubclass));
65             assertTrue(isMock(spyInBaseclass));
66         }
67     }
68 }
69