Search in sources :

Example 21 with JsonPrimitive

use of com.google.gson.JsonPrimitive 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)

Example 22 with JsonPrimitive

use of com.google.gson.JsonPrimitive 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 23 with JsonPrimitive

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

the class JsonRpcResultTest method shouldGetAsStringWhenParsingStringWithResultAsString.

@Test
public void shouldGetAsStringWhenParsingStringWithResultAsString() throws Exception {
    JsonPrimitive primitive = new JsonPrimitive("a");
    String expected = primitive.getAsString();
    JsonRpcResult jsonRpcResult = new JsonRpcResult(primitive.toString(), jsonParser);
    String actual = jsonRpcResult.getAs(String.class);
    assertEquals(expected, actual);
}
Also used : JsonPrimitive(com.google.gson.JsonPrimitive) Test(org.testng.annotations.Test)

Example 24 with JsonPrimitive

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

the class JsonRpcResultTest method shouldGetAsNumberWhenParsingStringWithResultAsNumber.

@Test
public void shouldGetAsNumberWhenParsingStringWithResultAsNumber() throws Exception {
    JsonPrimitive value = new JsonPrimitive(0D);
    Double expected = value.getAsDouble();
    JsonRpcResult jsonRpcResult = new JsonRpcResult(value.toString(), jsonParser);
    Double actual = jsonRpcResult.getAs(Double.class);
    assertEquals(expected, actual);
}
Also used : JsonPrimitive(com.google.gson.JsonPrimitive) Test(org.testng.annotations.Test)

Example 25 with JsonPrimitive

use of com.google.gson.JsonPrimitive 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)

Aggregations

JsonPrimitive (com.google.gson.JsonPrimitive)168 JsonArray (com.google.gson.JsonArray)103 JsonObject (com.google.gson.JsonObject)78 Test (org.testng.annotations.Test)56 JsonElement (com.google.gson.JsonElement)47 Test (org.junit.Test)12 Map (java.util.Map)9 Matchers.anyString (org.mockito.Matchers.anyString)8 JsonProcessorInjectionMap (com.builtbroken.mc.lib.json.loading.JsonProcessorInjectionMap)7 Gson (com.google.gson.Gson)5 JsonParser (com.google.gson.JsonParser)4 Date (java.util.Date)4 HashMap (java.util.HashMap)4 GsonBuilder (com.google.gson.GsonBuilder)3 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 Matcher (java.util.regex.Matcher)3 LobWrapper (angularBeans.io.LobWrapper)2 DatasetCreationSpec (co.cask.cdap.internal.dataset.DatasetCreationSpec)2 IRenderState (com.builtbroken.mc.client.json.imp.IRenderState)2