diff --git a/src/main/java/com/nirima/jenkins/plugins/docker/DockerCloud.java b/src/main/java/com/nirima/jenkins/plugins/docker/DockerCloud.java index 16cc22da..ec90b3d3 100644 --- a/src/main/java/com/nirima/jenkins/plugins/docker/DockerCloud.java +++ b/src/main/java/com/nirima/jenkins/plugins/docker/DockerCloud.java @@ -139,8 +139,7 @@ public DockerCloud(String name, DockerAPI dockerApi, List templa this.dockerApi = dockerApi; this.templates = templates; if (name == null || name.isBlank()) { - LOGGER.warn( - "Docker cloud created with an empty name. Docker cloud requires a non-blank name after Jenkins 2.402"); + LOGGER.warn("Docker cloud requires a non-blank name after Jenkins 2.402"); } } diff --git a/src/test/java/com/nirima/jenkins/plugins/docker/DockerCloudTest.java b/src/test/java/com/nirima/jenkins/plugins/docker/DockerCloudTest.java index 0fb08602..64a7a761 100644 --- a/src/test/java/com/nirima/jenkins/plugins/docker/DockerCloudTest.java +++ b/src/test/java/com/nirima/jenkins/plugins/docker/DockerCloudTest.java @@ -18,6 +18,9 @@ import java.util.List; import java.util.Map; import java.util.Set; +import java.util.logging.Level; +import org.hamcrest.MatcherAssert; +import org.hamcrest.core.IsIterableContaining; import org.jenkinsci.plugins.docker.commons.credentials.DockerServerCredentials; import org.jenkinsci.plugins.docker.commons.credentials.DockerServerEndpoint; import org.junit.Assert; @@ -25,6 +28,7 @@ import org.junit.Test; import org.jvnet.hudson.test.Issue; import org.jvnet.hudson.test.JenkinsRule; +import org.jvnet.hudson.test.LoggerRule; /** * @author Kanstantsin Shautsou @@ -34,6 +38,9 @@ public class DockerCloudTest { @Rule public JenkinsRule jenkins = new JenkinsRule(); + @Rule + public LoggerRule lr = new LoggerRule(); + @SuppressWarnings("unused") @Test public void testConstructor_0_10_2() { @@ -49,20 +56,26 @@ public void testConstructor_0_10_2() { null); // dockerHostname } + private static final String LOG_MESSAGE = "Docker cloud requires a non-blank name after Jenkins 2.402"; + @Issue("JENKINS-70729") // Warn if cloud name is empty @Test public void testConstructorWithEmptyName() { + lr.record(DockerCloud.class.getName(), Level.ALL).capture(16); DockerCloud cloud = new DockerCloud("", new DockerAPI(new DockerServerEndpoint("uri", "credentialsId")), List.of()); Assert.assertEquals(cloud.getDisplayName(), ""); + MatcherAssert.assertThat(lr.getMessages(), IsIterableContaining.hasItem(LOG_MESSAGE)); } @Issue("JENKINS-70729") // Warn if cloud name is null @Test public void testConstructorWithNullName() { + lr.record(DockerCloud.class.getName(), Level.ALL).capture(16); DockerCloud cloud = new DockerCloud(null, new DockerAPI(new DockerServerEndpoint("uri", "credentialsId")), List.of()); Assert.assertEquals(cloud.getDisplayName(), null); + MatcherAssert.assertThat(lr.getMessages(), IsIterableContaining.hasItem(LOG_MESSAGE)); } @Test