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 ;
20+ import org .junit .jupiter .api .extension .ExtendWith ;
2121import org .junit .jupiter .params .ParameterizedClass ;
2222import org .junit .jupiter .params .provider .MethodSource ;
23- import org .junit .runner .RunWith ;
24- import org .junit .runners .BlockJUnit4ClassRunner ;
2523import org .mockito .Answers ;
2624import org .mockito .Mockito ;
2725import org .mockito .stubbing .Answer ;
2826import org .testcontainers .DockerClientFactory ;
2927import org .testcontainers .TestImages ;
28+ import org .testcontainers .containers .ReusabilityUnitTests .CanBeReusedTest .CustomContainer ;
29+ import org .testcontainers .containers .ReusabilityUnitTests .CanBeReusedTest .CustomContainerWithContainerIsCreated ;
30+ import org .testcontainers .containers .ReusabilityUnitTests .CopyFilesHashTest .TestStrategy ;
3031import org .testcontainers .containers .startupcheck .StartupCheckStrategy ;
32+ import org .testcontainers .containers .startupcheck .StartupCheckStrategy .StartupStatus ;
3133import org .testcontainers .containers .wait .strategy .AbstractWaitStrategy ;
32- import org .testcontainers .utility .MockTestcontainersConfigurationRule ;
34+ import org .testcontainers .utility .MockTestcontainersConfigurationExtension ;
3335import org .testcontainers .utility .MountableFile ;
3436import org .testcontainers .utility .TestcontainersConfiguration ;
3537
5557
5658public class ReusabilityUnitTests {
5759
58- @ Nested
5960 @ ParameterizedClass
6061 @ MethodSource ("data" )
6162 @ RequiredArgsConstructor
6263 @ FieldDefaults (makeFinal = true )
63- public class CanBeReusedTest {
64- public Object [][] data () {
64+ public static class CanBeReusedTest {
65+
66+ public static Object [][] data () {
6567 return new Object [][] {
6668 { "generic" , new GenericContainer <>(TestImages .TINY_IMAGE ), true },
6769 { "anonymous generic" , new GenericContainer (TestImages .TINY_IMAGE ) {}, true },
@@ -86,14 +88,14 @@ public void shouldBeReusable() {
8688 }
8789 }
8890
89- class CustomContainer extends GenericContainer <CustomContainer > {
91+ static class CustomContainer extends GenericContainer <CustomContainer > {
9092
9193 CustomContainer () {
9294 super (TestImages .TINY_IMAGE );
9395 }
9496 }
9597
96- class CustomContainerWithContainerIsCreated
98+ static class CustomContainerWithContainerIsCreated
9799 extends GenericContainer <CustomContainerWithContainerIsCreated > {
98100
99101 CustomContainerWithContainerIsCreated () {
@@ -107,10 +109,8 @@ protected void containerIsCreated(String containerId) {
107109 }
108110 }
109111
110- @ Nested
111- @ RunWith (BlockJUnit4ClassRunner .class )
112112 @ FieldDefaults (makeFinal = true )
113- public class HooksTest extends AbstractReusabilityTest {
113+ public static class HooksTest extends AbstractReusabilityTest {
114114
115115 List <String > script = new ArrayList <>();
116116
@@ -189,10 +189,8 @@ public void shouldNotCallHookIfNotReused() {
189189 }
190190 }
191191
192- @ Nested
193- @ RunWith (BlockJUnit4ClassRunner .class )
194192 @ FieldDefaults (makeFinal = true )
195- public class HashTest extends AbstractReusabilityTest {
193+ public static class HashTest extends AbstractReusabilityTest {
196194
197195 protected GenericContainer <?> container = makeReusable (
198196 new GenericContainer (TestImages .TINY_IMAGE ) {
@@ -304,22 +302,20 @@ public void shouldHashCopiedFiles() {
304302 }
305303 }
306304
307-
308- interface TestStrategy {
309- void withCopyFileToContainer (MountableFile mountableFile , String path );
310-
311- void clear ();
312- }
313-
314- @ Nested
315305 @ ParameterizedClass
316306 @ MethodSource ("strategies" )
317307 @ FieldDefaults (makeFinal = true )
318- public class CopyFilesHashTest {
308+ public static class CopyFilesHashTest {
319309
320310 private final TestStrategy strategy ;
321311
322- private class MountableFileTestStrategy implements TestStrategy {
312+ interface TestStrategy {
313+ void withCopyFileToContainer (MountableFile mountableFile , String path );
314+
315+ void clear ();
316+ }
317+
318+ private static class MountableFileTestStrategy implements TestStrategy {
323319
324320 private final GenericContainer <?> container ;
325321
@@ -338,7 +334,7 @@ public void clear() {
338334 }
339335 }
340336
341- private class TransferableTestStrategy implements TestStrategy {
337+ private static class TransferableTestStrategy implements TestStrategy {
342338
343339 private final GenericContainer <?> container ;
344340
@@ -357,7 +353,7 @@ public void clear() {
357353 }
358354 }
359355
360- public List <Function <GenericContainer <?>, TestStrategy >> strategies () {
356+ public static List <Function <GenericContainer <?>, TestStrategy >> strategies () {
361357 return Arrays .asList (MountableFileTestStrategy ::new , TransferableTestStrategy ::new );
362358 }
363359
@@ -508,11 +504,9 @@ public void folderPermissions() throws Exception {
508504 }
509505 }
510506
507+ @ ExtendWith (MockTestcontainersConfigurationExtension .class )
511508 @ FieldDefaults (makeFinal = true )
512- public abstract class AbstractReusabilityTest {
513-
514- @ Rule
515- public MockTestcontainersConfigurationRule configurationMock = new MockTestcontainersConfigurationRule ();
509+ public abstract static class AbstractReusabilityTest {
516510
517511 protected DockerClient client = Mockito .mock (DockerClient .class );
518512
0 commit comments