From 425cb25549ae83082b5e1ba4dfbc3bb635a15faf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89amonn=20McManus?= Date: Mon, 2 Aug 2021 17:33:10 -0700 Subject: [PATCH] Adjust some minor details of #1391. Use two-space indentation for the new test. Use standard Google import style. Supply missing type argument for `TypeVariable`. --- .../com/google/gson/internal/$Gson$Types.java | 6 +- .../ReusedTypeVariablesFullyResolveTest.java | 57 ++++++++++--------- 2 files changed, 32 insertions(+), 31 deletions(-) diff --git a/gson/src/main/java/com/google/gson/internal/$Gson$Types.java b/gson/src/main/java/com/google/gson/internal/$Gson$Types.java index 53985bc30a..a708dc055b 100644 --- a/gson/src/main/java/com/google/gson/internal/$Gson$Types.java +++ b/gson/src/main/java/com/google/gson/internal/$Gson$Types.java @@ -339,13 +339,13 @@ public static Type[] getMapKeyAndValueTypes(Type context, Class contextRawTyp } public static Type resolve(Type context, Class contextRawType, Type toResolve) { - return resolve(context, contextRawType, toResolve, new HashMap()); + return resolve(context, contextRawType, toResolve, new HashMap, Type>()); } private static Type resolve(Type context, Class contextRawType, Type toResolve, - Map visitedTypeVariables) { + Map, Type> visitedTypeVariables) { // this implementation is made a little more complicated in an attempt to avoid object-creation - TypeVariable resolving = null; + TypeVariable resolving = null; while (true) { if (toResolve instanceof TypeVariable) { TypeVariable typeVariable = (TypeVariable) toResolve; diff --git a/gson/src/test/java/com/google/gson/functional/ReusedTypeVariablesFullyResolveTest.java b/gson/src/test/java/com/google/gson/functional/ReusedTypeVariablesFullyResolveTest.java index e3ddd840e9..10c7c6db1d 100644 --- a/gson/src/test/java/com/google/gson/functional/ReusedTypeVariablesFullyResolveTest.java +++ b/gson/src/test/java/com/google/gson/functional/ReusedTypeVariablesFullyResolveTest.java @@ -1,16 +1,17 @@ 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 @@ -18,37 +19,37 @@ */ 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 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 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 {} + private static class TestEnumSetCollection extends SetCollection {} - private static class SetCollection extends BaseCollection> {} + private static class SetCollection extends BaseCollection> {} - private static class BaseCollection> - { - public C collection; - } + private static class BaseCollection> + { + public C collection; + } }