View Javadoc
1   package mockit;
2   
3   import static org.junit.jupiter.api.Assertions.assertEquals;
4   import static org.junit.jupiter.api.Assertions.assertNotNull;
5   
6   import org.junit.jupiter.api.Test;
7   
8   /**
9    * The Class TestedClassWithNoPublicConstructorTest.
10   */
11  final class TestedClassWithNoPublicConstructorTest {
12  
13      /**
14       * The Class TestedClassWithPackagePrivateConstructor.
15       */
16      @SuppressWarnings("unused")
17      public static final class TestedClassWithPackagePrivateConstructor {
18  
19          /**
20           * Instantiates a new tested class with package private constructor.
21           *
22           * @param values
23           *            the values
24           */
25          private TestedClassWithPackagePrivateConstructor(int... values) {
26              throw new RuntimeException("Must not occur");
27          }
28  
29          /**
30           * Instantiates a new tested class with package private constructor.
31           *
32           * @param i
33           *            the i
34           * @param collaborator
35           *            the collaborator
36           */
37          TestedClassWithPackagePrivateConstructor(int i, Collaborator collaborator) {
38              assertEquals(123, i);
39              assertNotNull(collaborator);
40          }
41  
42          /**
43           * Instantiates a new tested class with package private constructor.
44           *
45           * @param i
46           *            the i
47           * @param collaborator
48           *            the collaborator
49           * @param s
50           *            the s
51           */
52          private TestedClassWithPackagePrivateConstructor(int i, Collaborator collaborator, String s) {
53              throw new RuntimeException("Must not occur");
54          }
55      }
56  
57      /**
58       * The Class TestedClassWithPrivateConstructor.
59       */
60      @SuppressWarnings("UnusedDeclaration")
61      static class TestedClassWithPrivateConstructor {
62  
63          /**
64           * Instantiates a new tested class with private constructor.
65           */
66          private TestedClassWithPrivateConstructor() {
67              throw new RuntimeException("Must not occur");
68          }
69  
70          /**
71           * Instantiates a new tested class with private constructor.
72           *
73           * @param collaborator
74           *            the collaborator
75           */
76          private TestedClassWithPrivateConstructor(Collaborator collaborator) {
77              assertNotNull(collaborator);
78          }
79      }
80  
81      /**
82       * The Class Collaborator.
83       */
84      static class Collaborator {
85          /**
86           * Do something.
87           */
88          static void doSomething() {
89          }
90      }
91  
92      /** The tested 1. */
93      @Tested
94      TestedClassWithPackagePrivateConstructor tested1;
95  
96      /** The tested 2. */
97      @Tested
98      TestedClassWithPrivateConstructor tested2;
99  
100     /** The i. */
101     @Injectable
102     int i = 123;
103 
104     /** The collaborator. */
105     @Injectable
106     Collaborator collaborator;
107 
108     /**
109      * Verify instantiation of tested objects through injected constructors.
110      */
111     @Test
112     void verifyInstantiationOfTestedObjectsThroughInjectedConstructors() {
113         assertNotNull(tested1);
114         assertNotNull(tested2);
115     }
116 }