Write a test recommended by missing code coverage on TypeAdapter

This commit is contained in:
Jesse Wilson 2012-02-11 20:16:05 +00:00
parent 7b75efd09e
commit f40ac23e88

View File

@ -18,6 +18,9 @@ package com.google.gson.functional;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.JsonPrimitive;
import com.google.gson.JsonSyntaxException;
import com.google.gson.TypeAdapter;
import com.google.gson.reflect.TypeToken;
@ -193,6 +196,21 @@ public final class StreamingTypeAdaptersTest extends TestCase {
+ "'right':{'label':'right','left':null,'right':null}}",
toJson(nodeAdapter, root).replace('"', '\''));
}
public void testFromJsonTree() {
JsonObject truckObject = new JsonObject();
truckObject.add("horsePower", new JsonPrimitive(300));
JsonArray passengersArray = new JsonArray();
JsonObject jesseObject = new JsonObject();
jesseObject.add("age", new JsonPrimitive(30));
jesseObject.add("name", new JsonPrimitive("Jesse"));
passengersArray.add(jesseObject);
truckObject.add("passengers", passengersArray);
Truck truck = truckAdapter.fromJsonTree(truckObject);
assertEquals(300.0, truck.horsePower);
assertEquals(Arrays.asList(new Person("Jesse", 30)), truck.passengers);
}
static class Truck {
double horsePower;