0
 assertThat( "abd\n123" ).isEqualTo( "abd\r\n123" );

prints this

] PasswordCredentialsSerializationTest.testSerialize:33 expected:<"abd[
123"> but was:<"abd[]
123">

asside from interesting positioning of square brackets, is there any way to get assertj to print the the actual whitespace characters? one of the hard things to find in tests comparing large strings (and this is not a large string) is when the only thing different is whitespace characters.

xenoterracide
  • 16,274
  • 24
  • 118
  • 243
  • Short answer: no. Long answer: If you want to see whitspace characters escaped int the output, then you need to pass the string already with whitspace characters escaped. e.g. `assertThat( "abd\\n123" ).isEqualTo( "abd\\r\\n123" );`. – SubOptimal Aug 25 '16 at 07:12

1 Answers1

2

The bracket you see is the way an AssertionError is interpreted by JUnit (when JUnit is in the classpath, AssertJ uses it to build assertion errors that are IDE friendly).

AssertJ lets you customize how types are represented in error messages by using a custom representation, see this example.

Joel Costigliola
  • 6,308
  • 27
  • 35