forked from mockito/mockito
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DefaultInternalRunnerTest.java
85 lines (68 loc) · 2.9 KB
/
DefaultInternalRunnerTest.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*
* Copyright (c) 2017 Mockito contributors
* This program is made available under the terms of the MIT License.
*/
package org.mockito.internal.runners;
import org.junit.Test;
import org.junit.runner.Description;
import org.junit.runner.notification.Failure;
import org.junit.runner.notification.RunListener;
import org.junit.runner.notification.RunNotifier;
import org.mockito.Mock;
import org.mockito.internal.junit.MockitoTestListener;
import org.mockito.internal.junit.TestFinishedEvent;
import org.mockito.internal.util.Supplier;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.*;
public class DefaultInternalRunnerTest {
private final RunListener runListener = mock(RunListener.class);
private final MockitoTestListener mockitoTestListener = mock(MockitoTestListener.class);
private final Supplier<MockitoTestListener> supplier = new Supplier<MockitoTestListener>() {
public MockitoTestListener get() {
return mockitoTestListener;
}
};
@Test
public void does_not_fail_when_tests_succeeds() throws Exception {
new DefaultInternalRunner(SuccessTest.class, supplier)
.run(newNotifier(runListener));
verify(runListener, never()).testFailure(any(Failure.class));
verify(runListener, times(1)).testFinished(any(Description.class));
verify(mockitoTestListener, only()).testFinished(any(TestFinishedEvent.class));
}
@Test
public void does_not_fail_second_test_when_first_test_fail() throws Exception {
new DefaultInternalRunner(TestFailOnInitialization.class, supplier)
.run(newNotifier(runListener));
verify(runListener, times(1)).testFailure(any(Failure.class));
verify(runListener, times(1)).testFinished(any(Description.class));
verify(mockitoTestListener, only()).testFinished(any(TestFinishedEvent.class));
reset(runListener, mockitoTestListener);
new DefaultInternalRunner(SuccessTest.class, supplier)
.run(newNotifier(runListener));
verify(runListener, never()).testFailure(any(Failure.class));
verify(runListener, times(1)).testFinished(any(Description.class));
verify(mockitoTestListener, only()).testFinished(any(TestFinishedEvent.class));
}
private RunNotifier newNotifier(RunListener listener) {
RunNotifier notifier = new RunNotifier();
notifier.addListener(listener);
return notifier;
}
public static final class SuccessTest {
@Test
public void this_test_is_NOT_supposed_to_fail() {
assertTrue(true);
}
}
public static final class TestFailOnInitialization {
@Mock
private System system;
@Test
public void this_test_is_supposed_to_fail() {
assertNotNull(system);
}
}
}