1
2
3
4
5
6 package mockit;
7
8 import static org.junit.jupiter.api.Assertions.assertNotNull;
9 import static org.junit.jupiter.api.Assertions.assertNotSame;
10 import static org.junit.jupiter.api.Assertions.assertNull;
11
12 import mockit.integration.junit5.JMockitExtension;
13
14 import org.junit.jupiter.api.MethodOrderer.MethodName;
15 import org.junit.jupiter.api.Test;
16 import org.junit.jupiter.api.TestMethodOrder;
17 import org.junit.jupiter.api.extension.ExtendWith;
18
19
20
21
22 @ExtendWith(JMockitExtension.class)
23 @TestMethodOrder(MethodName.class)
24 class TestedClassInGlobalScopeTest {
25
26
27
28
29 static class TestedClass {
30
31 Integer someValue;
32 }
33
34
35 @Tested(fullyInitialized = true, global = true)
36 TestedClass testedGlobal;
37
38
39 @Tested(fullyInitialized = true)
40 TestedClass testedLocal;
41
42
43
44
45 @Test
46 void useTestedObjectInFirstStepOfTestedScenario() {
47 assertNull(testedGlobal.someValue);
48 assertNotSame(testedGlobal, testedLocal);
49 testedGlobal.someValue = 123;
50 }
51
52
53
54
55 @Test
56 void useTestedObjectInSecondStepOfTestedScenario() {
57 assertNotNull(testedGlobal.someValue);
58 assertNull(testedLocal.someValue);
59 }
60 }