Skip to content
Permalink
Browse files

[JENKINS-15250]: Added test case to show NPE when comparing warnings.

  • Loading branch information...
uhafner committed Sep 25, 2012
1 parent 7ff2ff6 commit 5fb9ddff3a6965037b6cdcca77542cd1fa3c7d00
Showing with 25 additions and 3 deletions.
  1. +25 −3 src/test/java/hudson/plugins/warnings/parser/WarningTest.java
@@ -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;
@@ -21,11 +22,11 @@
* @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);
@@ -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.
You can’t perform that action at this time.