Skip to content

Commit

Permalink
Test NextLabelCause equals contract
Browse files Browse the repository at this point in the history
The code incorrectly tested the equals contract of the wrong class due
to my copy and paste error.  Test the correct class.

Uses the simple() verifier because the UpstreamCause class seems to
have complications related to its superclass and I'd rather not spend
the time to investigate further.  The simple() verifier detected the
null pointer exceptions, so it is still better than not testing.

Removes temporary check for null pointers, since equalsverifier performs
the same checks.
  • Loading branch information
MarkEWaite committed Dec 24, 2024
1 parent 9ac76c0 commit d1abf29
Showing 1 changed file with 3 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
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;
Expand All @@ -21,21 +20,12 @@ public void testGetShortDescription() throws Exception {
NextLabelCause cause = new NextLabelCause("dummylabel", build);
String description = cause.getShortDescription();
Assert.assertEquals(description, "A build with label/node [dummylabel] was requested");

NextLabelCause causeA = new NextLabelCause(null, build);
NextLabelCause causeB = new NextLabelCause(null, build);
/* Temporary check that hashCode does not NPE on null label */
Assert.assertEquals(causeA.hashCode(), causeB.hashCode());
/* Temporary check that equals does not NPE on null label */
Assert.assertTrue(causeA.equals(causeB));
}

@Test
public void testEqualsContract() {
EqualsVerifier.forClass(LabelParameterValue.class)
.usingGetClass()
.suppress(Warning.NONFINAL_FIELDS)
.withIgnoredFields("description", "nextLabels")
.verify();
// The UpstreamCause base class of NextLabelCause complicates the equals contract.
// Intentionally use the simple() verifier.
EqualsVerifier.simple().forClass(NextLabelCause.class).verify();
}
}

0 comments on commit d1abf29

Please sign in to comment.