Search code examples
javajunit4

Junit fails- quotes in String comparing


I am trying to compare 2 String in assertEquals using JUnit 4, Java 8, to check decryption function, so:

String data = "veryLongEncryptedString.....";
String value = DecUtils.decryptToken(data, null); //returns String
assertEquals("Here User name: ", "encrypt expected value", value);

The values are equal but the console shows one of them quoted:

org.junit.ComparisonFailure: Here is test for Addition Result:  expected:<[xxx]> but was:<["xxx"]>

How do make both values quoted or unquoted? Thanks.


Solution

  • How do make both values quoted or unquoted?

    The idea of a assertEquals test is to compare an exact expected value with the output of a method. Here, the DecUtils.decryptToken is providing a string that already contains open and close quotes. So you have two choices:

    • Those quotes are expected as part of the return value, so you should change the test string to be the correct expected value: String data = "\"veryLongEncryptedString.....\"";

    • Those quotes are not expected as part of the return value: The test is failing because it should be failing, and you have to fix the decryptToken routine so it returns the correct result.

    Which one of those to do depends on the documentation for DecUtils.decryptToken, but please note that you should do only one!