2121package io .jenkins .dockerjavaapi .client ;
2222
2323import static org .hamcrest .CoreMatchers .sameInstance ;
24- import static org .junit . Assert .assertThat ;
24+ import static org .hamcrest . MatcherAssert .assertThat ;
2525import static org .mockito .Mockito .inOrder ;
2626import static org .mockito .Mockito .mock ;
2727import static org .mockito .Mockito .times ;
3232import java .lang .reflect .Method ;
3333import java .lang .reflect .Parameter ;
3434import java .util .ArrayList ;
35- import java .util .Comparator ;
3635import 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 ;
4038import org .mockito .InOrder ;
4139import org .mockito .exceptions .base .MockitoException ;
4240
4543 * method in the instance it delegates to. Uses reflection/introspection to
4644 * ensure that this class doesn't need updating if new methods are added.
4745 */
48- @ RunWith (Parameterized .class )
49- public class DelegatingDockerClientTest {
46+ class DelegatingDockerClientTest {
5047
5148 /**
5249 * Defines the set of data that all test methods (in this test class) will be
@@ -60,8 +57,7 @@ public class DelegatingDockerClientTest {
6057 *
6158 * @return {@link Iterable} of [ {@link String}, {@link Method} ].
6259 */
63- @ Parameterized .Parameters (name = "{0}" )
64- public static Iterable <Object []> data () {
60+ static Iterable <Object []> data () {
6561 final List <Object []> data = new ArrayList <>();
6662 final Method [] declaredMethods = DockerClient .class .getDeclaredMethods ();
6763 for (Method m : declaredMethods ) {
@@ -78,25 +74,14 @@ public static Iterable<Object[]> data() {
7874 final Object [] testCase = new Object [] {testCaseName .toString (), m };
7975 data .add (testCase );
8076 }
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 );
8881 });
8982 return data ;
9083 }
9184
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-
10085 private interface HookPoints {
10186 void interceptAnswerCalled (Object originalAnswer );
10287
@@ -123,8 +108,9 @@ protected void interceptVoid() {
123108 }
124109 }
125110
126- @ Test
127- public void methodIsDelegatedCorrectly () throws Exception {
111+ @ ParameterizedTest (name = "{0}" )
112+ @ MethodSource ("data" )
113+ void methodIsDelegatedCorrectly (String dockerClientMethodName , Method dockerClientMethod ) throws Exception {
128114 // Given
129115 final Parameter [] methodParameters = dockerClientMethod .getParameters ();
130116 final Object [] mockParameters = createFakeArgumentValues (methodParameters );
@@ -179,7 +165,7 @@ private static Object createFakeObject(final Class<?> paramType, final String pa
179165 // can access and make a real instance instead of a mock.
180166 // MAINTENANCE NOTE:
181167 // 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
183169 // constructor and trying to fake any arguments it needs.
184170 final Constructor <?> defaultConstructor = paramType .getConstructor ();
185171 return defaultConstructor .newInstance ();
0 commit comments