Created
August 27, 2015 16:57
-
-
Save kevints/d1e26514468863e8c088 to your computer and use it in GitHub Desktop.
Testing GSON defaults - gson rev is 2.3.1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.apache.aurora.scheduler.http; | |
import java.util.List; | |
import com.google.gson.Gson; | |
import org.junit.Test; | |
import static java.util.Arrays.asList; | |
import static java.util.Collections.emptyList; | |
import static org.junit.Assert.assertEquals; | |
public class GsonTest { | |
private static final Gson GSON = new Gson(); | |
private static final List<String> DEFAULT_STRINGS = asList("DEFAULT", "STRINGS"); | |
public static final String EMPTY_JSON_OBJECT = "{}"; | |
public static final String FULL_JSON_OBJECT = "{strings: []}"; | |
private static class MutableDefaultTest { | |
private List<String> strings = DEFAULT_STRINGS; | |
// Default constructor. | |
} | |
private static class ImmutableDefaultTest { | |
private final List<String> strings = DEFAULT_STRINGS; | |
// Default constructor. | |
} | |
private static class MutableEmptyOverrideTest { | |
private List<String> strings = DEFAULT_STRINGS; | |
private MutableEmptyOverrideTest() { | |
// GSON constructor. | |
} | |
} | |
private static class ImmutableEmptyOverrideTest { | |
private final List<String> strings = DEFAULT_STRINGS; | |
private ImmutableEmptyOverrideTest() { | |
// GSON constructor. | |
} | |
} | |
static class MutableInitializeOverrideTest { | |
private List<String> strings; | |
private MutableInitializeOverrideTest() { | |
strings = DEFAULT_STRINGS; | |
} | |
} | |
static class ImmutableInitializeOverrideTest { | |
private final List<String> strings; | |
ImmutableInitializeOverrideTest() { | |
strings = DEFAULT_STRINGS; | |
} | |
} | |
@Test | |
public void testGsonDefaults() { | |
assertEquals(DEFAULT_STRINGS, GSON.fromJson(EMPTY_JSON_OBJECT, MutableDefaultTest.class).strings); | |
assertEquals(DEFAULT_STRINGS, GSON.fromJson(EMPTY_JSON_OBJECT, ImmutableDefaultTest.class).strings); | |
assertEquals(DEFAULT_STRINGS, GSON.fromJson(EMPTY_JSON_OBJECT, MutableEmptyOverrideTest.class).strings); | |
assertEquals(DEFAULT_STRINGS, GSON.fromJson(EMPTY_JSON_OBJECT, ImmutableEmptyOverrideTest.class).strings); | |
assertEquals(DEFAULT_STRINGS, GSON.fromJson(EMPTY_JSON_OBJECT, MutableInitializeOverrideTest.class).strings); | |
assertEquals(DEFAULT_STRINGS, GSON.fromJson(EMPTY_JSON_OBJECT, ImmutableInitializeOverrideTest.class).strings); | |
assertEquals(emptyList(), GSON.fromJson(FULL_JSON_OBJECT, MutableDefaultTest.class).strings); | |
assertEquals(emptyList(), GSON.fromJson(FULL_JSON_OBJECT, ImmutableDefaultTest.class).strings); | |
assertEquals(emptyList(), GSON.fromJson(FULL_JSON_OBJECT, MutableEmptyOverrideTest.class).strings); | |
assertEquals(emptyList(), GSON.fromJson(FULL_JSON_OBJECT, ImmutableEmptyOverrideTest.class).strings); | |
assertEquals(emptyList(), GSON.fromJson(FULL_JSON_OBJECT, MutableInitializeOverrideTest.class).strings); | |
assertEquals(emptyList(), GSON.fromJson(FULL_JSON_OBJECT, ImmutableInitializeOverrideTest.class).strings); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment