21
21
package io .jenkins .dockerjavaapi .client ;
22
22
23
23
import static org .hamcrest .CoreMatchers .sameInstance ;
24
- import static org .junit . Assert .assertThat ;
24
+ import static org .hamcrest . MatcherAssert .assertThat ;
25
25
import static org .mockito .Mockito .inOrder ;
26
26
import static org .mockito .Mockito .mock ;
27
27
import static org .mockito .Mockito .times ;
32
32
import java .lang .reflect .Method ;
33
33
import java .lang .reflect .Parameter ;
34
34
import java .util .ArrayList ;
35
- import java .util .Comparator ;
36
35
import java .util .List ;
37
- import org .junit .Test ;
38
- import org .junit .runner .RunWith ;
39
- import org .junit .runners .Parameterized ;
36
+ import org .junit .jupiter .params .ParameterizedTest ;
37
+ import org .junit .jupiter .params .provider .MethodSource ;
40
38
import org .mockito .InOrder ;
41
39
import org .mockito .exceptions .base .MockitoException ;
42
40
45
43
* method in the instance it delegates to. Uses reflection/introspection to
46
44
* ensure that this class doesn't need updating if new methods are added.
47
45
*/
48
- @ RunWith (Parameterized .class )
49
- public class DelegatingDockerClientTest {
46
+ class DelegatingDockerClientTest {
50
47
51
48
/**
52
49
* Defines the set of data that all test methods (in this test class) will be
@@ -60,8 +57,7 @@ public class DelegatingDockerClientTest {
60
57
*
61
58
* @return {@link Iterable} of [ {@link String}, {@link Method} ].
62
59
*/
63
- @ Parameterized .Parameters (name = "{0}" )
64
- public static Iterable <Object []> data () {
60
+ static Iterable <Object []> data () {
65
61
final List <Object []> data = new ArrayList <>();
66
62
final Method [] declaredMethods = DockerClient .class .getDeclaredMethods ();
67
63
for (Method m : declaredMethods ) {
@@ -78,25 +74,14 @@ public static Iterable<Object[]> data() {
78
74
final Object [] testCase = new Object [] {testCaseName .toString (), m };
79
75
data .add (testCase );
80
76
}
81
- data .sort (new Comparator <Object []>() {
82
- @ Override
83
- public int compare (Object [] o1 , Object [] o2 ) {
84
- final String n1 = (String ) o1 [0 ];
85
- final String n2 = (String ) o2 [0 ];
86
- return n1 .compareTo (n2 );
87
- }
77
+ data .sort ((o1 , o2 ) -> {
78
+ final String n1 = (String ) o1 [0 ];
79
+ final String n2 = (String ) o2 [0 ];
80
+ return n1 .compareTo (n2 );
88
81
});
89
82
return data ;
90
83
}
91
84
92
- private final String dockerClientMethodName ;
93
- private final Method dockerClientMethod ;
94
-
95
- public DelegatingDockerClientTest (String methodName , Method dockerClientMethod ) {
96
- this .dockerClientMethodName = methodName ;
97
- this .dockerClientMethod = dockerClientMethod ;
98
- }
99
-
100
85
private interface HookPoints {
101
86
void interceptAnswerCalled (Object originalAnswer );
102
87
@@ -123,8 +108,9 @@ protected void interceptVoid() {
123
108
}
124
109
}
125
110
126
- @ Test
127
- public void methodIsDelegatedCorrectly () throws Exception {
111
+ @ ParameterizedTest (name = "{0}" )
112
+ @ MethodSource ("data" )
113
+ void methodIsDelegatedCorrectly (String dockerClientMethodName , Method dockerClientMethod ) throws Exception {
128
114
// Given
129
115
final Parameter [] methodParameters = dockerClientMethod .getParameters ();
130
116
final Object [] mockParameters = createFakeArgumentValues (methodParameters );
@@ -179,7 +165,7 @@ private static Object createFakeObject(final Class<?> paramType, final String pa
179
165
// can access and make a real instance instead of a mock.
180
166
// MAINTENANCE NOTE:
181
167
// So far we've gotten away with only looking for a default constructor.
182
- // If, in future, this isn't enough then we could try picking another
168
+ // If, in the future, this isn't enough then we could try picking another
183
169
// constructor and trying to fake any arguments it needs.
184
170
final Constructor <?> defaultConstructor = paramType .getConstructor ();
185
171
return defaultConstructor .newInstance ();
0 commit comments