Home | History | Annotate | Download | only in junitrule
      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 RuleTestWithParameterConstructorTest {
     18 
     19 	 @Rule
     20 	 public MockitoRule mockitoJUnitRule = MockitoJUnit.rule();
     21 
     22     @Mock
     23     private Injected injected;
     24 
     25     @InjectMocks
     26     private InjectInto injectInto;
     27 
     28     @Test
     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 
     36     public static class Injected {
     37     }
     38 
     39     public static class InjectInto {
     40 
     41         private Injected injected;
     42 
     43         public Injected getInjected() {
     44             return injected;
     45         }
     46     }
     47 }
     48