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.assertNull;
10  
11  import jakarta.inject.Inject;
12  
13  import mockit.integration.junit5.JMockitExtension;
14  
15  import org.junit.jupiter.api.Test;
16  import org.junit.jupiter.api.extension.ExtendWith;
17  
18  /**
19   * The Class TestedClassWithFullMixedFieldDITest.
20   */
21  @ExtendWith(JMockitExtension.class)
22  class TestedClassWithFullMixedFieldDITest {
23  
24      /**
25       * The Class TestedClass.
26       */
27      static class TestedClass {
28  
29          /** The dependency. */
30          @Inject
31          Dependency dependency;
32  
33          /** The text. */
34          StringBuilder text;
35      }
36  
37      /**
38       * The Class Dependency.
39       */
40      static class Dependency {
41          /** The value. */
42          String value;
43      }
44  
45      /**
46       * The Class Dependency2.
47       */
48      static class Dependency2 {
49      }
50  
51      /**
52       * Verify that fields from JRE types are not initialized.
53       *
54       * @param tested
55       *            the tested
56       */
57      @Test
58      void verifyThatFieldsFromJRETypesAreNotInitialized(@Tested(fullyInitialized = true) TestedClass tested) {
59          assertNull(tested.text);
60          assertNull(tested.dependency.value);
61      }
62  
63      /**
64       * The Class TestedClass2.
65       */
66      static class TestedClass2 {
67  
68          /** The dependency 1. */
69          @Inject
70          Dependency dependency1;
71  
72          /** The dependency 2. */
73          Dependency2 dependency2;
74      }
75  
76      /**
77       * Verify that fields of user types are initialized even only some are annotated.
78       *
79       * @param tested
80       *            the tested
81       */
82      @Test
83      void verifyThatFieldsOfUserTypesAreInitializedEvenOnlySomeAreAnnotated(
84              @Tested(fullyInitialized = true) TestedClass2 tested) {
85          assertNotNull(tested.dependency1);
86          assertNotNull(tested.dependency2);
87      }
88  }