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
10
11 final class TestedClassWithNoPublicConstructorTest {
12
13
14
15
16 @SuppressWarnings("unused")
17 public static final class TestedClassWithPackagePrivateConstructor {
18
19
20
21
22
23
24
25 private TestedClassWithPackagePrivateConstructor(int... values) {
26 throw new RuntimeException("Must not occur");
27 }
28
29
30
31
32
33
34
35
36
37 TestedClassWithPackagePrivateConstructor(int i, Collaborator collaborator) {
38 assertEquals(123, i);
39 assertNotNull(collaborator);
40 }
41
42
43
44
45
46
47
48
49
50
51
52 private TestedClassWithPackagePrivateConstructor(int i, Collaborator collaborator, String s) {
53 throw new RuntimeException("Must not occur");
54 }
55 }
56
57
58
59
60 @SuppressWarnings("UnusedDeclaration")
61 static class TestedClassWithPrivateConstructor {
62
63
64
65
66 private TestedClassWithPrivateConstructor() {
67 throw new RuntimeException("Must not occur");
68 }
69
70
71
72
73
74
75
76 private TestedClassWithPrivateConstructor(Collaborator collaborator) {
77 assertNotNull(collaborator);
78 }
79 }
80
81
82
83
84 static class Collaborator {
85
86
87
88 static void doSomething() {
89 }
90 }
91
92
93 @Tested
94 TestedClassWithPackagePrivateConstructor tested1;
95
96
97 @Tested
98 TestedClassWithPrivateConstructor tested2;
99
100
101 @Injectable
102 int i = 123;
103
104
105 @Injectable
106 Collaborator collaborator;
107
108
109
110
111 @Test
112 void verifyInstantiationOfTestedObjectsThroughInjectedConstructors() {
113 assertNotNull(tested1);
114 assertNotNull(tested2);
115 }
116 }