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 jakarta.inject.Inject;
9   
10  import mockit.integration.junit5.ExpectedException;
11  import mockit.integration.junit5.JMockitExtension;
12  
13  import org.junit.jupiter.api.Test;
14  import org.junit.jupiter.api.extension.ExtendWith;
15  
16  /**
17   * The Class TestedFieldWithFailedFullDITest.
18   */
19  @ExtendWith(JMockitExtension.class)
20  class TestedFieldWithFailedFullDITest {
21  
22      /**
23       * The Class ClassWithFieldOfClassHavingParameterizedConstructor.
24       */
25      static class ClassWithFieldOfClassHavingParameterizedConstructor {
26          /** The dependency. */
27          @Inject
28          ClassWithParameterizedConstructor dependency;
29      }
30  
31      /**
32       * The Class ClassWithParameterizedConstructor.
33       */
34      static class ClassWithParameterizedConstructor {
35          /**
36           * Instantiates a new class with parameterized constructor.
37           *
38           * @param value
39           *            the value
40           */
41          ClassWithParameterizedConstructor(@SuppressWarnings("unused") int value) {
42          }
43      }
44  
45      /** The tested. */
46      @Tested(fullyInitialized = true)
47      ClassWithFieldOfClassHavingParameterizedConstructor tested;
48  
49      /**
50       * Attempt to use tested object whose creation failed due to injectable with null value.
51       */
52      @Test
53      @ExpectedException(value = IllegalStateException.class, expectedMessages = { "Missing @Tested or @Injectable",
54              "for parameter \"value\" in constructor ClassWithParameterizedConstructor(int value)",
55              "when initializing field ", "dependency",
56              "of @Tested object \"ClassWithFieldOfClassHavingParameterizedConstructor tested" })
57      void attemptToUseTestedObjectWhoseCreationFailedDueToInjectableWithNullValue() {
58      }
59  
60      /**
61       * Attempt to use tested object whose creation failed due to injectable with null value 2.
62       */
63      @Test
64      @ExpectedException(value = IllegalStateException.class, expectedMessages = { "Missing @Tested or @Injectable",
65              "for parameter \"value\" in constructor ClassWithParameterizedConstructor(int value)",
66              "when initializing field ", "dependency",
67              "of @Tested object \"ClassWithFieldOfClassHavingParameterizedConstructor tested" })
68      void attemptToUseTestedObjectWhoseCreationFailedDueToInjectableWithNullValue2() {
69      }
70  }