-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
/
MockitoJUnitRuleTest.java
48 lines (37 loc) · 1.17 KB
/
MockitoJUnitRuleTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*
* Copyright (c) 2017 Mockito contributors
* This program is made available under the terms of the MIT License.
*/
package org.mockitousage.junitrule;
import org.junit.Rule;
import org.junit.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
public class MockitoJUnitRuleTest {
@Rule
public MockitoRule mockitoRule = MockitoJUnit.rule();
// Fixes #1578: Protect against multiple execution.
@Rule
public MockitoRule mockitoRule2 = mockitoRule;
@Mock
private Injected injected;
@InjectMocks
private InjectInto injectInto;
@Test
public void testInjectMocks() throws Exception {
assertNotNull("Mock created", injected);
assertNotNull("Object created", injectInto);
assertEquals("A injected into B", injected, injectInto.getInjected());
}
public static class Injected { }
public static class InjectInto {
private Injected injected;
public Injected getInjected() {
return injected;
}
}
}