From 02049f28ca2ab613ea074a11d29f6115fc722439 Mon Sep 17 00:00:00 2001 From: Tamaghna Chattopadhyay <139495942+shinigami-777@users.noreply.github.com> Date: Tue, 24 Dec 2024 05:28:29 +0530 Subject: [PATCH] Improve NextLabelCause Test Coverage (#370) * NextLabelCauseTest-added Signed-off-by: shinigami-777 * Use equalsverifier with NextLabelCause Provides a deeper test of the equals contract and the hashCode contract. * moved-contents-of-setup Signed-off-by: shinigami-777 * removed-comment * comment-reverted-back * Remove inaccurate comment --------- Signed-off-by: shinigami-777 Co-authored-by: Mark Waite --- .../NextLabelCauseTest.java | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/test/java/org/jvnet/jenkins/plugins/nodelabelparameter/NextLabelCauseTest.java diff --git a/src/test/java/org/jvnet/jenkins/plugins/nodelabelparameter/NextLabelCauseTest.java b/src/test/java/org/jvnet/jenkins/plugins/nodelabelparameter/NextLabelCauseTest.java new file mode 100644 index 0000000..aa715eb --- /dev/null +++ b/src/test/java/org/jvnet/jenkins/plugins/nodelabelparameter/NextLabelCauseTest.java @@ -0,0 +1,34 @@ +package org.jvnet.jenkins.plugins.nodelabelparameter; + +import hudson.model.FreeStyleBuild; +import hudson.model.FreeStyleProject; +import nl.jqno.equalsverifier.EqualsVerifier; +import nl.jqno.equalsverifier.Warning; +import org.junit.Assert; +import org.junit.Rule; +import org.junit.Test; +import org.jvnet.hudson.test.JenkinsRule; + +public class NextLabelCauseTest { + + @Rule + public JenkinsRule j = new JenkinsRule(); + + @Test + public void testGetShortDescription() throws Exception { + FreeStyleProject project = j.createFreeStyleProject("projectB"); + FreeStyleBuild build = j.buildAndAssertSuccess(project); + NextLabelCause cause = new NextLabelCause("dummylabel", build); + String description = cause.getShortDescription(); + Assert.assertEquals(description, "A build with label/node [dummylabel] was requested"); + } + + @Test + public void testEqualsContract() { + EqualsVerifier.forClass(LabelParameterValue.class) + .usingGetClass() + .suppress(Warning.NONFINAL_FIELDS) + .withIgnoredFields("description", "nextLabels") + .verify(); + } +}