1111import com .github .dockerjava .core .command .StartContainerCmdImpl ;
1212import lombok .RequiredArgsConstructor ;
1313import lombok .experimental .FieldDefaults ;
14- import org .junit .Assume ;
14+ import org .junit .Rule ;
1515import org .junit .Test ;
1616import org .junit .experimental .runners .Enclosed ;
1717import org .junit .runner .RunWith ;
2323import org .testcontainers .DockerClientFactory ;
2424import org .testcontainers .containers .startupcheck .StartupCheckStrategy ;
2525import org .testcontainers .containers .wait .strategy .AbstractWaitStrategy ;
26+ import org .testcontainers .utility .MockTestcontainersConfigurationRule ;
2627import org .testcontainers .utility .TestcontainersConfiguration ;
2728
2829import java .util .ArrayList ;
@@ -128,9 +129,8 @@ protected void containerIsStarted(InspectContainerResponse containerInfo, boolea
128129
129130 @ Test
130131 public void shouldSetLabelsIfEnvironmentDoesNotSupportReuse () {
131- // TODO mock TestcontainersConfiguration
132- Assume .assumeFalse ("does not support reuse" , TestcontainersConfiguration .getInstance ().environmentSupportsReuse ());
133- AtomicReference <CreateContainerCmd > commandRef = new AtomicReference <>();
132+ Mockito .doReturn (false ).when (TestcontainersConfiguration .getInstance ()).environmentSupportsReuse ();
133+
134134 String containerId = randomContainerId ();
135135 when (client .createContainerCmd (any ())).then (createContainerAnswer (containerId ));
136136 when (client .listContainersCmd ()).then (listContainersAnswer ());
@@ -147,8 +147,7 @@ public void shouldSetLabelsIfEnvironmentDoesNotSupportReuse() {
147147
148148 @ Test
149149 public void shouldCallHookIfReused () {
150- // TODO mock TestcontainersConfiguration
151- Assume .assumeTrue ("supports reuse" , TestcontainersConfiguration .getInstance ().environmentSupportsReuse ());
150+ Mockito .doReturn (true ).when (TestcontainersConfiguration .getInstance ()).environmentSupportsReuse ();
152151 String containerId = randomContainerId ();
153152 when (client .createContainerCmd (any ())).then (createContainerAnswer (containerId ));
154153 String existingContainerId = randomContainerId ();
@@ -200,8 +199,7 @@ public void shouldStartIfListReturnsEmpty() {
200199
201200 @ Test
202201 public void shouldReuseIfListReturnsID () {
203- // TODO mock TestcontainersConfiguration
204- Assume .assumeTrue ("supports reuse" , TestcontainersConfiguration .getInstance ().environmentSupportsReuse ());
202+ Mockito .doReturn (true ).when (TestcontainersConfiguration .getInstance ()).environmentSupportsReuse ();
205203 String containerId = randomContainerId ();
206204 when (client .createContainerCmd (any ())).then (createContainerAnswer (containerId ));
207205 String existingContainerId = randomContainerId ();
@@ -216,8 +214,7 @@ public void shouldReuseIfListReturnsID() {
216214
217215 @ Test
218216 public void shouldSetLabelsIfEnvironmentDoesNotSupportReuse () {
219- // TODO mock TestcontainersConfiguration
220- Assume .assumeFalse ("does not support reuse" , TestcontainersConfiguration .getInstance ().environmentSupportsReuse ());
217+ Mockito .doReturn (false ).when (TestcontainersConfiguration .getInstance ()).environmentSupportsReuse ();
221218 AtomicReference <CreateContainerCmd > commandRef = new AtomicReference <>();
222219 String containerId = randomContainerId ();
223220 when (client .createContainerCmd (any ())).then (createContainerAnswer (containerId , commandRef ::set ));
@@ -236,19 +233,29 @@ public void shouldSetLabelsIfEnvironmentDoesNotSupportReuse() {
236233 }
237234
238235 @ FieldDefaults (makeFinal = true )
239- static abstract class AbstractReusabilityTest {
236+ public static abstract class AbstractReusabilityTest {
237+
238+ @ Rule
239+ public MockTestcontainersConfigurationRule configurationMock = new MockTestcontainersConfigurationRule ();
240240
241241 protected DockerClient client = Mockito .mock (DockerClient .class );
242242
243243 protected <T extends GenericContainer <?>> T makeReusable (T container ) {
244244 container .dockerClient = client ;
245245 container .withNetworkMode ("none" ); // to disable the port forwarding
246246 container .withStartupCheckStrategy (new StartupCheckStrategy () {
247- @ Override
248- public StartupStatus checkStartupState (DockerClient dockerClient , String containerId ) {
249- return StartupStatus .SUCCESSFUL ;
250- }
251- });
247+
248+ @ Override
249+ public boolean waitUntilStartupSuccessful (DockerClient dockerClient , String containerId ) {
250+ // Skip DockerClient rate limiter
251+ return true ;
252+ }
253+
254+ @ Override
255+ public StartupStatus checkStartupState (DockerClient dockerClient , String containerId ) {
256+ return StartupStatus .SUCCESSFUL ;
257+ }
258+ });
252259 container .waitingFor (new AbstractWaitStrategy () {
253260 @ Override
254261 protected void waitUntilReady () {
0 commit comments