View Javadoc
1   package mockit;
2   
3   import static org.junit.jupiter.api.Assertions.assertEquals;
4   
5   import org.junit.Before;
6   import org.junit.Rule;
7   import org.junit.Test;
8   import org.junit.rules.ExpectedException;
9   
10  /**
11   * The Class TestedFieldWithFailedConstructorDITest.
12   */
13  public final class TestedFieldWithFailedConstructorDITest {
14  
15      /** The thrown. */
16      @Rule
17      public final ExpectedException thrown = ExpectedException.none();
18  
19      /**
20       * Configure expected exception.
21       */
22      @Before
23      public void configureExpectedException() {
24          thrown.expect(IllegalArgumentException.class);
25          thrown.expectMessage("No injectable value available for parameter \"value\" in constructor ");
26          thrown.expectMessage("ClassWithOneParameter(Integer value)");
27      }
28  
29      /**
30       * The Class ClassWithOneParameter.
31       */
32      static class ClassWithOneParameter {
33  
34          /** The value. */
35          Integer value;
36  
37          /**
38           * Instantiates a new class with one parameter.
39           *
40           * @param value
41           *            the value
42           */
43          ClassWithOneParameter(Integer value) {
44              this.value = value;
45          }
46      }
47  
48      /** The tested. */
49      @Tested
50      ClassWithOneParameter tested;
51  
52      /** The foo. */
53      @Injectable
54      Integer foo;
55  
56      /**
57       * Attempt to use tested object whose creation failed due to injectable without A value.
58       *
59       * @param s
60       *            the s
61       */
62      @Test
63      public void attemptToUseTestedObjectWhoseCreationFailedDueToInjectableWithoutAValue(@Injectable String s) {
64          assertEquals("", s);
65      }
66  }