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.bugs.injection; 6 7 import static org.junit.Assert.assertNotNull; 8 9 import org.junit.Test; 10 import org.junit.runner.RunWith; 11 import org.mockito.InjectMocks; 12 import org.mockito.Mock; 13 import org.mockito.junit.MockitoJUnitRunner; 14 15 // issue 289 16 @RunWith(MockitoJUnitRunner.class) 17 public class ChildWithSameParentFieldInjectionTest { 18 @InjectMocks private System system; 19 20 @Mock private SomeService someService; 21 22 @Test parent_field_is_not_null()23 public void parent_field_is_not_null() { 24 assertNotNull(((AbstractSystem) system).someService); 25 } 26 27 @Test child_field_is_not_null()28 public void child_field_is_not_null() { 29 assertNotNull(system.someService); 30 } 31 32 public static class System extends AbstractSystem { 33 private SomeService someService; 34 doSomethingElse()35 public void doSomethingElse() { 36 someService.doSomething(); 37 } 38 } 39 40 public static class AbstractSystem { 41 private SomeService someService; 42 doSomething()43 public void doSomething() { 44 someService.doSomething(); 45 } 46 } 47 48 public static class SomeService { doSomething()49 public void doSomething() {} 50 } 51 } 52