Skip to content

Commit

Permalink
Minor cleanups in deprecations and other warnings (#1522)
Browse files Browse the repository at this point in the history
  • Loading branch information
Degubi authored and inder123 committed Oct 3, 2019
1 parent 0e90771 commit 7845c38
Show file tree
Hide file tree
Showing 17 changed files with 61 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ public void testDatePattern() throws Exception {
assertEquals(toLiteral(formatter.format(currentDate)), dateString);
}

@SuppressWarnings("unused")
public void testInvalidDatePattern() throws Exception {
try {
new DefaultDateTypeAdapter(Date.class, "I am a bad Date pattern....");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ protected void setUp() throws Exception {
fieldAttributes = new FieldAttributes(Foo.class.getField("bar"));
}

@SuppressWarnings("unused")
public void testNullField() throws Exception {
try {
new FieldAttributes(null);
Expand Down
45 changes: 23 additions & 22 deletions gson/src/test/java/com/google/gson/JsonPrimitiveTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
*/
public class JsonPrimitiveTest extends TestCase {

@SuppressWarnings("unused")
public void testNulls() {
try {
new JsonPrimitive((Boolean) null);
Expand Down Expand Up @@ -113,8 +114,8 @@ public void testExponential() throws Exception {
JsonPrimitive json = new JsonPrimitive("1E+7");

assertEquals(new BigDecimal("1E+7"), json.getAsBigDecimal());
assertEquals(new Double("1E+7"), json.getAsDouble(), 0.00001);
assertEquals(new Float("1E+7"), json.getAsDouble(), 0.00001);
assertEquals(1E+7, json.getAsDouble(), 0.00001);
assertEquals(1E+7, json.getAsDouble(), 0.00001);

try {
json.getAsInt();
Expand All @@ -123,91 +124,91 @@ public void testExponential() throws Exception {
}

public void testByteEqualsShort() {
JsonPrimitive p1 = new JsonPrimitive(new Byte((byte)10));
JsonPrimitive p2 = new JsonPrimitive(new Short((short)10));
JsonPrimitive p1 = new JsonPrimitive(Byte.valueOf((byte)10));
JsonPrimitive p2 = new JsonPrimitive(Short.valueOf((short)10));
assertEquals(p1, p2);
assertEquals(p1.hashCode(), p2.hashCode());
}

public void testByteEqualsInteger() {
JsonPrimitive p1 = new JsonPrimitive(new Byte((byte)10));
JsonPrimitive p2 = new JsonPrimitive(new Integer(10));
JsonPrimitive p1 = new JsonPrimitive(Byte.valueOf((byte)10));
JsonPrimitive p2 = new JsonPrimitive(Integer.valueOf(10));
assertEquals(p1, p2);
assertEquals(p1.hashCode(), p2.hashCode());
}

public void testByteEqualsLong() {
JsonPrimitive p1 = new JsonPrimitive(new Byte((byte)10));
JsonPrimitive p2 = new JsonPrimitive(new Long(10L));
JsonPrimitive p1 = new JsonPrimitive(Byte.valueOf((byte)10));
JsonPrimitive p2 = new JsonPrimitive(Long.valueOf(10L));
assertEquals(p1, p2);
assertEquals(p1.hashCode(), p2.hashCode());
}

public void testByteEqualsBigInteger() {
JsonPrimitive p1 = new JsonPrimitive(new Byte((byte)10));
JsonPrimitive p1 = new JsonPrimitive(Byte.valueOf((byte)10));
JsonPrimitive p2 = new JsonPrimitive(new BigInteger("10"));
assertEquals(p1, p2);
assertEquals(p1.hashCode(), p2.hashCode());
}

public void testShortEqualsInteger() {
JsonPrimitive p1 = new JsonPrimitive(new Short((short)10));
JsonPrimitive p2 = new JsonPrimitive(new Integer(10));
JsonPrimitive p1 = new JsonPrimitive(Short.valueOf((short)10));
JsonPrimitive p2 = new JsonPrimitive(Integer.valueOf(10));
assertEquals(p1, p2);
assertEquals(p1.hashCode(), p2.hashCode());
}

public void testShortEqualsLong() {
JsonPrimitive p1 = new JsonPrimitive(new Short((short)10));
JsonPrimitive p2 = new JsonPrimitive(new Long(10));
JsonPrimitive p1 = new JsonPrimitive(Short.valueOf((short)10));
JsonPrimitive p2 = new JsonPrimitive(Long.valueOf(10));
assertEquals(p1, p2);
assertEquals(p1.hashCode(), p2.hashCode());
}

public void testShortEqualsBigInteger() {
JsonPrimitive p1 = new JsonPrimitive(new Short((short)10));
JsonPrimitive p1 = new JsonPrimitive(Short.valueOf((short)10));
JsonPrimitive p2 = new JsonPrimitive(new BigInteger("10"));
assertEquals(p1, p2);
assertEquals(p1.hashCode(), p2.hashCode());
}

public void testIntegerEqualsLong() {
JsonPrimitive p1 = new JsonPrimitive(new Integer(10));
JsonPrimitive p2 = new JsonPrimitive(new Long(10L));
JsonPrimitive p1 = new JsonPrimitive(Integer.valueOf(10));
JsonPrimitive p2 = new JsonPrimitive(Long.valueOf(10L));
assertEquals(p1, p2);
assertEquals(p1.hashCode(), p2.hashCode());
}

public void testIntegerEqualsBigInteger() {
JsonPrimitive p1 = new JsonPrimitive(new Integer(10));
JsonPrimitive p1 = new JsonPrimitive(Integer.valueOf(10));
JsonPrimitive p2 = new JsonPrimitive(new BigInteger("10"));
assertEquals(p1, p2);
assertEquals(p1.hashCode(), p2.hashCode());
}

public void testLongEqualsBigInteger() {
JsonPrimitive p1 = new JsonPrimitive(new Long(10L));
JsonPrimitive p1 = new JsonPrimitive(Long.valueOf(10L));
JsonPrimitive p2 = new JsonPrimitive(new BigInteger("10"));
assertEquals(p1, p2);
assertEquals(p1.hashCode(), p2.hashCode());
}

public void testFloatEqualsDouble() {
JsonPrimitive p1 = new JsonPrimitive(new Float(10.25F));
JsonPrimitive p2 = new JsonPrimitive(new Double(10.25D));
JsonPrimitive p1 = new JsonPrimitive(Float.valueOf(10.25F));
JsonPrimitive p2 = new JsonPrimitive(Double.valueOf(10.25D));
assertEquals(p1, p2);
assertEquals(p1.hashCode(), p2.hashCode());
}

public void testFloatEqualsBigDecimal() {
JsonPrimitive p1 = new JsonPrimitive(new Float(10.25F));
JsonPrimitive p1 = new JsonPrimitive(Float.valueOf(10.25F));
JsonPrimitive p2 = new JsonPrimitive(new BigDecimal("10.25"));
assertEquals(p1, p2);
assertEquals(p1.hashCode(), p2.hashCode());
}

public void testDoubleEqualsBigDecimal() {
JsonPrimitive p1 = new JsonPrimitive(new Double(10.25D));
JsonPrimitive p1 = new JsonPrimitive(Double.valueOf(10.25D));
JsonPrimitive p2 = new JsonPrimitive(new BigDecimal("10.25"));
assertEquals(p1, p2);
assertEquals(p1.hashCode(), p2.hashCode());
Expand Down
23 changes: 1 addition & 22 deletions gson/src/test/java/com/google/gson/common/MoreAsserts.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package com.google.gson.common;

import junit.framework.Assert;
import org.junit.Assert;

import java.util.Collection;

Expand All @@ -28,26 +28,6 @@
*/
public class MoreAsserts {

public static void assertEquals(int[] expected, int[] target) {
if (expected == null) {
Assert.assertNull(target);
}
Assert.assertEquals(expected.length, target.length);
for (int i = 0; i < expected.length; ++i) {
Assert.assertEquals(expected[i], target[i]);
}
}

public static void assertEquals(Integer[] expected, Integer[] target) {
if (expected == null) {
Assert.assertNull(target);
}
Assert.assertEquals(expected.length, target.length);
for (int i = 0; i < expected.length; ++i) {
Assert.assertEquals(expected[i], target[i]);
}
}

/**
* Asserts that the specified {@code value} is not present in {@code collection}
* @param collection the collection to look into
Expand All @@ -69,5 +49,4 @@ public static void assertEqualsAndHashCode(Object a, Object b) {
Assert.assertFalse(a.equals(null));
Assert.assertFalse(a.equals(new Object()));
}

}
8 changes: 4 additions & 4 deletions gson/src/test/java/com/google/gson/functional/ArrayTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonParseException;
import com.google.gson.common.MoreAsserts;
import com.google.gson.common.TestTypes.BagOfPrimitives;
import com.google.gson.common.TestTypes.ClassWithObjects;
import com.google.gson.reflect.TypeToken;

import junit.framework.TestCase;
import static org.junit.Assert.assertArrayEquals;

import java.lang.reflect.Type;
import java.math.BigDecimal;
Expand Down Expand Up @@ -53,7 +53,7 @@ public void testTopLevelArrayOfIntsSerialization() {
public void testTopLevelArrayOfIntsDeserialization() {
int[] expected = { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
int[] actual = gson.fromJson("[1,2,3,4,5,6,7,8,9]", int[].class);
MoreAsserts.assertEquals(expected, actual);
assertArrayEquals(expected, actual);
}

public void testInvalidArrayDeserialization() {
Expand Down Expand Up @@ -173,8 +173,8 @@ public void testArrayOfCollectionDeserialization() throws Exception {
Collection<Integer>[] target = gson.fromJson(json, type);

assertEquals(2, target.length);
MoreAsserts.assertEquals(new Integer[] { 1, 2 }, target[0].toArray(new Integer[0]));
MoreAsserts.assertEquals(new Integer[] { 3, 4 }, target[1].toArray(new Integer[0]));
assertArrayEquals(new Integer[] { 1, 2 }, target[0].toArray(new Integer[0]));
assertArrayEquals(new Integer[] { 3, 4 }, target[1].toArray(new Integer[0]));
}

public void testArrayOfPrimitivesAsObjectsSerialization() throws Exception {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import com.google.gson.reflect.TypeToken;

import junit.framework.TestCase;
import static org.junit.Assert.assertArrayEquals;

/**
* Functional tests for Json serialization and deserialization of collections.
Expand Down Expand Up @@ -70,7 +71,7 @@ public void testTopLevelCollectionOfIntegersDeserialization() {
Type collectionType = new TypeToken<Collection<Integer>>() { }.getType();
Collection<Integer> target = gson.fromJson(json, collectionType);
int[] expected = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
MoreAsserts.assertEquals(expected, toIntArray(target));
assertArrayEquals(expected, toIntArray(target));
}

public void testTopLevelListOfIntegerCollectionsDeserialization() throws Exception {
Expand All @@ -86,7 +87,7 @@ public void testTopLevelListOfIntegerCollectionsDeserialization() throws Excepti
}

for (int i = 0; i < 3; i++) {
MoreAsserts.assertEquals(expected[i], toIntArray(target.get(i)));
assertArrayEquals(expected[i], toIntArray(target.get(i)));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,9 @@ public void testChangingCustomTreeAndDeserializing() {

public void testExtraCommasInArrays() {
Type type = new TypeToken<List<String>>() {}.getType();
assertEquals(list("a", null, "b", null, null), gson.fromJson("[a,,b,,]", type));
assertEquals(list(null, null), gson.fromJson("[,]", type));
assertEquals(list("a", null), gson.fromJson("[a,]", type));
assertEquals(Arrays.asList("a", null, "b", null, null), gson.fromJson("[a,,b,,]", type));
assertEquals(Arrays.asList(null, null), gson.fromJson("[,]", type));
assertEquals(Arrays.asList("a", null), gson.fromJson("[a,]", type));
}

public void testExtraCommasInMaps() {
Expand All @@ -136,8 +136,4 @@ public void testExtraCommasInMaps() {
} catch (JsonSyntaxException expected) {
}
}

private <T> List<T> list(T... elements) {
return Arrays.asList(elements);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ public void disabled_testTwoTypesCollapseToOneSerialize() {
.create();

Map<Number, String> original = new LinkedHashMap<Number, String>();
original.put(new Double(1.0), "a");
original.put(new Float(1.0), "b");
original.put(1.0D, "a");
original.put(1.0F, "b");
try {
gson.toJson(original, new TypeToken<Map<Number, String>>() {}.getType());
fail(); // we no longer hash keys at serialization time
Expand Down
2 changes: 1 addition & 1 deletion gson/src/test/java/com/google/gson/functional/MapTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ public void testMapDeserializationWithWildcardValues() {
Type typeOfMap = new TypeToken<Map<String, ? extends Long>>() {}.getType();
Map<String, ? extends Long> map = gson.fromJson("{\"test\":123}", typeOfMap);
assertEquals(1, map.size());
assertEquals(new Long(123L), map.get("test"));
assertEquals(Long.valueOf(123L), map.get("test"));
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public void testParameterizedTypesWithCustomDeserializer() {
.registerTypeAdapter(ptStringType, new MyParameterizedTypeAdapter<String>())
.registerTypeAdapter(ptStringType, new MyParameterizedTypeInstanceCreator<String>(""))
.registerTypeAdapter(ptIntegerType,
new MyParameterizedTypeInstanceCreator<Integer>(new Integer(0)))
new MyParameterizedTypeInstanceCreator<Integer>(0))
.create();

MyParameterizedType<Integer> src = new MyParameterizedType<Integer>(10);
Expand Down
12 changes: 6 additions & 6 deletions gson/src/test/java/com/google/gson/functional/PrimitiveTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,12 @@ public void testNumberSerialization() {

public void testNumberDeserialization() {
String json = "1";
Number expected = new Integer(json);
Number expected = Integer.valueOf(json);
Number actual = gson.fromJson(json, Number.class);
assertEquals(expected.intValue(), actual.intValue());

json = String.valueOf(Long.MAX_VALUE);
expected = new Long(json);
expected = Long.valueOf(json);
actual = gson.fromJson(json, Number.class);
assertEquals(expected.longValue(), actual.longValue());

Expand All @@ -164,16 +164,16 @@ public void testNumberAsStringDeserialization() {
}

public void testPrimitiveDoubleAutoboxedSerialization() {
assertEquals("-122.08234335", gson.toJson(-122.08234335));
assertEquals("122.08112002", gson.toJson(new Double(122.08112002)));
assertEquals("-122.08234335", gson.toJson(-122.08234335D));
assertEquals("122.08112002", gson.toJson(122.08112002D));
}

public void testPrimitiveDoubleAutoboxedDeserialization() {
double actual = gson.fromJson("-122.08858585", double.class);
assertEquals(-122.08858585, actual);
assertEquals(-122.08858585D, actual);

actual = gson.fromJson("122.023900008000", Double.class);
assertEquals(122.023900008, actual);
assertEquals(122.023900008D, actual);
}

public void testPrimitiveDoubleAutoboxedInASingleElementArraySerialization() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,17 +157,17 @@ public void testStrictBoxedNansAndInfinities() throws IOException {
writer.setLenient(false);
writer.beginArray();
try {
writer.value(new Double(Double.NaN));
writer.value(Double.valueOf(Double.NaN));
fail();
} catch (IllegalArgumentException expected) {
}
try {
writer.value(new Double(Double.NEGATIVE_INFINITY));
writer.value(Double.valueOf(Double.NEGATIVE_INFINITY));
fail();
} catch (IllegalArgumentException expected) {
}
try {
writer.value(new Double(Double.POSITIVE_INFINITY));
writer.value(Double.valueOf(Double.POSITIVE_INFINITY));
fail();
} catch (IllegalArgumentException expected) {
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,11 @@
*/
public class RecursiveTypesResolveTest extends TestCase {

@SuppressWarnings("unused")
private static class Foo1<A> {
public Foo2<? extends A> foo2;
public Foo2<? extends A> foo2;
}

@SuppressWarnings("unused")
private static class Foo2<B> {
public Foo1<? super B> foo1;
}
Expand Down Expand Up @@ -93,10 +94,12 @@ public void testSubSupertype() {
* Tests for recursion while resolving type variables.
*/

@SuppressWarnings("unused")
private static class TestType<X> {
TestType<? super X> superType;
}

@SuppressWarnings("unused")
private static class TestType2<X, Y> {
TestType2<? super Y, ? super X> superReversedType;
}
Expand All @@ -111,6 +114,3 @@ public void testRecursiveTypeVariablesResolve12() throws Exception {
assertNotNull(adapter);
}
}



0 comments on commit 7845c38

Please sign in to comment.