From 2fef0b090060471ef300b70f01966f9c467e187f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edd=C3=BA=20Mel=C3=A9ndez?= Date: Fri, 2 Dec 2022 18:03:49 -0600 Subject: [PATCH] move logic to isCompatibleWith --- .../utility/DockerImageName.java | 22 +++++++++---------- 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/core/src/main/java/org/testcontainers/utility/DockerImageName.java b/core/src/main/java/org/testcontainers/utility/DockerImageName.java index 01280f0287e..4b416ed8d17 100644 --- a/core/src/main/java/org/testcontainers/utility/DockerImageName.java +++ b/core/src/main/java/org/testcontainers/utility/DockerImageName.java @@ -11,7 +11,6 @@ import org.testcontainers.utility.Versioning.Sha256Versioning; import org.testcontainers.utility.Versioning.TagVersioning; -import java.util.Arrays; import java.util.regex.Pattern; @EqualsAndHashCode(exclude = { "rawName", "compatibleSubstituteFor" }) @@ -235,7 +234,14 @@ public DockerImageName asCompatibleSubstituteFor(DockerImageName otherImageName) */ public boolean isCompatibleWith(DockerImageName other) { // is this image already the same or equivalent? - if (other.equals(this)) { + String finalImageName; + if (this.repository.startsWith(LIBRARY_PREFIX)) { + finalImageName = this.repository; + } else { + finalImageName = LIBRARY_PREFIX + this.repository; + } + DockerImageName imageWithLibraryPrefix = DockerImageName.parse(finalImageName); + if (other.equals(this) || imageWithLibraryPrefix.equals(this)) { return true; } @@ -261,21 +267,13 @@ public void assertCompatibleWith(DockerImageName... anyOthers) { throw new IllegalArgumentException("anyOthers parameter must be non-empty"); } - DockerImageName[] dockerImageNames = Arrays.copyOf(anyOthers, anyOthers.length + 1); - if (this.repository.startsWith(LIBRARY_PREFIX)) { - dockerImageNames[dockerImageNames.length - 1] = DockerImageName.parse(this.repository); - } else { - String imageWithLibraryPrefix = LIBRARY_PREFIX + this.repository; - dockerImageNames[dockerImageNames.length - 1] = DockerImageName.parse(imageWithLibraryPrefix); - } - - for (DockerImageName anyOther : dockerImageNames) { + for (DockerImageName anyOther : anyOthers) { if (this.isCompatibleWith(anyOther)) { return; } } - final DockerImageName exampleOther = dockerImageNames[0]; + final DockerImageName exampleOther = anyOthers[0]; throw new IllegalStateException( String.format(