Skip to content
Browse files

Addressing some style and performance issues with null error messages.

  • Loading branch information...
1 parent 3639784 commit a1b61ff5fa353842f57a4b9773c336f164f24f00 @adriannistor adriannistor committed Apr 8, 2012
Showing with 3 additions and 7 deletions.
  1. +3 −7 src/main/java/junit/framework/Assert.java
View
10 src/main/java/junit/framework/Assert.java
@@ -226,7 +226,7 @@ static public void assertNotNull(String message, Object object) {
* Object to check or <code>null</code>
*/
static public void assertNull(Object object) {
- String message = "Expected: <null> but was: " + String.valueOf(object);
+ String message= object != null ? "Expected: <null> but was: " + object.toString() : "";
@kcooney
kcooney added a note Apr 20, 2012

If you are really concerned with this kind of performance issue, then why not:

if (object != null)
  assertNull("Expected: <null> but was: " + object.toString(), object)
@adriannistoruiuc
Owner

Yes, this would be another way to do it for the current assertNull and
looks fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
assertNull(message, object);
}
/**
@@ -270,16 +270,12 @@ static public void assertNotSame(Object expected, Object actual) {
}
static public void failSame(String message) {
- String formatted= "";
- if (message != null)
- formatted= message+" ";
+ String formatted= (message != null) ? message+" " : "";
fail(formatted+"expected not same");
}
static public void failNotSame(String message, Object expected, Object actual) {
- String formatted= "";
- if (message != null)
- formatted= message+" ";
+ String formatted= (message != null) ? message+" " : "";
fail(formatted+"expected same:<"+expected+"> was not:<"+actual+">");
}

0 comments on commit a1b61ff

Please sign in to comment.
Something went wrong with that request. Please try again.