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);
}
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);
}
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);
}
use of com.google.gson.JsonPrimitive in project che by eclipse.
the class JsonRpcResultTest method shouldToJsonValueWhenParsingStringWithResultAsASingleString.
@Test
public void shouldToJsonValueWhenParsingStringWithResultAsASingleString() throws Exception {
JsonPrimitive expected = new JsonPrimitive("a");
JsonRpcResult jsonRpcResult = new JsonRpcResult(expected.toString(), jsonParser);
JsonElement actual = jsonRpcResult.toJsonElement();
assertEquals(expected, actual);
}
use of com.google.gson.JsonPrimitive 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());
}
Aggregations