diff --git a/src/main/java/org/csanchez/jenkins/plugins/kubernetes/PodTemplate.java b/src/main/java/org/csanchez/jenkins/plugins/kubernetes/PodTemplate.java index 14b5f4b847..e442f3f5ee 100644 --- a/src/main/java/org/csanchez/jenkins/plugins/kubernetes/PodTemplate.java +++ b/src/main/java/org/csanchez/jenkins/plugins/kubernetes/PodTemplate.java @@ -651,7 +651,7 @@ public void setYaml(String yaml) { @Nonnull public List getYamls() { - if (yamls == null) { + if (yamls == null || yamls.isEmpty()) { if (yaml != null) { return Collections.singletonList(yaml); } else { diff --git a/src/test/java/org/csanchez/jenkins/plugins/kubernetes/PodTemplateTest.java b/src/test/java/org/csanchez/jenkins/plugins/kubernetes/PodTemplateTest.java new file mode 100644 index 0000000000..d6a0f0c0ed --- /dev/null +++ b/src/test/java/org/csanchez/jenkins/plugins/kubernetes/PodTemplateTest.java @@ -0,0 +1,21 @@ +package org.csanchez.jenkins.plugins.kubernetes; + +import org.junit.Test; + +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.empty; +import static org.junit.Assert.assertThat; + +public class PodTemplateTest { + @Test + public void getYamlsExposesSingleYamlField() { + PodTemplate podTemplate = new PodTemplate(); + assertThat(podTemplate.getYamls(), empty()); + podTemplate.setYamls(null); + assertThat(podTemplate.getYamls(), empty()); + podTemplate.setYaml("yaml"); + assertThat(podTemplate.getYamls(), contains("yaml")); + podTemplate.setYaml(null); + assertThat(podTemplate.getYamls(), empty()); + } +}