This is the first time I'm trying to write my JUnit tests. In my case I need to validate a JSON response from an API with my expected JSON string. Part of my code looks like this:
@Test
public void test()
{
String expected = "{\"b\":1}";
HttpClient client = HttpClientBuilder.create().build();
HttpPost request = new HttpPost("http://10.0.0.10/e/p");
StringEntity params = new StringEntity("{\"a\":1}");
request.addHeader("Content-Type", "application/json");
request.setEntity(params);
HttpResponse response = client.execute(request);
HttpEntity entity = response.getEntity();
response.getStatusLine().getStatusCode();
JsonObject actual = readResponse(entity);
}
Now, you can see my expected value is a string. But, the actual value I am getting as JsonObject. Either I have to keep both into json string and assert them as json or I have to convert my actual value to JsonObject. I searched for both ways but couldn't figure out how. What/how would be the best fix for my case?