Adding a few more assert to the InstanceCreatorTest to ensure that the default values are set for sub class fields.
This commit is contained in:
parent
d87d3f807f
commit
102f8b3a71
|
@ -16,10 +16,6 @@
|
||||||
|
|
||||||
package com.google.gson.functional;
|
package com.google.gson.functional;
|
||||||
|
|
||||||
import java.lang.reflect.Type;
|
|
||||||
|
|
||||||
import junit.framework.TestCase;
|
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.GsonBuilder;
|
import com.google.gson.GsonBuilder;
|
||||||
import com.google.gson.InstanceCreator;
|
import com.google.gson.InstanceCreator;
|
||||||
|
@ -27,6 +23,10 @@ import com.google.gson.common.TestTypes.Base;
|
||||||
import com.google.gson.common.TestTypes.ClassWithBaseField;
|
import com.google.gson.common.TestTypes.ClassWithBaseField;
|
||||||
import com.google.gson.common.TestTypes.Sub;
|
import com.google.gson.common.TestTypes.Sub;
|
||||||
|
|
||||||
|
import junit.framework.TestCase;
|
||||||
|
|
||||||
|
import java.lang.reflect.Type;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Functional Test exercising custom serialization only. When test applies to both
|
* Functional Test exercising custom serialization only. When test applies to both
|
||||||
* serialization and deserialization then add it to CustomTypeAdapterTest.
|
* serialization and deserialization then add it to CustomTypeAdapterTest.
|
||||||
|
@ -56,9 +56,14 @@ public class InstanceCreatorTest extends TestCase {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.create();
|
.create();
|
||||||
|
|
||||||
String json = "{baseName:'Base',subName:'SubRevised'}";
|
String json = "{baseName:'Base',subName:'SubRevised'}";
|
||||||
Base base = gson.fromJson(json, Base.class);
|
Base base = gson.fromJson(json, Base.class);
|
||||||
assertFalse("SubRevised".equals(((Sub)base).subName));
|
assertTrue(base instanceof Sub);
|
||||||
|
|
||||||
|
Sub sub = (Sub) base;
|
||||||
|
assertFalse("SubRevised".equals(sub.subName));
|
||||||
|
assertEquals(Sub.SUB_NAME, sub.subName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testInstanceCreatorReturnsSubTypeForField() {
|
public void testInstanceCreatorReturnsSubTypeForField() {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user