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.assertEquals;
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 TestedFieldWithFailedConstructorDITest.
18   */
19  @ExtendWith(JMockitExtension.class)
20  class TestedFieldWithFailedConstructorDITest {
21  
22      /**
23       * The Class ClassWithOneParameter.
24       */
25      static class ClassWithOneParameter {
26  
27          /** The value. */
28          Integer value;
29  
30          /**
31           * Instantiates a new class with one parameter.
32           *
33           * @param value
34           *            the value
35           */
36          ClassWithOneParameter(Integer value) {
37              this.value = value;
38          }
39      }
40  
41      /** The tested. */
42      @Tested
43      ClassWithOneParameter tested;
44  
45      /** The foo. */
46      @Injectable
47      Integer foo;
48  
49      /**
50       * Attempt to use tested object whose creation failed due to injectable without A value.
51       *
52       * @param s
53       *            the s
54       */
55      @Test
56      @ExpectedException(value = IllegalArgumentException.class, expectedMessages = "No injectable value available for parameter \"value\" in constructor ClassWithOneParameter(Integer value)")
57      void attemptToUseTestedObjectWhoseCreationFailedDueToInjectableWithoutAValue(@Injectable String s) {
58          // This will not run as constructor failed above
59          assertEquals("", s);
60      }
61  }