View Javadoc
1   /*
2    * MIT License
3    * Copyright (c) 2006-2025 JMockit developers
4    * See LICENSE file for full license text.
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   * The Class TestedClassInGlobalScopeTest.
21   */
22  @ExtendWith(JMockitExtension.class)
23  @TestMethodOrder(MethodName.class)
24  class TestedClassInGlobalScopeTest {
25  
26      /**
27       * The Class TestedClass.
28       */
29      static class TestedClass {
30          /** The some value. */
31          Integer someValue;
32      }
33  
34      /** The tested global. */
35      @Tested(fullyInitialized = true, global = true)
36      TestedClass testedGlobal;
37  
38      /** The tested local. */
39      @Tested(fullyInitialized = true)
40      TestedClass testedLocal;
41  
42      /**
43       * Use tested object in first step of tested scenario.
44       */
45      @Test
46      void useTestedObjectInFirstStepOfTestedScenario() {
47          assertNull(testedGlobal.someValue);
48          assertNotSame(testedGlobal, testedLocal);
49          testedGlobal.someValue = 123;
50      }
51  
52      /**
53       * Use tested object in second step of tested scenario.
54       */
55      @Test
56      void useTestedObjectInSecondStepOfTestedScenario() {
57          assertNotNull(testedGlobal.someValue);
58          assertNull(testedLocal.someValue);
59      }
60  }