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