JsonHelper test

This commit is contained in:
Milos Kozak 2018-03-12 11:12:41 +01:00
parent a5830cc452
commit 601dbc1036

View file

@ -0,0 +1,29 @@
package info.nightscout.utils;
import org.json.JSONException;
import org.json.JSONObject;
import org.junit.Test;
import static org.junit.Assert.*;
/**
* Created by mike on 12.03.2018.
*/
public class JsonHelperTest {
String jsonString = "{\"d\":\"3.0\",\"i\":\"4\",\"s\":\"5\"}";
@Test
public void runTest() throws JSONException {
JSONObject object = new JSONObject(jsonString);
assertEquals(null, JsonHelper.safeGetString(object, "notexisting"));
assertEquals("5", JsonHelper.safeGetString(object, "s"));
assertEquals(0.0d, JsonHelper.safeGetDouble(object, "notexisting"), 0.0d);
assertEquals(3.0d, JsonHelper.safeGetDouble(object, "d"), 0.000001d);
assertEquals(0, JsonHelper.safeGetInt(object, "notexisting"));
assertEquals(4, JsonHelper.safeGetInt(object, "i"));
}
}