Skip to content

Commit

Permalink
Override ChainedImageNameSubstitutor toString (#7522)
Browse files Browse the repository at this point in the history
Returns ChainedImageNameSubstitutor's getDescription

Fixes #7039
  • Loading branch information
eddumelendez committed Sep 13, 2023
1 parent e67fc7d commit 00cc0ea
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,11 @@ protected String getDescription() {
configuredInstance.getDescription()
);
}

@Override
public String toString() {
return getDescription();
}
}

private static class NoopImageNameSubstitutor extends ImageNameSubstitutor {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
import org.junit.Rule;
import org.junit.Test;
import org.mockito.Mockito;
import org.testcontainers.containers.GenericContainer;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.ArgumentMatchers.eq;

public class ImageNameSubstitutorTest {
Expand Down Expand Up @@ -64,4 +66,19 @@ public void testWorksWithoutConfiguredImplementation() {
.as("the image has been substituted by default then configured implementations")
.isEqualTo("substituted-image:latest");
}

@Test
public void testImageNameSubstitutorToString() {
Mockito
.doReturn(FakeImageSubstitutor.class.getCanonicalName())
.when(TestcontainersConfiguration.getInstance())
.getImageSubstitutorClassName();

try (GenericContainer<?> container = new GenericContainer<>(DockerImageName.parse("original"))) {
assertThatThrownBy(container::start)
.hasMessageContaining(
"imageNameSubstitutor=Chained substitutor of 'default implementation' and then 'test implementation'"
);
}
}
}

0 comments on commit 00cc0ea

Please sign in to comment.