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 MockitoJUnitRuleTest { 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 public static class Injected { } 32 33 public static class InjectInto { 34 private Injected injected; 35 getInjected()36 public Injected getInjected() { 37 return injected; 38 } 39 } 40 } 41