java-utilities/src/test/java/com/gmgauthier/junit/UnitTests.java

44 lines
1.2 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 {
@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;
try {
fixtureData = JsonUtils.getFixtureDataFrom("flerbus");
} catch (IOException e) {
throw new RuntimeException(e);
}
Assertions.assertEquals("Doody", fixtureData.get("Howdy").getAsString());
}
}