10000 http: Fix test dependency on hash order, which is about to change; · comma337/google-http-java-client@7feb194 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7feb194

Browse files
committed
http: Fix test dependency on hash order, which is about to change;
Documentation updates. https://codereview.appspot.com/110050044/
1 parent dbf30ba commit 7feb194

File tree

6 files changed

+26
-12
lines changed

6 files changed

+26
-12
lines changed

google-http-client-test/src/main/java/com/google/api/client/test/util/store/AbstractDataStoreFactoryTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,14 +137,14 @@ public void testValues() throws Exception {
137137
// delete one
138138
stringTyped.delete("k");
139139
assertNull(stringTyped.get("k"));
140-
assertEquals(Arrays.asList("other"), stringTyped.values());
140+
assertContentsAnyOrder(stringTyped.values(), "other");
141141
stringTyped.delete("k2");
142142
// boolean
143143
stringTyped.set("k", "v");
144144
assertTrue(boolTyped.values().isEmpty());
145145
boolTyped.set("k", true);
146-
assertEquals(Arrays.asList("v"), stringTyped.values());
147-
assertEquals(Arrays.asList(true), boolTyped.values());
146+
assertContentsAnyOrder(stringTyped.values(), "v");
147+
assertContentsAnyOrder(boolTyped.values(), true);
148148
}
149149

150150
public void testKeySet() throws Exception {

google-http-client/src/main/java/com/google/api/client/json/Json.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@
1414

1515
package com.google.api.client.json;
1616

17-
import com.google.api.client.http.HttpMediaType;
18-
import com.google.api.client.util.Charsets;
19-
2017
/**
2118
* JSON utilities.
2219
*
@@ -29,11 +26,11 @@ public class Json {
2926
* {@code "application/json; charset=utf-8"} media type used as a default for JSON parsing.
3027
*
3128
* <p>
32-
* Use {@link HttpMediaType#equalsIgnoreParameters} for comparing media types.
29+
* Use {@link com.google.api.client.http.HttpMediaType#equalsIgnoreParameters} for comparing
30+
* media types.
3331
* </p>
3432
*
3533
* @since 1.10
3634
*/
37-
public static final String MEDIA_TYPE =
38-
new HttpMediaType("application/json").setCharsetParameter(Charsets.UTF_8).build();
35+
public static final String MEDIA_TYPE = "application/json; charset=UTF-8";
3936
}

google-http-client/src/main/java/com/google/api/client/json/JsonParser.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,19 @@
4242
import java.util.concurrent.locks.ReentrantLock;
4343

4444
/**
45-
* Abstract low-level JSON parser.
45+
* Abstract low-level JSON parser. See
46+
* <a href="https://code.google.com/p/google-http-java-client/wiki/JSON">
47+
* https://code.google.com/p/google-http-java-client/wiki/JSON</a>
4648
*
4749
* <p>
4850
* Implementation has no fields and therefore thread-safe, but sub-classes are not necessarily
4951
* thread-safe.
5052
* </p>
53+
* <p>
54+
* <p>
55+
* If a JSON map is encountered while using a destination class of type Map, then an
56+
* {@link ArrayMap} is used by default for the parsed values.
57+
* </p>
5158
*
5259
* @since 1.3
5360
* @author Yaniv Inbar
@@ -436,6 +443,8 @@ private void parse(
436443
ClassInfo classInfo = ClassInfo.of(destinationClass);
437444
boolean isGenericData = GenericData.class.isAssignableFrom(destinationClass);
438445
if (!isGenericData && Map.class.isAssignableFrom(destinationClass)) {
446+
// The destination class is not a sub-class of GenericData but is of Map, so parse data
447+
// using parseMap.
439448
@SuppressWarnings("unchecked")
440449
Map<String, Object> destinationMap = (Map<String, Object>) destination;
441450
parseMap(null, destinationMap, Types.getMapValueParameter(destinationClass), context,
@@ -472,7 +481,7 @@ private void parse(
472481
GenericData object = (GenericData) destination;
473482
object.set(key, parseValue(null, null, context, destination, customizeParser, true));
474483
} else {
475-
// unrecognized field, skip value
484+
// unrecognized field, skip value.
476485
if (customizeParser != null) {
477486
customizeParser.handleUnrecognizedKey(destination, key);
478487
}

google-http-client/src/main/java/com/google/api/client/util/Types.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,9 @@ public static Type getMapValueParameter(Type mapType) {
324324

325325
private static Type getActualParameterAtPosition(Type type, Class<?> superClass, int position) {
326326
ParameterizedType parameterizedType = Types.getSuperParameterizedType(type, superClass);
327+
if (parameterizedType == null) {
328+
return null;
329+
}
327330
Type valueType = parameterizedType.getActualTypeArguments()[position];
328331
// this is normally a type variable, except in the case where the class of iterableType is
329332
// superClass, e.g. Iterable<String>

google-http-client/src/test/java/com/google/api/client/http/HttpMediaTypeTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ public void testBuild_parameters() {
4343
assertEquals("main/sub; aaa=1; bbb=\";/ \"", m.build());
4444
}
4545

46+
public void testBuild_json() {
47+
HttpMediaType m = new HttpMediaType("application/json").setCharsetParameter(Charsets.UTF_8);
48+
assertEquals("application/json; charset=UTF-8", m.build());
49+
}
50+
4651
public void testBuild_multipartSpec() {
4752
HttpMediaType m = new HttpMediaType("main", "sub");
4853
m.setParameter("bbb", "foo=/bar");

google-http-client/src/test/java/com/google/api/client/util/DataTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ public void testIsNull() {
8989
assertFalse(Data.isNull((byte) 0));
9090
assertFalse(Data.isNull((short) 0));
9191
assertFalse(Data.isNull(0));
92-
assertFalse(Data.isNull(0l));
92+
assertFalse(Data.isNull(0L));
9393
assertFalse(Data.isNull((float) 0));
9494
assertFalse(Data.isNull((double) 0));
9595
assertFalse(Data.isNull(BigDecimal.ZERO));

0 commit comments

Comments
 (0)
0