Add doesNotHaveToString assertion#2052
Conversation
joel-costigliola
left a comment
There was a problem hiding this comment.
@lykims thanks, good PR, just a few improvements to do and we are good.
| * assertThat(homer).doesNotHaveToString("Marge"); | ||
| * </code></pre> |
| } | ||
|
|
||
| private ShouldNotHaveToString(Object actual, String other) { | ||
| super("%nExpecting actual's toString() not to be equal to:%n <%s>%nbut was:%n <%s>", other, actual.toString()); |
There was a problem hiding this comment.
let's simplify this to:
"%nExpecting actual's toString() not to be equal to:%n <%s>"
the reason is but was:%n <%s> section is actually repeating actual's toString value
| // GIVEN | ||
| Object actualObject = null; | ||
| // WHEN | ||
| ThrowingCallable code = () -> objects.assertDoesNotHaveToString(someInfo(), actualObject, "bar"); |
There was a problem hiding this comment.
use expectAssertionError from org.assertj.core.util.AssertionsUtil which returns an AssertionError
| AssertionError error = expectAssertionError(() -> objects.assertDoesNotHaveToString(info, actual, "Person[name='foo']")); | ||
| // THEN | ||
| verify(failures).failure(info, shouldNotHaveToString("Person[name='foo']", "Person[name='foo']")); | ||
| assertThat(error).hasMessageContainingAll("Person[name='foo']"); |
There was a problem hiding this comment.
remove this line, it is already covered by verify(failures) (we don't want to test the error message but only that we call the proper error message factory)
| // GIVEN | ||
| AssertionInfo info = someInfo(); | ||
| // WHEN | ||
| AssertionError error = expectAssertionError(() -> objects.assertDoesNotHaveToString(info, actual, "Person[name='foo']")); |
There was a problem hiding this comment.
remove AssertionError error local variable (see next comment why)
…ng error message and unit tests
|
@joel-costigliola I addressed your comments. I also applied changes suggested for |
|
Integrated thanks for the good work @lykims! |
Check List:
Minor fixes for
hasToStringdoc description andShouldHaveToStringerror as well.