forked from google/gson
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adjust some minor details of google#1391.
Use two-space indentation for the new test. Use standard Google import style. Supply missing type argument for `TypeVariable`.
- Loading branch information
1 parent
d65960b
commit 425cb25
Showing
2 changed files
with
32 additions
and
31 deletions.
There are no files selected for viewing
This file contains 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
57 changes: 29 additions & 28 deletions
57
gson/src/test/java/com/google/gson/functional/ReusedTypeVariablesFullyResolveTest.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,55 @@ | ||
package com.google.gson.functional; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNotNull; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
import com.google.gson.Gson; | ||
import com.google.gson.GsonBuilder; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
import java.util.Collection; | ||
import java.util.Iterator; | ||
import java.util.Set; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
/** | ||
* This test covers the scenario described in #1390 where a type variable needs to be used | ||
* by a type definition multiple times. Both type variable references should resolve to the | ||
* same underlying concrete type. | ||
*/ | ||
public class ReusedTypeVariablesFullyResolveTest { | ||
|
||
private Gson gson; | ||
private Gson gson; | ||
|
||
@Before | ||
public void setUp() { | ||
gson = new GsonBuilder().create(); | ||
} | ||
@Before | ||
public void setUp() { | ||
gson = new GsonBuilder().create(); | ||
} | ||
|
||
@SuppressWarnings("ConstantConditions") // The instances were being unmarshaled as Strings instead of TestEnums | ||
@Test | ||
public void testGenericsPreservation() { | ||
TestEnumSetCollection withSet = gson.fromJson("{\"collection\":[\"ONE\",\"THREE\"]}", TestEnumSetCollection.class); | ||
Iterator<TestEnum> iterator = withSet.collection.iterator(); | ||
assertNotNull(withSet); | ||
assertNotNull(withSet.collection); | ||
assertEquals(2, withSet.collection.size()); | ||
TestEnum first = iterator.next(); | ||
TestEnum second = iterator.next(); | ||
@SuppressWarnings("ConstantConditions") // The instances were being unmarshaled as Strings instead of TestEnums | ||
@Test | ||
public void testGenericsPreservation() { | ||
TestEnumSetCollection withSet = gson.fromJson("{\"collection\":[\"ONE\",\"THREE\"]}", TestEnumSetCollection.class); | ||
Iterator<TestEnum> iterator = withSet.collection.iterator(); | ||
assertNotNull(withSet); | ||
assertNotNull(withSet.collection); | ||
assertEquals(2, withSet.collection.size()); | ||
TestEnum first = iterator.next(); | ||
TestEnum second = iterator.next(); | ||
|
||
assertTrue(first instanceof TestEnum); | ||
assertTrue(second instanceof TestEnum); | ||
} | ||
assertTrue(first instanceof TestEnum); | ||
assertTrue(second instanceof TestEnum); | ||
} | ||
|
||
enum TestEnum { ONE, TWO, THREE } | ||
enum TestEnum { ONE, TWO, THREE } | ||
|
||
private static class TestEnumSetCollection extends SetCollection<TestEnum> {} | ||
private static class TestEnumSetCollection extends SetCollection<TestEnum> {} | ||
|
||
private static class SetCollection<T> extends BaseCollection<T, Set<T>> {} | ||
private static class SetCollection<T> extends BaseCollection<T, Set<T>> {} | ||
|
||
private static class BaseCollection<U, C extends Collection<U>> | ||
{ | ||
public C collection; | ||
} | ||
private static class BaseCollection<U, C extends Collection<U>> | ||
{ | ||
public C collection; | ||
} | ||
|
||
} |