46 lines
1.3 KiB
Java
46 lines
1.3 KiB
Java
package com.gmgauthier.junit;
|
|
|
|
import com.gmgauthier.JsonUtils;
|
|
import com.google.gson.JsonObject;
|
|
import com.google.gson.JsonParser;
|
|
|
|
import kong.unirest.json.JSONObject;
|
|
import org.junit.jupiter.api.Assertions;
|
|
import org.junit.jupiter.api.DisplayName;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
import java.io.IOException;
|
|
|
|
public class UnitTests {
|
|
|
|
public JsonUtils jsonUtils = new JsonUtils();
|
|
|
|
@Test
|
|
@DisplayName("Convert A Google JSON to a Kong JSON")
|
|
public void TestGetJsonFromGson() {
|
|
//Given a Google JsonObject
|
|
String jsonString = "{\"Key1\":\"Val1\", \"Key2\":\"Val2\"}";
|
|
JsonObject gJsonObject = JsonParser.parseString(jsonString).getAsJsonObject();
|
|
|
|
//When we convert the object
|
|
JSONObject jObj = jsonUtils.getJsonFromGson(gJsonObject);
|
|
|
|
//Then the new object should be a Kong JSONObject
|
|
Assertions.assertEquals(JSONObject.class,jObj.getClass());
|
|
}
|
|
|
|
@Test
|
|
@DisplayName("Read JSON From a File")
|
|
public void TestGetDataFromJson() {
|
|
JsonObject fixtureData = null;
|
|
try {
|
|
fixtureData = jsonUtils.getFixtureDataFrom("flerbus");
|
|
} catch (IOException e) {
|
|
throw new RuntimeException(e);
|
|
}
|
|
Assertions.assertEquals("Doody", fixtureData.get("Howdy").getAsString());
|
|
}
|
|
|
|
|
|
}
|