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