Search in sources :

Example 26 with JsonArray

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

the class JsonRpcListTest method shouldToJsonArrayParsedNumberArray.

@Test
public void shouldToJsonArrayParsedNumberArray() throws Exception {
    JsonArray expected = new JsonArray();
    expected.add(new JsonPrimitive(0D));
    String message = expected.toString();
    JsonRpcList jsonRpcList = new JsonRpcList(message, 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)

Example 27 with JsonArray

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

the class JsonRpcResultTest method shouldToJsonValueWhenPassingParametersWithResultAsAListOfDto.

@Test
public void shouldToJsonValueWhenPassingParametersWithResultAsAListOfDto() throws Exception {
    JsonArray expected = new JsonArray();
    JsonObject value = jsonParser.parse(dto.toString()).getAsJsonObject();
    expected.add(value);
    JsonRpcResult jsonRpcResult = new JsonRpcResult(singletonList(dto), jsonParser);
    JsonElement actual = jsonRpcResult.toJsonElement();
    assertEquals(expected, actual);
}
Also used : JsonArray(com.google.gson.JsonArray) JsonElement(com.google.gson.JsonElement) JsonObject(com.google.gson.JsonObject) Test(org.testng.annotations.Test)

Example 28 with JsonArray

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

the class JsonRpcResultTest method shouldToStringWhenPassingParametersWithResultAsAListOfDto.

@Test
public void shouldToStringWhenPassingParametersWithResultAsAListOfDto() throws Exception {
    JsonArray array = new JsonArray();
    JsonObject value = jsonParser.parse(dto.toString()).getAsJsonObject();
    array.add(value);
    String expected = array.toString();
    JsonRpcResult jsonRpcResult = new JsonRpcResult(singletonList(dto), jsonParser);
    String actual = jsonRpcResult.toString();
    assertEquals(expected, actual);
}
Also used : JsonArray(com.google.gson.JsonArray) JsonObject(com.google.gson.JsonObject) Test(org.testng.annotations.Test)

Example 29 with JsonArray

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

the class JsonRpcResultTest method shouldToStringWhenPassingParametersWithResultAsAListOfString.

@Test
public void shouldToStringWhenPassingParametersWithResultAsAListOfString() throws Exception {
    String value = "a";
    JsonArray array = new JsonArray();
    array.add(new JsonPrimitive(value));
    String expected = array.toString();
    JsonRpcResult jsonRpcResult = new JsonRpcResult(singletonList(value), jsonParser);
    String actual = jsonRpcResult.toString();
    assertEquals(expected, actual);
}
Also used : JsonArray(com.google.gson.JsonArray) JsonPrimitive(com.google.gson.JsonPrimitive) Test(org.testng.annotations.Test)

Example 30 with JsonArray

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

the class JsonRpcResultTest method shouldGetAsListOfNumberWhenPassingParametersWithResultAsListOfNumber.

@Test
public void shouldGetAsListOfNumberWhenPassingParametersWithResultAsListOfNumber() throws Exception {
    Double expected = 0D;
    JsonPrimitive primitive = new JsonPrimitive(expected);
    JsonArray array = new JsonArray();
    array.add(primitive);
    JsonRpcResult jsonRpcResult = new JsonRpcResult(singletonList(expected), jsonParser);
    List<Double> actual = jsonRpcResult.getAsListOf(Double.class);
    assertEquals(expected, actual.iterator().next());
}
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