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