Fix ObjectTest not restoring default Locale (#2050)

This commit is contained in:
Marcono1234 2022-01-10 16:18:42 +01:00 committed by GitHub
parent 4ec67c00a0
commit d38e397421
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -55,22 +55,27 @@ import junit.framework.TestCase;
*/ */
public class ObjectTest extends TestCase { public class ObjectTest extends TestCase {
private Gson gson; private Gson gson;
private TimeZone oldTimeZone = TimeZone.getDefault(); private TimeZone oldTimeZone;
private Locale oldLocale;
@Override @Override
protected void setUp() throws Exception { protected void setUp() throws Exception {
super.setUp(); super.setUp();
gson = new Gson(); gson = new Gson();
oldTimeZone = TimeZone.getDefault();
TimeZone.setDefault(TimeZone.getTimeZone("America/Los_Angeles")); TimeZone.setDefault(TimeZone.getTimeZone("America/Los_Angeles"));
oldLocale = Locale.getDefault();
Locale.setDefault(Locale.US); Locale.setDefault(Locale.US);
} }
@Override @Override
protected void tearDown() throws Exception { protected void tearDown() throws Exception {
TimeZone.setDefault(oldTimeZone); TimeZone.setDefault(oldTimeZone);
Locale.setDefault(oldLocale);
super.tearDown(); super.tearDown();
} }
public void testJsonInSingleQuotesDeserialization() { public void testJsonInSingleQuotesDeserialization() {
String json = "{'stringValue':'no message','intValue':10,'longValue':20}"; String json = "{'stringValue':'no message','intValue':10,'longValue':20}";
BagOfPrimitives target = gson.fromJson(json, BagOfPrimitives.class); BagOfPrimitives target = gson.fromJson(json, BagOfPrimitives.class);