Search in sources :

Example 21 with JsonArray

use of com.google.gson.JsonArray in project che by eclipse.

the class JsonRpcParamsTest method shouldToJsonValueForParsedListDtoParams.

@Test
public void shouldToJsonValueForParsedListDtoParams() throws Exception {
    JsonArray array = new JsonArray();
    JsonObject jsonObject = jsonParser.parse(DTO_JSON).getAsJsonObject();
    array.add(jsonObject);
    JsonRpcParams jsonRpcParams = new JsonRpcParams("[" + DTO_JSON + "]", jsonParser);
    JsonElement jsonValue = jsonRpcParams.toJsonElement();
    assertEquals(array, jsonValue);
}
Also used : JsonArray(com.google.gson.JsonArray) JsonElement(com.google.gson.JsonElement) JsonObject(com.google.gson.JsonObject) Test(org.testng.annotations.Test)

Example 22 with JsonArray

use of com.google.gson.JsonArray in project che by eclipse.

the class JsonRpcParamsTest method shouldToStringForParsedListStringParams.

@Test
public void shouldToStringForParsedListStringParams() throws Exception {
    String value = "value";
    JsonArray array = new JsonArray();
    array.add(new JsonPrimitive(value));
    String expected = array.toString();
    JsonRpcParams jsonRpcParams = new JsonRpcParams("[\"" + value + "\"]", jsonParser);
    String actual = jsonRpcParams.toString();
    assertEquals(expected, actual);
}
Also used : JsonArray(com.google.gson.JsonArray) JsonPrimitive(com.google.gson.JsonPrimitive) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.testng.annotations.Test)

Example 23 with JsonArray

use of com.google.gson.JsonArray in project che by eclipse.

the class JsonRpcListTest method shouldToJsonArrayParsedBooleanArray.

@Test
public void shouldToJsonArrayParsedBooleanArray() throws Exception {
    Boolean expected = false;
    JsonArray array = new JsonArray();
    array.add(new JsonPrimitive(expected));
    String message = array.toString();
    JsonRpcList jsonRpcList = new JsonRpcList(message, jsonParser);
    JsonArray actual = jsonRpcList.toJsonArray();
    assertEquals(array, actual);
}
Also used : JsonArray(com.google.gson.JsonArray) JsonPrimitive(com.google.gson.JsonPrimitive) Test(org.testng.annotations.Test)

Example 24 with JsonArray

use of com.google.gson.JsonArray in project che by eclipse.

the class JsonRpcListTest method shouldParseNumberArray.

@Test
public void shouldParseNumberArray() throws Exception {
    Double expected = 0D;
    JsonArray array = new JsonArray();
    array.add(new JsonPrimitive(expected));
    String message = array.toString();
    JsonRpcList jsonRpcList = new JsonRpcList(message, jsonParser);
    Double actual = jsonRpcList.get(0, Double.class);
    assertEquals(expected, actual);
}
Also used : JsonArray(com.google.gson.JsonArray) JsonPrimitive(com.google.gson.JsonPrimitive) Test(org.testng.annotations.Test)

Example 25 with JsonArray

use of com.google.gson.JsonArray in project che by eclipse.

the class JsonRpcListTest method shouldToJsonArrayCreatedStringArray.

@Test
public void shouldToJsonArrayCreatedStringArray() throws Exception {
    JsonArray expected = new JsonArray();
    expected.add(new JsonPrimitive("a"));
    JsonRpcList jsonRpcList = new JsonRpcList(singletonList("a"), jsonParser);
    JsonArray actual = jsonRpcList.toJsonArray();
    assertEquals(expected, actual);
}
Also used : JsonArray(com.google.gson.JsonArray) JsonPrimitive(com.google.gson.JsonPrimitive) Test(org.testng.annotations.Test)

Aggregations

JsonArray (com.google.gson.JsonArray)351 JsonObject (com.google.gson.JsonObject)227 JsonElement (com.google.gson.JsonElement)122 JsonPrimitive (com.google.gson.JsonPrimitive)103 Test (org.testng.annotations.Test)59 JsonParser (com.google.gson.JsonParser)49 ArrayList (java.util.ArrayList)44 HashMap (java.util.HashMap)33 Map (java.util.Map)31 Gson (com.google.gson.Gson)17 Test (org.junit.Test)16 IOException (java.io.IOException)10 Matchers.anyString (org.mockito.Matchers.anyString)10 TextView (android.widget.TextView)9 List (java.util.List)9 Point (android.graphics.Point)8 JsonParseException (com.google.gson.JsonParseException)7 GsonUtilities.jboolean (com.ibm.streamsx.topology.internal.gson.GsonUtilities.jboolean)7 KcaUtils.getStringFromException (com.antest1.kcanotify.KcaUtils.getStringFromException)6 JsonSyntaxException (com.google.gson.JsonSyntaxException)6