Skip to content

Commit 7845c38

Browse files
Degubiinder123
authored andcommitted
Minor cleanups in deprecations and other warnings (#1522)
1 parent 0e90771 commit 7845c38

17 files changed

+61
-81
lines changed

gson/src/test/java/com/google/gson/DefaultDateTypeAdapterTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ public void testDatePattern() throws Exception {
167167
assertEquals(toLiteral(formatter.format(currentDate)), dateString);
168168
}
169169

170+
@SuppressWarnings("unused")
170171
public void testInvalidDatePattern() throws Exception {
171172
try {
172173
new DefaultDateTypeAdapter(Date.class, "I am a bad Date pattern....");

gson/src/test/java/com/google/gson/FieldAttributesTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ protected void setUp() throws Exception {
3939
fieldAttributes = new FieldAttributes(Foo.class.getField("bar"));
4040
}
4141

42+
@SuppressWarnings("unused")
4243
public void testNullField() throws Exception {
4344
try {
4445
new FieldAttributes(null);

gson/src/test/java/com/google/gson/JsonPrimitiveTest.java

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
*/
3131
public class JsonPrimitiveTest extends TestCase {
3232

33+
@SuppressWarnings("unused")
3334
public void testNulls() {
3435
try {
3536
new JsonPrimitive((Boolean) null);
@@ -113,8 +114,8 @@ public void testExponential() throws Exception {
113114
JsonPrimitive json = new JsonPrimitive("1E+7");
114115

115116
assertEquals(new BigDecimal("1E+7"), json.getAsBigDecimal());
116-
assertEquals(new Double("1E+7"), json.getAsDouble(), 0.00001);
117-
assertEquals(new Float("1E+7"), json.getAsDouble(), 0.00001);
117+
assertEquals(1E+7, json.getAsDouble(), 0.00001);
118+
assertEquals(1E+7, json.getAsDouble(), 0.00001);
118119

119120
try {
120121
json.getAsInt();
@@ -123,91 +124,91 @@ public void testExponential() throws Exception {
123124
}
124125

125126
public void testByteEqualsShort() {
126-
JsonPrimitive p1 = new JsonPrimitive(new Byte((byte)10));
127-
JsonPrimitive p2 = new JsonPrimitive(new Short((short)10));
127+
JsonPrimitive p1 = new JsonPrimitive(Byte.valueOf((byte)10));
128+
JsonPrimitive p2 = new JsonPrimitive(Short.valueOf((short)10));
128129
assertEquals(p1, p2);
129130
assertEquals(p1.hashCode(), p2.hashCode());
130131
}
131132

132133
public void testByteEqualsInteger() {
133-
JsonPrimitive p1 = new JsonPrimitive(new Byte((byte)10));
134-
JsonPrimitive p2 = new JsonPrimitive(new Integer(10));
134+
JsonPrimitive p1 = new JsonPrimitive(Byte.valueOf((byte)10));
135+
JsonPrimitive p2 = new JsonPrimitive(Integer.valueOf(10));
135136
assertEquals(p1, p2);
136137
assertEquals(p1.hashCode(), p2.hashCode());
137138
}
138139

139140
public void testByteEqualsLong() {
140-
JsonPrimitive p1 = new JsonPrimitive(new Byte((byte)10));
141-
JsonPrimitive p2 = new JsonPrimitive(new Long(10L));
141+
JsonPrimitive p1 = new JsonPrimitive(Byte.valueOf((byte)10));
142+
JsonPrimitive p2 = new JsonPrimitive(Long.valueOf(10L));
142143
assertEquals(p1, p2);
143144
assertEquals(p1.hashCode(), p2.hashCode());
144145
}
145146

146147
public void testByteEqualsBigInteger() {
147-
JsonPrimitive p1 = new JsonPrimitive(new Byte((byte)10));
148+
JsonPrimitive p1 = new JsonPrimitive(Byte.valueOf((byte)10));
148149
JsonPrimitive p2 = new JsonPrimitive(new BigInteger("10"));
149150
assertEquals(p1, p2);
150151
assertEquals(p1.hashCode(), p2.hashCode());
151152
}
152153

153154
public void testShortEqualsInteger() {
154-
JsonPrimitive p1 = new JsonPrimitive(new Short((short)10));
155-
JsonPrimitive p2 = new JsonPrimitive(new Integer(10));
155+
JsonPrimitive p1 = new JsonPrimitive(Short.valueOf((short)10));
156+
JsonPrimitive p2 = new JsonPrimitive(Integer.valueOf(10));
156157
assertEquals(p1, p2);
157158
assertEquals(p1.hashCode(), p2.hashCode());
158159
}
159160

160161
public void testShortEqualsLong() {
161-
JsonPrimitive p1 = new JsonPrimitive(new Short((short)10));
162-
JsonPrimitive p2 = new JsonPrimitive(new Long(10));
162+
JsonPrimitive p1 = new JsonPrimitive(Short.valueOf((short)10));
163+
JsonPrimitive p2 = new JsonPrimitive(Long.valueOf(10));
163164
assertEquals(p1, p2);
164165
assertEquals(p1.hashCode(), p2.hashCode());
165166
}
166167

167168
public void testShortEqualsBigInteger() {
168-
JsonPrimitive p1 = new JsonPrimitive(new Short((short)10));
169+
JsonPrimitive p1 = new JsonPrimitive(Short.valueOf((short)10));
169170
JsonPrimitive p2 = new JsonPrimitive(new BigInteger("10"));
170171
assertEquals(p1, p2);
171172
assertEquals(p1.hashCode(), p2.hashCode());
172173
}
173174

174175
public void testIntegerEqualsLong() {
175-
JsonPrimitive p1 = new JsonPrimitive(new Integer(10));
176-
JsonPrimitive p2 = new JsonPrimitive(new Long(10L));
176+
JsonPrimitive p1 = new JsonPrimitive(Integer.valueOf(10));
177+
JsonPrimitive p2 = new JsonPrimitive(Long.valueOf(10L));
177178
assertEquals(p1, p2);
178179
assertEquals(p1.hashCode(), p2.hashCode());
179180
}
180181

181182
public void testIntegerEqualsBigInteger() {
182-
JsonPrimitive p1 = new JsonPrimitive(new Integer(10));
183+
JsonPrimitive p1 = new JsonPrimitive(Integer.valueOf(10));
183184
JsonPrimitive p2 = new JsonPrimitive(new BigInteger("10"));
184185
assertEquals(p1, p2);
185186
assertEquals(p1.hashCode(), p2.hashCode());
186187
}
187188

188189
public void testLongEqualsBigInteger() {
189-
JsonPrimitive p1 = new JsonPrimitive(new Long(10L));
190+
JsonPrimitive p1 = new JsonPrimitive(Long.valueOf(10L));
190191
JsonPrimitive p2 = new JsonPrimitive(new BigInteger("10"));
191192
assertEquals(p1, p2);
192193
assertEquals(p1.hashCode(), p2.hashCode());
193194
}
194195

195196
public void testFloatEqualsDouble() {
196-
JsonPrimitive p1 = new JsonPrimitive(new Float(10.25F));
197-
JsonPrimitive p2 = new JsonPrimitive(new Double(10.25D));
197+
JsonPrimitive p1 = new JsonPrimitive(Float.valueOf(10.25F));
198+
JsonPrimitive p2 = new JsonPrimitive(Double.valueOf(10.25D));
198199
assertEquals(p1, p2);
199200
assertEquals(p1.hashCode(), p2.hashCode());
200201
}
201202

202203
public void testFloatEqualsBigDecimal() {
203-
JsonPrimitive p1 = new JsonPrimitive(new Float(10.25F));
204+
JsonPrimitive p1 = new JsonPrimitive(Float.valueOf(10.25F));
204205
JsonPrimitive p2 = new JsonPrimitive(new BigDecimal("10.25"));
205206
assertEquals(p1, p2);
206207
assertEquals(p1.hashCode(), p2.hashCode());
207208
}
208209

209210
public void testDoubleEqualsBigDecimal() {
210-
JsonPrimitive p1 = new JsonPrimitive(new Double(10.25D));
211+
JsonPrimitive p1 = new JsonPrimitive(Double.valueOf(10.25D));
211212
JsonPrimitive p2 = new JsonPrimitive(new BigDecimal("10.25"));
212213
assertEquals(p1, p2);
213214
assertEquals(p1.hashCode(), p2.hashCode());

gson/src/test/java/com/google/gson/common/MoreAsserts.java

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
package com.google.gson.common;
1818

19-
import junit.framework.Assert;
19+
import org.junit.Assert;
2020

2121
import java.util.Collection;
2222

@@ -28,26 +28,6 @@
2828
*/
2929
public class MoreAsserts {
3030

31-
public static void assertEquals(int[] expected, int[] target) {
32-
if (expected == null) {
33-
Assert.assertNull(target);
34-
}
35-
Assert.assertEquals(expected.length, target.length);
36-
for (int i = 0; i < expected.length; ++i) {
37-
Assert.assertEquals(expected[i], target[i]);
38-
}
39-
}
40-
41-
public static void assertEquals(Integer[] expected, Integer[] target) {
42-
if (expected == null) {
43-
Assert.assertNull(target);
44-
}
45-
Assert.assertEquals(expected.length, target.length);
46-
for (int i = 0; i < expected.length; ++i) {
47-
Assert.assertEquals(expected[i], target[i]);
48-
}
49-
}
50-
5131
/**
5232
* Asserts that the specified {@code value} is not present in {@code collection}
5333
* @param collection the collection to look into
@@ -69,5 +49,4 @@ public static void assertEqualsAndHashCode(Object a, Object b) {
6949
Assert.assertFalse(a.equals(null));
7050
Assert.assertFalse(a.equals(new Object()));
7151
}
72-
7352
}

gson/src/test/java/com/google/gson/functional/ArrayTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@
1919
import com.google.gson.Gson;
2020
import com.google.gson.GsonBuilder;
2121
import com.google.gson.JsonParseException;
22-
import com.google.gson.common.MoreAsserts;
2322
import com.google.gson.common.TestTypes.BagOfPrimitives;
2423
import com.google.gson.common.TestTypes.ClassWithObjects;
2524
import com.google.gson.reflect.TypeToken;
2625

2726
import junit.framework.TestCase;
27+
import static org.junit.Assert.assertArrayEquals;
2828

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

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

175175
assertEquals(2, target.length);
176-
MoreAsserts.assertEquals(new Integer[] { 1, 2 }, target[0].toArray(new Integer[0]));
177-
MoreAsserts.assertEquals(new Integer[] { 3, 4 }, target[1].toArray(new Integer[0]));
176+
assertArrayEquals(new Integer[] { 1, 2 }, target[0].toArray(new Integer[0]));
177+
assertArrayEquals(new Integer[] { 3, 4 }, target[1].toArray(new Integer[0]));
178178
}
179179

180180
public void testArrayOfPrimitivesAsObjectsSerialization() throws Exception {

gson/src/test/java/com/google/gson/functional/CollectionTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import com.google.gson.reflect.TypeToken;
4343

4444
import junit.framework.TestCase;
45+
import static org.junit.Assert.assertArrayEquals;
4546

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

7677
public void testTopLevelListOfIntegerCollectionsDeserialization() throws Exception {
@@ -86,7 +87,7 @@ public void testTopLevelListOfIntegerCollectionsDeserialization() throws Excepti
8687
}
8788

8889
for (int i = 0; i < 3; i++) {
89-
MoreAsserts.assertEquals(expected[i], toIntArray(target.get(i)));
90+
assertArrayEquals(expected[i], toIntArray(target.get(i)));
9091
}
9192
}
9293

gson/src/test/java/com/google/gson/functional/JsonParserTest.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,9 @@ public void testChangingCustomTreeAndDeserializing() {
123123

124124
public void testExtraCommasInArrays() {
125125
Type type = new TypeToken<List<String>>() {}.getType();
126-
assertEquals(list("a", null, "b", null, null), gson.fromJson("[a,,b,,]", type));
127-
assertEquals(list(null, null), gson.fromJson("[,]", type));
128-
assertEquals(list("a", null), gson.fromJson("[a,]", type));
126+
assertEquals(Arrays.asList("a", null, "b", null, null), gson.fromJson("[a,,b,,]", type));
127+
assertEquals(Arrays.asList(null, null), gson.fromJson("[,]", type));
128+
assertEquals(Arrays.asList("a", null), gson.fromJson("[a,]", type));
129129
}
130130

131131
public void testExtraCommasInMaps() {
@@ -136,8 +136,4 @@ public void testExtraCommasInMaps() {
136136
} catch (JsonSyntaxException expected) {
137137
}
138138
}
139-
140-
private <T> List<T> list(T... elements) {
141-
return Arrays.asList(elements);
142-
}
143139
}

gson/src/test/java/com/google/gson/functional/MapAsArrayTypeAdapterTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ public void disabled_testTwoTypesCollapseToOneSerialize() {
5959
.create();
6060

6161
Map<Number, String> original = new LinkedHashMap<Number, String>();
62-
original.put(new Double(1.0), "a");
63-
original.put(new Float(1.0), "b");
62+
original.put(1.0D, "a");
63+
original.put(1.0F, "b");
6464
try {
6565
gson.toJson(original, new TypeToken<Map<Number, String>>() {}.getType());
6666
fail(); // we no longer hash keys at serialization time

gson/src/test/java/com/google/gson/functional/MapTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ public void testMapDeserializationWithWildcardValues() {
364364
Type typeOfMap = new TypeToken<Map<String, ? extends Long>>() {}.getType();
365365
Map<String, ? extends Long> map = gson.fromJson("{\"test\":123}", typeOfMap);
366366
assertEquals(1, map.size());
367-
assertEquals(new Long(123L), map.get("test"));
367+
assertEquals(Long.valueOf(123L), map.get("test"));
368368
}
369369

370370

gson/src/test/java/com/google/gson/functional/ParameterizedTypesTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public void testParameterizedTypesWithCustomDeserializer() {
121121
.registerTypeAdapter(ptStringType, new MyParameterizedTypeAdapter<String>())
122122
.registerTypeAdapter(ptStringType, new MyParameterizedTypeInstanceCreator<String>(""))
123123
.registerTypeAdapter(ptIntegerType,
124-
new MyParameterizedTypeInstanceCreator<Integer>(new Integer(0)))
124+
new MyParameterizedTypeInstanceCreator<Integer>(0))
125125
.create();
126126

127127
MyParameterizedType<Integer> src = new MyParameterizedType<Integer>(10);

gson/src/test/java/com/google/gson/functional/PrimitiveTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -144,12 +144,12 @@ public void testNumberSerialization() {
144144

145145
public void testNumberDeserialization() {
146146
String json = "1";
147-
Number expected = new Integer(json);
147+
Number expected = Integer.valueOf(json);
148148
Number actual = gson.fromJson(json, Number.class);
149149
assertEquals(expected.intValue(), actual.intValue());
150150

151151
json = String.valueOf(Long.MAX_VALUE);
152-
expected = new Long(json);
152+
expected = Long.valueOf(json);
153153
actual = gson.fromJson(json, Number.class);
154154
assertEquals(expected.longValue(), actual.longValue());
155155

@@ -164,16 +164,16 @@ public void testNumberAsStringDeserialization() {
164164
}
165165

166166
public void testPrimitiveDoubleAutoboxedSerialization() {
167-
assertEquals("-122.08234335", gson.toJson(-122.08234335));
168-
assertEquals("122.08112002", gson.toJson(new Double(122.08112002)));
167+
assertEquals("-122.08234335", gson.toJson(-122.08234335D));
168+
assertEquals("122.08112002", gson.toJson(122.08112002D));
169169
}
170170

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

175175
actual = gson.fromJson("122.023900008000", Double.class);
176-
assertEquals(122.023900008, actual);
176+
assertEquals(122.023900008D, actual);
177177
}
178178

179179
public void testPrimitiveDoubleAutoboxedInASingleElementArraySerialization() {

gson/src/test/java/com/google/gson/internal/bind/JsonTreeWriterTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,17 +157,17 @@ public void testStrictBoxedNansAndInfinities() throws IOException {
157157
writer.setLenient(false);
158158
writer.beginArray();
159159
try {
160-
writer.value(new Double(Double.NaN));
160+
writer.value(Double.valueOf(Double.NaN));
161161
fail();
162162
} catch (IllegalArgumentException expected) {
163163
}
164164
try {
165-
writer.value(new Double(Double.NEGATIVE_INFINITY));
165+
writer.value(Double.valueOf(Double.NEGATIVE_INFINITY));
166166
fail();
167167
} catch (IllegalArgumentException expected) {
168168
}
169169
try {
170-
writer.value(new Double(Double.POSITIVE_INFINITY));
170+
writer.value(Double.valueOf(Double.POSITIVE_INFINITY));
171171
fail();
172172
} catch (IllegalArgumentException expected) {
173173
}

gson/src/test/java/com/google/gson/internal/bind/RecursiveTypesResolveTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,11 @@
3434
*/
3535
public class RecursiveTypesResolveTest extends TestCase {
3636

37+
@SuppressWarnings("unused")
3738
private static class Foo1<A> {
38-
public Foo2<? extends A> foo2;
39+
public Foo2<? extends A> foo2;
3940
}
40-
41+
@SuppressWarnings("unused")
4142
private static class Foo2<B> {
4243
public Foo1<? super B> foo1;
4344
}
@@ -93,10 +94,12 @@ public void testSubSupertype() {
9394
* Tests for recursion while resolving type variables.
9495
*/
9596

97+
@SuppressWarnings("unused")
9698
private static class TestType<X> {
9799
TestType<? super X> superType;
98100
}
99101

102+
@SuppressWarnings("unused")
100103
private static class TestType2<X, Y> {
101104
TestType2<? super Y, ? super X> superReversedType;
102105
}
@@ -111,6 +114,3 @@ public void testRecursiveTypeVariablesResolve12() throws Exception {
111114
assertNotNull(adapter);
112115
}
113116
}
114-
115-
116-

0 commit comments

Comments
 (0)