1 package org.mockitousage.junitrule; 2 3 import org.junit.Rule; 4 import org.junit.Test; 5 import org.mockito.InjectMocks; 6 import org.mockito.Mock; 7 import org.mockito.junit.MockitoJUnit; 8 import org.mockito.junit.MockitoRule; 9 10 import static org.junit.Assert.assertEquals; 11 import static org.junit.Assert.assertNotNull; 12 13 public class RuleTestWithFactoryMethodTest { 14 15 @Rule 16 public MockitoRule mockitoRule = MockitoJUnit.rule(); 17 18 @Mock 19 private Injected injected; 20 21 @InjectMocks 22 private InjectInto injectInto; 23 24 @Test testInjectMocks()25 public void testInjectMocks() throws Exception { 26 assertNotNull("Mock created", injected); 27 assertNotNull("Object created", injectInto); 28 assertEquals("A injected into B", injected, injectInto.getInjected()); 29 30 } 31 32 public static class Injected { 33 } 34 35 public static class InjectInto { 36 37 private Injected injected; 38 getInjected()39 public Injected getInjected() { 40 return injected; 41 } 42 } 43 } 44