JsonHelper test
This commit is contained in:
parent
a5830cc452
commit
601dbc1036
1 changed files with 29 additions and 0 deletions
29
app/src/test/java/info/nightscout/utils/JsonHelperTest.java
Normal file
29
app/src/test/java/info/nightscout/utils/JsonHelperTest.java
Normal 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"));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue