unable to remove slash after performing a replaceAll

BruceyBandit :
Object jsonBody = getParsedJSONDocument(document);
Object href =  JsonPath.read(jsonBody, "$.href");

assertThat(href, is(String.format(System.getenv(ENDPOINT)+"%s", url).replaceAll("\\\\", "")));

I am trying to perform an assertion against a url and the issue I am having is the \ in the url when it gets it from the response.

It spits out <["https:\/\/www.testenv\/examplesite.com\"]>

How do I remove the slash and take it out of the array as I am expecting:

"https://www.testenv/examplesite.com"
Joop Eggen :

Somehow the forward slashes were escaped in json: wrong data. If that is your statement.

String href = JsonPath.read(jsonBody, "$.href");
href = href.replace("\\", "");

Furthermore, though correct, better style would be simply using + or:

assertThat(href, is(String.format("%s%s", System.getenv(ENDPOINT), url)).replace("\\", ""));

Maybe you intended the replace to happen on href. In junit the first comparison element is the expected value, the second of the actual computed value.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=27145&siteId=1
Recommended