99import com .github .dockerjava .api .command .InspectContainerResponse ;
1010import com .github .dockerjava .api .command .ListContainersCmd ;
1111import com .github .dockerjava .api .command .StartContainerCmd ;
12+ import com .github .dockerjava .api .model .Container ;
1213import com .github .dockerjava .core .command .CreateContainerCmdImpl ;
1314import com .github .dockerjava .core .command .InspectContainerCmdImpl ;
1415import com .github .dockerjava .core .command .ListContainersCmdImpl ;
1516import com .github .dockerjava .core .command .StartContainerCmdImpl ;
1617import lombok .RequiredArgsConstructor ;
1718import lombok .experimental .FieldDefaults ;
18- import org .junit .Rule ;
19- import org .junit .jupiter .api .Nested ;
2019import org .junit .jupiter .api .Test ;
2120import org .junit .jupiter .params .ParameterizedClass ;
2221import org .junit .jupiter .params .provider .MethodSource ;
23- import org .junit .runner .RunWith ;
24- import org .junit .runners .BlockJUnit4ClassRunner ;
2522import org .mockito .Answers ;
2623import org .mockito .Mockito ;
2724import org .mockito .stubbing .Answer ;
2825import org .testcontainers .DockerClientFactory ;
2926import org .testcontainers .TestImages ;
3027import org .testcontainers .containers .startupcheck .StartupCheckStrategy ;
3128import org .testcontainers .containers .wait .strategy .AbstractWaitStrategy ;
32- import org .testcontainers .utility .MockTestcontainersConfigurationRule ;
29+ import org .testcontainers .utility .MockTestcontainersConfiguration ;
3330import org .testcontainers .utility .MountableFile ;
3431import org .testcontainers .utility .TestcontainersConfiguration ;
3532
5552
5653public class ReusabilityUnitTests {
5754
58- @ Nested
5955 @ ParameterizedClass
6056 @ MethodSource ("data" )
6157 @ RequiredArgsConstructor
6258 @ FieldDefaults (makeFinal = true )
63- public class CanBeReusedTest {
64- public Object [][] data () {
59+ public static class CanBeReusedTest {
60+ public static Object [][] data () {
6561 return new Object [][] {
6662 { "generic" , new GenericContainer <>(TestImages .TINY_IMAGE ), true },
6763 { "anonymous generic" , new GenericContainer (TestImages .TINY_IMAGE ) {}, true },
@@ -86,14 +82,14 @@ public void shouldBeReusable() {
8682 }
8783 }
8884
89- class CustomContainer extends GenericContainer <CustomContainer > {
85+ static class CustomContainer extends GenericContainer <CustomContainer > {
9086
9187 CustomContainer () {
9288 super (TestImages .TINY_IMAGE );
9389 }
9490 }
9591
96- class CustomContainerWithContainerIsCreated
92+ static class CustomContainerWithContainerIsCreated
9793 extends GenericContainer <CustomContainerWithContainerIsCreated > {
9894
9995 CustomContainerWithContainerIsCreated () {
@@ -107,10 +103,8 @@ protected void containerIsCreated(String containerId) {
107103 }
108104 }
109105
110- @ Nested
111- @ RunWith (BlockJUnit4ClassRunner .class )
112106 @ FieldDefaults (makeFinal = true )
113- public class HooksTest extends AbstractReusabilityTest {
107+ public static class HooksTest extends AbstractReusabilityTest {
114108
115109 List <String > script = new ArrayList <>();
116110
@@ -189,10 +183,8 @@ public void shouldNotCallHookIfNotReused() {
189183 }
190184 }
191185
192- @ Nested
193- @ RunWith (BlockJUnit4ClassRunner .class )
194186 @ FieldDefaults (makeFinal = true )
195- public class HashTest extends AbstractReusabilityTest {
187+ public static class HashTest extends AbstractReusabilityTest {
196188
197189 protected GenericContainer <?> container = makeReusable (
198190 new GenericContainer (TestImages .TINY_IMAGE ) {
@@ -304,22 +296,20 @@ public void shouldHashCopiedFiles() {
304296 }
305297 }
306298
307-
308- interface TestStrategy {
309- void withCopyFileToContainer (MountableFile mountableFile , String path );
310-
311- void clear ();
312- }
313-
314- @ Nested
315299 @ ParameterizedClass
316300 @ MethodSource ("strategies" )
317301 @ FieldDefaults (makeFinal = true )
318- public class CopyFilesHashTest {
302+ public static class CopyFilesHashTest {
319303
320304 private final TestStrategy strategy ;
321305
322- private class MountableFileTestStrategy implements TestStrategy {
306+ interface TestStrategy {
307+ void withCopyFileToContainer (MountableFile mountableFile , String path );
308+
309+ void clear ();
310+ }
311+
312+ private static class MountableFileTestStrategy implements TestStrategy {
323313
324314 private final GenericContainer <?> container ;
325315
@@ -338,7 +328,7 @@ public void clear() {
338328 }
339329 }
340330
341- private class TransferableTestStrategy implements TestStrategy {
331+ private static class TransferableTestStrategy implements TestStrategy {
342332
343333 private final GenericContainer <?> container ;
344334
@@ -357,7 +347,7 @@ public void clear() {
357347 }
358348 }
359349
360- public List <Function <GenericContainer <?>, TestStrategy >> strategies () {
350+ public static List <Function <GenericContainer <?>, TestStrategy >> strategies () {
361351 return Arrays .asList (MountableFileTestStrategy ::new , TransferableTestStrategy ::new );
362352 }
363353
@@ -508,11 +498,9 @@ public void folderPermissions() throws Exception {
508498 }
509499 }
510500
501+ @ MockTestcontainersConfiguration
511502 @ FieldDefaults (makeFinal = true )
512- public abstract class AbstractReusabilityTest {
513-
514- @ Rule
515- public MockTestcontainersConfigurationRule configurationMock = new MockTestcontainersConfigurationRule ();
503+ public abstract static class AbstractReusabilityTest {
516504
517505 protected DockerClient client = Mockito .mock (DockerClient .class );
518506
0 commit comments