1212import org .testcontainers .DockerClientFactory ;
1313import org .testcontainers .TestImages ;
1414import org .testcontainers .Testcontainers ;
15+ import org .testcontainers .utility .TestcontainersConfiguration ;
1516
1617import java .io .IOException ;
1718import java .io .OutputStream ;
1819import java .net .InetSocketAddress ;
19- import java .util .HashMap ;
2020import java .util .List ;
21- import java .util .Map ;
2221import java .util .UUID ;
2322
2423import static org .assertj .core .api .Assertions .assertThat ;
24+ import static org .assertj .core .api .Assumptions .assumeThat ;
2525
2626public class ExposedHostTest {
2727
@@ -91,16 +91,11 @@ public void testExposedHostPortOnFixedInternalPorts() {
9191
9292 @ Test
9393 public void testExposedHostWithReusableContainerAndFixedNetworkName () throws IOException , InterruptedException {
94- Map <String , String > labels = new HashMap <>();
95- labels .put ("exposeHostPorts" , "samePorts" );
96-
94+ assumeThat (TestcontainersConfiguration .getInstance ().environmentSupportsReuse ()).isTrue ();
9795 Network network = createReusableNetwork (UUID .randomUUID ());
9896 Testcontainers .exposeHostPorts (server .getAddress ().getPort ());
9997
100- GenericContainer <?> container = new GenericContainer <>(tinyContainerDef ())
101- .withLabels (labels )
102- .withReuse (true )
103- .withNetwork (network );
98+ GenericContainer <?> container = new GenericContainer <>(tinyContainerDef ()).withReuse (true ).withNetwork (network );
10499 container .start ();
105100
106101 assertHttpResponseFromHost (container , server .getAddress ().getPort ());
@@ -109,7 +104,6 @@ public void testExposedHostWithReusableContainerAndFixedNetworkName() throws IOE
109104 Testcontainers .exposeHostPorts (server .getAddress ().getPort ());
110105
111106 GenericContainer <?> reusedContainer = new GenericContainer <>(tinyContainerDef ())
112- .withLabels (labels )
113107 .withReuse (true )
114108 .withNetwork (network );
115109 reusedContainer .start ();
@@ -125,16 +119,11 @@ public void testExposedHostWithReusableContainerAndFixedNetworkName() throws IOE
125119 @ Test
126120 public void testExposedHostOnFixedInternalPortsWithReusableContainerAndFixedNetworkName ()
127121 throws IOException , InterruptedException {
128- Map <String , String > labels = new HashMap <>();
129- labels .put ("exposeHostPorts" , "differentPorts" );
130-
122+ assumeThat (TestcontainersConfiguration .getInstance ().environmentSupportsReuse ()).isTrue ();
131123 Network network = createReusableNetwork (UUID .randomUUID ());
132124 Testcontainers .exposeHostPorts (ImmutableMap .of (server .getAddress ().getPort (), 1234 ));
133125
134- GenericContainer <?> container = new GenericContainer <>(tinyContainerDef ())
135- .withLabels (labels )
136- .withReuse (true )
137- .withNetwork (network );
126+ GenericContainer <?> container = new GenericContainer <>(tinyContainerDef ()).withReuse (true ).withNetwork (network );
138127 container .start ();
139128
140129 assertHttpResponseFromHost (container , 1234 );
@@ -143,7 +132,6 @@ public void testExposedHostOnFixedInternalPortsWithReusableContainerAndFixedNetw
143132 Testcontainers .exposeHostPorts (ImmutableMap .of (server .getAddress ().getPort (), 1234 ));
144133
145134 GenericContainer <?> reusedContainer = new GenericContainer <>(tinyContainerDef ())
146- .withLabels (labels )
147135 .withReuse (true )
148136 .withNetwork (network );
149137 reusedContainer .start ();
0 commit comments