Skip to content

Commit

Permalink
Fixed: TESTNG-472: Better output for assertNull()
Browse files Browse the repository at this point in the history
  • Loading branch information
cbeust committed Apr 12, 2011
1 parent e0014c2 commit 8b53fef
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGES.txt
Expand Up @@ -3,6 +3,7 @@ Current
Added: @Factory(dataProvider / dataProviderClass) on constructors
Added: assertNotEquals() to Assert
Added: assertArrayEquals() to AssertJUnit
Fixed: TESTNG-472: Better output for assertNull()
Fixed: ConcurrentModificationException when using parallel data providers.
Fixed: TESTNG-282: Problem when including+excluding packages (addicted)
Fixed: TESTNG-471: assertEquals(Map, Map) fails if a map is a subset of the other
Expand Down
13 changes: 11 additions & 2 deletions src/main/java/org/testng/Assert.java
Expand Up @@ -391,6 +391,13 @@ static public void assertNotNull(Object object) {
* @param message the assertion error message
*/
static public void assertNotNull(Object object, String message) {
if (object == null) {
String formatted = "";
if(message != null) {
formatted = message + " ";
}
fail(formatted + "expected object to not be null");
}
assertTrue(object != null, message);
}

Expand All @@ -410,7 +417,9 @@ static public void assertNull(Object object) {
* @param message the assertion error message
*/
static public void assertNull(Object object, String message) {
assertTrue(object == null, message);
if (object != null) {
failNotSame(object, null, message);
}
}

/**
Expand Down Expand Up @@ -473,7 +482,7 @@ static private void failNotSame(Object actual, Object expected, String message)
if(message != null) {
formatted = message + " ";
}
fail(formatted + "expected same with:<" + expected + "> but was:<" + actual + ">");
fail(formatted + "expected:<" + expected + "> but was:<" + actual + ">");
}

static private void failNotEquals(Object actual , Object expected, String message ) {
Expand Down

0 comments on commit 8b53fef

Please sign in to comment.