Skip to content
This repository has been archived by the owner on Apr 6, 2022. It is now read-only.

Commit

Permalink
[JENKINS-15250]: Added test case to show NPE when comparing warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
uhafner committed Sep 25, 2012
1 parent 7ff2ff6 commit 5fb9ddf
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions src/test/java/hudson/plugins/warnings/parser/WarningTest.java
Expand Up @@ -2,6 +2,7 @@

import static org.junit.Assert.*;
import hudson.plugins.analysis.core.AnnotationDifferencer;
import hudson.plugins.analysis.util.TreeString;
import hudson.plugins.analysis.util.model.FileAnnotation;

import java.util.HashSet;
Expand All @@ -21,11 +22,11 @@ public class WarningTest {
* @see <a href="http://issues.jenkins-ci.org/browse/JENKINS-14821">Issue 14821</a>
*/
@Test
public void testEquals() {
Warning expected = new Warning("filename", 0, "type", "category", "message");
public void testEqualsIssue14821() {
Warning expected = createWarning();
expected.setContextHashCode(1);

Warning actual = new Warning("filename", 0, "type", "category", "message");
Warning actual = createWarning();
expected.setContextHashCode(2);

assertEquals("The objects are not the same", expected, actual);
Expand All @@ -39,5 +40,26 @@ public void testEquals() {
Set<FileAnnotation> annotations = AnnotationDifferencer.getNewAnnotations(current, reference);
assertTrue("There are new warnings", annotations.isEmpty());
}

/**
* Verifies that we correctly handle <code>null</code> values in {@link TreeString} instances.
*
* @see <a href="http://issues.jenkins-ci.org/browse/JENKINS-15250">Issue 15250</a>
*/
@Test
public void testEqualsIssue15250() {
Warning first = createWarning();
Warning second = createWarning();

assertEquals("The objects are not the same", first, second);
first.setPackageName("something");
assertFalse("The objects are the same", first.equals(second));
first.setModuleName("something");
assertFalse("The objects are the same", first.equals(second));
}

private Warning createWarning() {
return new Warning("filename", 0, "type", "category", "message");
}
}

0 comments on commit 5fb9ddf

Please sign in to comment.