View Javadoc
1   package mockit;
2   
3   import javax.inject.Inject;
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 TestedFieldWithFailedFullDITest.
12   */
13  public final class TestedFieldWithFailedFullDITest {
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(IllegalStateException.class);
25          thrown.expectMessage("Missing @Tested or @Injectable");
26          thrown.expectMessage("for parameter \"value\" in constructor ClassWithParameterizedConstructor(int value)");
27          thrown.expectMessage("when initializing field ");
28          thrown.expectMessage("dependency");
29          thrown.expectMessage("of @Tested object \""
30                  + ClassWithFieldOfClassHavingParameterizedConstructor.class.getSimpleName() + " tested");
31      }
32  
33      /**
34       * The Class ClassWithFieldOfClassHavingParameterizedConstructor.
35       */
36      static class ClassWithFieldOfClassHavingParameterizedConstructor {
37          /** The dependency. */
38          @Inject
39          ClassWithParameterizedConstructor dependency;
40      }
41  
42      /**
43       * The Class ClassWithParameterizedConstructor.
44       */
45      static class ClassWithParameterizedConstructor {
46          /**
47           * Instantiates a new class with parameterized constructor.
48           *
49           * @param value
50           *            the value
51           */
52          ClassWithParameterizedConstructor(@SuppressWarnings("unused") int value) {
53          }
54      }
55  
56      /** The tested. */
57      @Tested(fullyInitialized = true)
58      ClassWithFieldOfClassHavingParameterizedConstructor tested;
59  
60      /**
61       * Attempt to use tested object whose creation failed due to injectable with null value.
62       */
63      @Test
64      public void attemptToUseTestedObjectWhoseCreationFailedDueToInjectableWithNullValue() {
65      }
66  
67      /**
68       * Attempt to use tested object whose creation failed due to injectable with null value 2.
69       */
70      @Test
71      public void attemptToUseTestedObjectWhoseCreationFailedDueToInjectableWithNullValue2() {
72      }
73  }