diff --git a/.kokoro/presubmit/graalvm-native-a.cfg b/.kokoro/presubmit/graalvm-native-a.cfg
index 1b125c908..1f4b4493c 100644
--- a/.kokoro/presubmit/graalvm-native-a.cfg
+++ b/.kokoro/presubmit/graalvm-native-a.cfg
@@ -29,5 +29,5 @@ env_vars: {
}
container_properties {
- docker_image: "us-docker.pkg.dev/java-graalvm-ci-prod/graalvm-integration-testing/graalvm_a:1.13.0"
+ docker_image: "us-docker.pkg.dev/java-graalvm-ci-prod/graalvm-integration-testing/graalvm_a:1.14.0"
}
diff --git a/.kokoro/presubmit/graalvm-native-b.cfg b/.kokoro/presubmit/graalvm-native-b.cfg
index 40dced107..1a8dec5aa 100644
--- a/.kokoro/presubmit/graalvm-native-b.cfg
+++ b/.kokoro/presubmit/graalvm-native-b.cfg
@@ -29,5 +29,5 @@ env_vars: {
}
container_properties {
- docker_image: "us-docker.pkg.dev/java-graalvm-ci-prod/graalvm-integration-testing/graalvm_b:1.13.0"
+ docker_image: "us-docker.pkg.dev/java-graalvm-ci-prod/graalvm-integration-testing/graalvm_b:1.14.0"
}
diff --git a/google-http-client-appengine/pom.xml b/google-http-client-appengine/pom.xml
index d7f740df1..8947539c3 100644
--- a/google-http-client-appengine/pom.xml
+++ b/google-http-client-appengine/pom.xml
@@ -90,4 +90,15 @@
test
+
+
+ native-deps
+
+
+ com.google.appengine
+ appengine-api-1.0-sdk
+
+
+
+
diff --git a/google-http-client-appengine/src/main/resources/META-INF/native-image/com.google.http-client/google-http-client-appengine/reflect-config.json b/google-http-client-appengine/src/main/resources/META-INF/native-image/com.google.http-client/google-http-client-appengine/reflect-config.json
new file mode 100644
index 000000000..d2efd41b8
--- /dev/null
+++ b/google-http-client-appengine/src/main/resources/META-INF/native-image/com.google.http-client/google-http-client-appengine/reflect-config.json
@@ -0,0 +1,47 @@
+[
+ {
+ "name": "com.google.apphosting.api.DatastorePb$DeleteRequest",
+ "methods": [
+ {
+ "name": "",
+ "parameterTypes": []
+ }
+ ]
+ },
+ {
+ "name": "com.google.apphosting.api.DatastorePb$GetRequest",
+ "methods": [
+ {
+ "name": "",
+ "parameterTypes": []
+ }
+ ]
+ },
+ {
+ "name": "com.google.apphosting.api.DatastorePb$NextRequest",
+ "methods": [
+ {
+ "name": "",
+ "parameterTypes": []
+ }
+ ]
+ },
+ {
+ "name": "com.google.apphosting.api.DatastorePb$PutRequest",
+ "methods": [
+ {
+ "name": "",
+ "parameterTypes": []
+ }
+ ]
+ },
+ {
+ "name": "com.google.apphosting.api.DatastorePb$Query",
+ "methods": [
+ {
+ "name": "",
+ "parameterTypes": []
+ }
+ ]
+ }
+]
diff --git a/google-http-client-appengine/src/test/java/com/google/api/client/extensions/appengine/http/UrlFetchTransportTest.java b/google-http-client-appengine/src/test/java/com/google/api/client/extensions/appengine/http/UrlFetchTransportTest.java
index 3de60a6d7..b9ce9585d 100644
--- a/google-http-client-appengine/src/test/java/com/google/api/client/extensions/appengine/http/UrlFetchTransportTest.java
+++ b/google-http-client-appengine/src/test/java/com/google/api/client/extensions/appengine/http/UrlFetchTransportTest.java
@@ -15,14 +15,19 @@
package com.google.api.client.extensions.appengine.http;
import junit.framework.TestCase;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
/**
* Tests {@link UrlFetchTransport}.
*
* @author Tony Aiuto
*/
+@RunWith(JUnit4.class)
public class UrlFetchTransportTest extends TestCase {
+ @Test
public void test() {
new UrlFetchTransport();
}
diff --git a/google-http-client-appengine/src/test/resources/META-INF/native-image/com.google.http-client/google-http-client-appengine/native-image.properties b/google-http-client-appengine/src/test/resources/META-INF/native-image/com.google.http-client/google-http-client-appengine/native-image.properties
new file mode 100644
index 000000000..33cc1b54d
--- /dev/null
+++ b/google-http-client-appengine/src/test/resources/META-INF/native-image/com.google.http-client/google-http-client-appengine/native-image.properties
@@ -0,0 +1 @@
+Args=--initialize-at-build-time=org.junit.runner.RunWith,java.lang.annotation.Annotation \
diff --git a/google-http-client-gson/pom.xml b/google-http-client-gson/pom.xml
index c25eb2afd..63f5fe10c 100644
--- a/google-http-client-gson/pom.xml
+++ b/google-http-client-gson/pom.xml
@@ -72,5 +72,10 @@
com.google.code.gson
gson
+
+ junit
+ junit
+ test
+
diff --git a/google-http-client-gson/src/test/java/com/google/api/client/json/gson/GsonFactoryTest.java b/google-http-client-gson/src/test/java/com/google/api/client/json/gson/GsonFactoryTest.java
index 5d166e689..b256f74f5 100644
--- a/google-http-client-gson/src/test/java/com/google/api/client/json/gson/GsonFactoryTest.java
+++ b/google-http-client-gson/src/test/java/com/google/api/client/json/gson/GsonFactoryTest.java
@@ -14,6 +14,10 @@
package com.google.api.client.json.gson;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
+
import com.google.api.client.json.GenericJson;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.JsonObjectParser;
@@ -25,6 +29,7 @@
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
+import org.junit.Test;
/**
* Tests {@link GsonFactory}.
@@ -58,21 +63,19 @@ public class GsonFactoryTest extends AbstractJsonFactoryTest {
+ GSON_LINE_SEPARATOR
+ "}";
- public GsonFactoryTest(String name) {
- super(name);
- }
-
@Override
protected JsonFactory newFactory() {
return new GsonFactory();
}
+ @Test
public final void testToPrettyString_entry() throws Exception {
Entry entry = new Entry();
entry.title = "foo";
assertEquals(JSON_ENTRY_PRETTY, newFactory().toPrettyString(entry));
}
+ @Test
public final void testToPrettyString_Feed() throws Exception {
Feed feed = new Feed();
Entry entryFoo = new Entry();
@@ -85,11 +88,13 @@ public final void testToPrettyString_Feed() throws Exception {
assertEquals(JSON_FEED_PRETTY, newFactory().toPrettyString(feed));
}
+ @Test
public final void testParse_directValue() throws IOException {
JsonParser parser = newFactory().createJsonParser("123");
assertEquals(123, parser.parse(Integer.class, true));
}
+ @Test
public final void testGetByteValue() throws IOException {
JsonParser parser = newFactory().createJsonParser("123");
@@ -101,6 +106,7 @@ public final void testGetByteValue() throws IOException {
}
}
+ @Test
public final void testReaderLeniency_lenient() throws IOException {
JsonObjectParser parser =
new JsonObjectParser(GsonFactory.builder().setReadLeniency(true).build());
@@ -113,6 +119,7 @@ public final void testReaderLeniency_lenient() throws IOException {
assertEquals("foo", json.get("title"));
}
+ @Test
public final void testReaderLeniency_not_lenient_by_default() throws IOException {
JsonObjectParser parser = new JsonObjectParser(GsonFactory.getDefaultInstance());
diff --git a/google-http-client-gson/src/test/resources/META-INF/native-image/com.google.http-client/google-http-client-gson/native-image.properties b/google-http-client-gson/src/test/resources/META-INF/native-image/com.google.http-client/google-http-client-gson/native-image.properties
new file mode 100644
index 000000000..3cbd2b27f
--- /dev/null
+++ b/google-http-client-gson/src/test/resources/META-INF/native-image/com.google.http-client/google-http-client-gson/native-image.properties
@@ -0,0 +1 @@
+Args=--initialize-at-build-time=org.junit.runner.RunWith,java.lang.annotation.Annotation
diff --git a/google-http-client-jackson2/pom.xml b/google-http-client-jackson2/pom.xml
index e1e09f8fb..3816e5094 100644
--- a/google-http-client-jackson2/pom.xml
+++ b/google-http-client-jackson2/pom.xml
@@ -71,5 +71,10 @@
com.fasterxml.jackson.core
jackson-core
+
+ junit
+ junit
+ test
+
diff --git a/google-http-client-jackson2/src/test/java/com/google/api/client/json/jackson2/JacksonFactoryTest.java b/google-http-client-jackson2/src/test/java/com/google/api/client/json/jackson2/JacksonFactoryTest.java
index c90edc2e3..89e7d0596 100644
--- a/google-http-client-jackson2/src/test/java/com/google/api/client/json/jackson2/JacksonFactoryTest.java
+++ b/google-http-client-jackson2/src/test/java/com/google/api/client/json/jackson2/JacksonFactoryTest.java
@@ -14,12 +14,17 @@
package com.google.api.client.json.jackson2;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
+
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.JsonParser;
import com.google.api.client.test.json.AbstractJsonFactoryTest;
import com.google.api.client.util.StringUtils;
import java.io.IOException;
import java.util.ArrayList;
+import org.junit.Test;
/**
* Tests {@link JacksonFactory}.
@@ -45,21 +50,19 @@ public class JacksonFactoryTest extends AbstractJsonFactoryTest {
+ StringUtils.LINE_SEPARATOR
+ "}";
- public JacksonFactoryTest(String name) {
- super(name);
- }
-
@Override
protected JsonFactory newFactory() {
return new JacksonFactory();
}
+ @Test
public final void testToPrettyString_entry() throws Exception {
Entry entry = new Entry();
entry.title = "foo";
assertEquals(JSON_ENTRY_PRETTY, newFactory().toPrettyString(entry));
}
+ @Test
public final void testToPrettyString_Feed() throws Exception {
Feed feed = new Feed();
Entry entryFoo = new Entry();
@@ -72,11 +75,13 @@ public final void testToPrettyString_Feed() throws Exception {
assertEquals(JSON_FEED_PRETTY, newFactory().toPrettyString(feed));
}
+ @Test
public final void testParse_directValue() throws Exception {
JsonParser parser = newFactory().createJsonParser("123");
assertEquals(123, parser.parse(Integer.class, true));
}
+ @Test
public final void testGetByteValue() throws IOException {
JsonParser parser = newFactory().createJsonParser("123");
diff --git a/google-http-client-jackson2/src/test/resources/META-INF/native-image/com.google.http-client/google-http-client-jackson2/native-image.properties b/google-http-client-jackson2/src/test/resources/META-INF/native-image/com.google.http-client/google-http-client-jackson2/native-image.properties
index b6b626175..0bb622f01 100644
--- a/google-http-client-jackson2/src/test/resources/META-INF/native-image/com.google.http-client/google-http-client-jackson2/native-image.properties
+++ b/google-http-client-jackson2/src/test/resources/META-INF/native-image/com.google.http-client/google-http-client-jackson2/native-image.properties
@@ -1,7 +1,6 @@
Args=--initialize-at-build-time=com.google.api.client.json.jackson2.JacksonFactoryTest \
--initialize-at-build-time=com.google.api.client.json.jackson2.JacksonGeneratorTest \
---initialize-at-build-time=com.fasterxml.jackson.core.io.SerializedString \
---initialize-at-build-time=com.fasterxml.jackson.core.io.CharTypes \
---initialize-at-build-time=com.fasterxml.jackson.core.JsonFactory \
---initialize-at-build-time=com.fasterxml.jackson.core.io.JsonStringEncoder \
---initialize-at-build-time=com.google.api.client.util.StringUtils
\ No newline at end of file
+--initialize-at-build-time=com.google.api.client.json.jackson2.JacksonFactory \
+--initialize-at-build-time=com.google.api.client.util.StringUtils \
+--initialize-at-build-time=com.fasterxml.jackson.core \
+--initialize-at-build-time=org.junit.runner.RunWith,java.lang.annotation.Annotation
\ No newline at end of file
diff --git a/google-http-client-protobuf/src/main/resources/META-INF/native-image/com.google.http-client/google-http-client-protobuf/native-image.properties b/google-http-client-protobuf/src/main/resources/META-INF/native-image/com.google.http-client/google-http-client-protobuf/native-image.properties
new file mode 100644
index 000000000..3cbd2b27f
--- /dev/null
+++ b/google-http-client-protobuf/src/main/resources/META-INF/native-image/com.google.http-client/google-http-client-protobuf/native-image.properties
@@ -0,0 +1 @@
+Args=--initialize-at-build-time=org.junit.runner.RunWith,java.lang.annotation.Annotation
diff --git a/google-http-client-protobuf/src/test/java/com/google/api/client/protobuf/ProtocolBuffersTest.java b/google-http-client-protobuf/src/test/java/com/google/api/client/protobuf/ProtocolBuffersTest.java
index 94d7d1391..40265b8c3 100644
--- a/google-http-client-protobuf/src/test/java/com/google/api/client/protobuf/ProtocolBuffersTest.java
+++ b/google-http-client-protobuf/src/test/java/com/google/api/client/protobuf/ProtocolBuffersTest.java
@@ -14,16 +14,22 @@
package com.google.api.client.protobuf;
+import static org.junit.Assert.assertEquals;
+
import java.io.ByteArrayInputStream;
-import junit.framework.TestCase;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
/**
* Tests {@link ProtocolBuffers}.
*
* @author Yaniv Inbar
*/
-public class ProtocolBuffersTest extends TestCase {
+@RunWith(JUnit4.class)
+public class ProtocolBuffersTest {
+ @Test
public void testParseAndClose() throws Exception {
SimpleProto.TestMessage mockResponse =
SimpleProto.TestMessage.newBuilder()
diff --git a/google-http-client-test/clirr-ignored-differences.xml b/google-http-client-test/clirr-ignored-differences.xml
new file mode 100644
index 000000000..34c8e4f44
--- /dev/null
+++ b/google-http-client-test/clirr-ignored-differences.xml
@@ -0,0 +1,75 @@
+
+
+
+
+
+
+ 4001
+ com/google/api/client/test/util/store/AbstractDataStoreFactoryTest
+ junit/framework/Test
+
+
+
+ 4001
+ com/google/api/client/test/json/AbstractJsonFactoryTest
+ junit/framework/Test
+
+
+
+ 4001
+ com/google/api/client/test/json/AbstractJsonGeneratorTest
+ junit/framework/Test
+
+
+
+ 4001
+ com/google/api/client/test/json/AbstractJsonParserTest
+ junit/framework/Test
+
+
+
+ 5001
+ com/google/api/client/test/util/store/AbstractDataStoreFactoryTest
+ junit/framework/*
+
+
+
+ 5001
+ com/google/api/client/test/json/AbstractJsonFactoryTest
+ junit/framework/*
+
+
+
+ 5001
+ com/google/api/client/test/json/AbstractJsonGeneratorTest
+ junit/framework/*
+
+
+
+ 5001
+ com/google/api/client/test/json/AbstractJsonParserTest
+ junit/framework/*
+
+
+
+ 7004
+ com/google/api/client/test/json/AbstractJsonFactoryTest
+ *
+
+
diff --git a/google-http-client-test/src/main/java/com/google/api/client/test/json/AbstractJsonFactoryTest.java b/google-http-client-test/src/main/java/com/google/api/client/test/json/AbstractJsonFactoryTest.java
index 8bf518109..a0629280f 100644
--- a/google-http-client-test/src/main/java/com/google/api/client/test/json/AbstractJsonFactoryTest.java
+++ b/google-http-client-test/src/main/java/com/google/api/client/test/json/AbstractJsonFactoryTest.java
@@ -14,6 +14,13 @@
package com.google.api.client.test.json;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
import com.google.api.client.http.json.JsonHttpContent;
import com.google.api.client.json.GenericJson;
import com.google.api.client.json.JsonFactory;
@@ -53,29 +60,36 @@
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
-import junit.framework.TestCase;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
/**
* Abstract test case for testing a {@link JsonFactory}.
*
* @author Yaniv Inbar
*/
-public abstract class AbstractJsonFactoryTest extends TestCase {
-
- public AbstractJsonFactoryTest(String name) {
- super(name);
- }
+@RunWith(JUnit4.class)
+public abstract class AbstractJsonFactoryTest {
protected abstract JsonFactory newFactory();
- private static final String EMPTY = "";
- private static final String JSON_THREE_ELEMENTS =
- "{"
- + " \"one\": { \"num\": 1 }"
- + ", \"two\": { \"num\": 2 }"
- + ", \"three\": { \"num\": 3 }"
- + "}";
+ private static final String EMPTY;
+ private static final String JSON_THREE_ELEMENTS;
+ private static final String EMPTY_OBJECT;
+ static {
+ EMPTY = "";
+ JSON_THREE_ELEMENTS =
+ "{"
+ + " \"one\": { \"num\": 1 }"
+ + ", \"two\": { \"num\": 2 }"
+ + ", \"three\": { \"num\": 3 }"
+ + "}";
+ EMPTY_OBJECT = "{}";
+ }
+
+ @Test
public void testParse_empty() throws Exception {
JsonParser parser = newFactory().createJsonParser(EMPTY);
parser.nextToken();
@@ -87,8 +101,7 @@ public void testParse_empty() throws Exception {
}
}
- private static final String EMPTY_OBJECT = "{}";
-
+ @Test
public void testParse_emptyMap() throws Exception {
JsonParser parser = newFactory().createJsonParser(EMPTY_OBJECT);
parser.nextToken();
@@ -97,6 +110,7 @@ public void testParse_emptyMap() throws Exception {
assertTrue(map.isEmpty());
}
+ @Test
public void testParse_emptyGenericJson() throws Exception {
JsonParser parser = newFactory().createJsonParser(EMPTY_OBJECT);
parser.nextToken();
@@ -104,6 +118,7 @@ public void testParse_emptyGenericJson() throws Exception {
assertTrue(json.isEmpty());
}
+ @Test
public void testParser_partialEmpty() throws Exception {
JsonFactory factory = newFactory();
JsonParser parser;
@@ -118,15 +133,21 @@ public void testParser_partialEmpty() throws Exception {
assertTrue(result.isEmpty());
}
- private static final String JSON_ENTRY = "{\"title\":\"foo\"}";
- private static final String JSON_FEED =
- "{\"entries\":[" + "{\"title\":\"foo\"}," + "{\"title\":\"bar\"}]}";
+ private static final String JSON_ENTRY;
+ private static final String JSON_FEED;
+
+ static {
+ JSON_ENTRY = "{\"title\":\"foo\"}";
+ JSON_FEED = "{\"entries\":[" + "{\"title\":\"foo\"}," + "{\"title\":\"bar\"}]}";
+ }
+ @Test
public void testParseEntry() throws Exception {
Entry entry = newFactory().createJsonParser(JSON_ENTRY).parseAndClose(Entry.class);
assertEquals("foo", entry.title);
}
+ @Test
public void testParser_partialEntry() throws Exception {
JsonFactory factory = newFactory();
JsonParser parser;
@@ -140,6 +161,7 @@ public void testParser_partialEntry() throws Exception {
assertEquals("foo", result.title);
}
+ @Test
public void testParseFeed() throws Exception {
JsonParser parser = newFactory().createJsonParser(JSON_FEED);
parser.nextToken();
@@ -151,6 +173,7 @@ public void testParseFeed() throws Exception {
}
@SuppressWarnings("unchecked")
+ @Test
public void testParseEntryAsMap() throws Exception {
JsonParser parser = newFactory().createJsonParser(JSON_ENTRY);
parser.nextToken();
@@ -159,6 +182,7 @@ public void testParseEntryAsMap() throws Exception {
assertTrue(map.isEmpty());
}
+ @Test
public void testSkipToKey_missingEmpty() throws Exception {
JsonParser parser = newFactory().createJsonParser(EMPTY_OBJECT);
parser.nextToken();
@@ -166,6 +190,7 @@ public void testSkipToKey_missingEmpty() throws Exception {
assertEquals(JsonToken.END_OBJECT, parser.getCurrentToken());
}
+ @Test
public void testSkipToKey_missing() throws Exception {
JsonParser parser = newFactory().createJsonParser(JSON_ENTRY);
parser.nextToken();
@@ -173,6 +198,7 @@ public void testSkipToKey_missing() throws Exception {
assertEquals(JsonToken.END_OBJECT, parser.getCurrentToken());
}
+ @Test
public void testSkipToKey_found() throws Exception {
JsonParser parser = newFactory().createJsonParser(JSON_ENTRY);
parser.nextToken();
@@ -181,6 +207,7 @@ public void testSkipToKey_found() throws Exception {
assertEquals("foo", parser.getText());
}
+ @Test
public void testSkipToKey_startWithFieldName() throws Exception {
JsonParser parser = newFactory().createJsonParser(JSON_ENTRY);
parser.nextToken();
@@ -190,6 +217,7 @@ public void testSkipToKey_startWithFieldName() throws Exception {
assertEquals("foo", parser.getText());
}
+ @Test
public void testSkipChildren_string() throws Exception {
JsonParser parser = newFactory().createJsonParser(JSON_ENTRY);
parser.nextToken();
@@ -199,6 +227,7 @@ public void testSkipChildren_string() throws Exception {
assertEquals("foo", parser.getText());
}
+ @Test
public void testSkipChildren_object() throws Exception {
JsonParser parser = newFactory().createJsonParser(JSON_ENTRY);
parser.nextToken();
@@ -206,6 +235,7 @@ public void testSkipChildren_object() throws Exception {
assertEquals(JsonToken.END_OBJECT, parser.getCurrentToken());
}
+ @Test
public void testSkipChildren_array() throws Exception {
JsonParser parser = newFactory().createJsonParser(JSON_FEED);
parser.nextToken();
@@ -214,6 +244,7 @@ public void testSkipChildren_array() throws Exception {
assertEquals(JsonToken.END_ARRAY, parser.getCurrentToken());
}
+ @Test
public void testNextToken() throws Exception {
JsonParser parser = newFactory().createJsonParser(JSON_FEED);
assertEquals(JsonToken.START_OBJECT, parser.nextToken());
@@ -232,6 +263,7 @@ public void testNextToken() throws Exception {
assertNull(parser.nextToken());
}
+ @Test
public void testCurrentToken() throws Exception {
JsonParser parser = newFactory().createJsonParser(JSON_FEED);
assertNull(parser.getCurrentToken());
@@ -277,8 +309,13 @@ public static class A {
@Key public Map map;
}
- static final String CONTAINED_MAP = "{\"map\":{\"title\":\"foo\"}}";
+ static final String CONTAINED_MAP;
+
+ static {
+ CONTAINED_MAP = "{\"map\":{\"title\":\"foo\"}}";
+ }
+ @Test
public void testParse() throws Exception {
JsonParser parser = newFactory().createJsonParser(CONTAINED_MAP);
parser.nextToken();
@@ -335,22 +372,27 @@ public static class NumberTypesAsString {
@Key @JsonString Map longMapValue;
}
- static final String NUMBER_TYPES =
- "{\"bigDecimalValue\":1.0,\"bigIntegerValue\":1,\"byteObjValue\":1,\"byteValue\":1,"
- + "\"doubleObjValue\":1.0,\"doubleValue\":1.0,\"floatObjValue\":1.0,\"floatValue\":1.0,"
- + "\"intObjValue\":1,\"intValue\":1,\"longListValue\":[1],\"longMapValue\":{\"a\":1},"
- + "\"longObjValue\":1,\"longValue\":1,\"shortObjValue\":1,\"shortValue\":1,"
- + "\"yetAnotherBigDecimalValue\":1}";
+ static final String NUMBER_TYPES;
+ static final String NUMBER_TYPES_AS_STRING;
- static final String NUMBER_TYPES_AS_STRING =
- "{\"bigDecimalValue\":\"1.0\",\"bigIntegerValue\":\"1\",\"byteObjValue\":\"1\","
- + "\"byteValue\":\"1\",\"doubleObjValue\":\"1.0\",\"doubleValue\":\"1.0\","
- + "\"floatObjValue\":\"1.0\",\"floatValue\":\"1.0\",\"intObjValue\":\"1\","
- + "\"intValue\":\"1\",\"longListValue\":[\"1\"],\"longMapValue\":{\"a\":\"1\"},"
- + "\"longObjValue\":\"1\",\"longValue\":\"1\","
- + "\"shortObjValue\":\"1\","
- + "\"shortValue\":\"1\",\"yetAnotherBigDecimalValue\":\"1\"}";
+ static {
+ NUMBER_TYPES =
+ "{\"bigDecimalValue\":1.0,\"bigIntegerValue\":1,\"byteObjValue\":1,\"byteValue\":1,"
+ + "\"doubleObjValue\":1.0,\"doubleValue\":1.0,\"floatObjValue\":1.0,\"floatValue\":1.0,"
+ + "\"intObjValue\":1,\"intValue\":1,\"longListValue\":[1],\"longMapValue\":{\"a\":1},"
+ + "\"longObjValue\":1,\"longValue\":1,\"shortObjValue\":1,\"shortValue\":1,"
+ + "\"yetAnotherBigDecimalValue\":1}";
+ NUMBER_TYPES_AS_STRING =
+ "{\"bigDecimalValue\":\"1.0\",\"bigIntegerValue\":\"1\",\"byteObjValue\":\"1\","
+ + "\"byteValue\":\"1\",\"doubleObjValue\":\"1.0\",\"doubleValue\":\"1.0\","
+ + "\"floatObjValue\":\"1.0\",\"floatValue\":\"1.0\",\"intObjValue\":\"1\","
+ + "\"intValue\":\"1\",\"longListValue\":[\"1\"],\"longMapValue\":{\"a\":\"1\"},"
+ + "\"longObjValue\":\"1\",\"longValue\":\"1\","
+ + "\"shortObjValue\":\"1\","
+ + "\"shortValue\":\"1\",\"yetAnotherBigDecimalValue\":\"1\"}";
+ }
+ @Test
public void testParser_numberTypes() throws Exception {
JsonFactory factory = newFactory();
JsonParser parser;
@@ -384,15 +426,22 @@ public void testParser_numberTypes() throws Exception {
}
}
+ @Test
public void testToFromString() throws Exception {
JsonFactory factory = newFactory();
NumberTypes result = factory.fromString(NUMBER_TYPES, NumberTypes.class);
assertEquals(NUMBER_TYPES, factory.toString(result));
}
- private static final String UTF8_VALUE = "123\u05D9\u05e0\u05D9\u05D1";
- private static final String UTF8_JSON = "{\"value\":\"" + UTF8_VALUE + "\"}";
+ private static final String UTF8_VALUE;
+ private static final String UTF8_JSON;
+ static {
+ UTF8_VALUE = "123\u05D9\u05e0\u05D9\u05D1";
+ UTF8_JSON = "{\"value\":\"" + UTF8_VALUE + "\"}";
+ }
+
+ @Test
public void testToFromString_UTF8() throws Exception {
JsonFactory factory = newFactory();
GenericJson result = factory.fromString(UTF8_JSON, GenericJson.class);
@@ -409,10 +458,15 @@ public static class AnyType {
@Key public Object nul;
}
- static final String ANY_TYPE =
- "{\"arr\":[1],\"bool\":true,\"nul\":null,\"num\":5,"
- + "\"obj\":{\"key\":\"value\"},\"str\":\"value\"}";
+ static final String ANY_TYPE;
+ static {
+ ANY_TYPE =
+ "{\"arr\":[1],\"bool\":true,\"nul\":null,\"num\":5,"
+ + "\"obj\":{\"key\":\"value\"},\"str\":\"value\"}";
+ }
+
+ @Test
public void testParser_anyType() throws Exception {
JsonFactory factory = newFactory();
JsonParser parser;
@@ -430,8 +484,13 @@ public static class ArrayType {
@Key public Integer[] integerArr;
}
- static final String ARRAY_TYPE = "{\"arr\":[4,5],\"arr2\":[[1,2],[3]],\"integerArr\":[6,7]}";
+ static final String ARRAY_TYPE;
+
+ static {
+ ARRAY_TYPE = "{\"arr\":[4,5],\"arr2\":[[1,2],[3]],\"integerArr\":[6,7]}";
+ }
+ @Test
public void testParser_arrayType() throws Exception {
JsonFactory factory = newFactory();
JsonParser parser;
@@ -461,8 +520,13 @@ public static class CollectionOfCollectionType {
@Key public LinkedList> arr;
}
- static final String COLLECTION_TYPE = "{\"arr\":[[\"a\",\"b\"],[\"c\"]]}";
+ static final String COLLECTION_TYPE;
+ static {
+ COLLECTION_TYPE = "{\"arr\":[[\"a\",\"b\"],[\"c\"]]}";
+ }
+
+ @Test
public void testParser_collectionType() throws Exception {
JsonFactory factory = newFactory();
JsonParser parser;
@@ -480,9 +544,13 @@ public static class MapOfMapType {
@Key public Map>[] value;
}
- static final String MAP_TYPE =
- "{\"value\":[{\"map1\":{\"k1\":1,\"k2\":2},\"map2\":{\"kk1\":3,\"kk2\":4}}]}";
+ static final String MAP_TYPE;
+
+ static {
+ MAP_TYPE = "{\"value\":[{\"map1\":{\"k1\":1,\"k2\":2},\"map2\":{\"kk1\":3,\"kk2\":4}}]}";
+ }
+ @Test
public void testParser_mapType() throws Exception {
// parse
JsonFactory factory = newFactory();
@@ -503,6 +571,7 @@ public void testParser_mapType() throws Exception {
assertEquals(4, map2.get("kk2").intValue());
}
+ @Test
public void testParser_hashmapForMapType() throws Exception {
// parse
JsonFactory factory = newFactory();
@@ -531,11 +600,16 @@ public static class WildCardTypes {
@Key public Collection extends Integer>[] upper;
}
- static final String WILDCARD_TYPE =
- "{\"lower\":[[1,2,3]],\"map\":{\"v\":1},\"mapInWild\":[{\"v\":1}],"
- + "\"mapUpper\":{\"v\":1},\"simple\":[[1,2,3]],\"upper\":[[1,2,3]]}";
+ static final String WILDCARD_TYPE;
+
+ static {
+ WILDCARD_TYPE =
+ "{\"lower\":[[1,2,3]],\"map\":{\"v\":1},\"mapInWild\":[{\"v\":1}],"
+ + "\"mapUpper\":{\"v\":1},\"simple\":[[1,2,3]],\"upper\":[[1,2,3]]}";
+ }
@SuppressWarnings("unchecked")
+ @Test
public void testParser_wildCardType() throws Exception {
// parse
JsonFactory factory = newFactory();
@@ -590,20 +664,31 @@ public static class DoubleListTypeVariableType extends TypeVariableType> {}
- static final String INTEGER_TYPE_VARIABLE_TYPE =
- "{\"arr\":[null,[null,1]],\"list\":[null,[null,1]],\"nullValue\":null,\"value\":1}";
+ static final String INTEGER_TYPE_VARIABLE_TYPE;
+
+ static final String INT_ARRAY_TYPE_VARIABLE_TYPE;
+
+ static final String DOUBLE_LIST_TYPE_VARIABLE_TYPE;
+
+ static final String FLOAT_MAP_TYPE_VARIABLE_TYPE;
+
+ static {
+ INTEGER_TYPE_VARIABLE_TYPE =
+ "{\"arr\":[null,[null,1]],\"list\":[null,[null,1]],\"nullValue\":null,\"value\":1}";
- static final String INT_ARRAY_TYPE_VARIABLE_TYPE =
- "{\"arr\":[null,[null,[1]]],\"list\":[null,[null,[1]]],\"nullValue\":null,\"value\":[1]}";
+ INT_ARRAY_TYPE_VARIABLE_TYPE =
+ "{\"arr\":[null,[null,[1]]],\"list\":[null,[null,[1]]],\"nullValue\":null,\"value\":[1]}";
- static final String DOUBLE_LIST_TYPE_VARIABLE_TYPE =
- "{\"arr\":[null,[null,[1.0]]],\"list\":[null,[null,[1.0]]],"
- + "\"nullValue\":null,\"value\":[1.0]}";
+ DOUBLE_LIST_TYPE_VARIABLE_TYPE =
+ "{\"arr\":[null,[null,[1.0]]],\"list\":[null,[null,[1.0]]],"
+ + "\"nullValue\":null,\"value\":[1.0]}";
- static final String FLOAT_MAP_TYPE_VARIABLE_TYPE =
- "{\"arr\":[null,[null,{\"a\":1.0}]],\"list\":[null,[null,{\"a\":1.0}]],"
- + "\"nullValue\":null,\"value\":{\"a\":1.0}}";
+ FLOAT_MAP_TYPE_VARIABLE_TYPE =
+ "{\"arr\":[null,[null,{\"a\":1.0}]],\"list\":[null,[null,{\"a\":1.0}]],"
+ + "\"nullValue\":null,\"value\":{\"a\":1.0}}";
+ }
+ @Test
public void testParser_integerTypeVariableType() throws Exception {
// parse
JsonFactory factory = newFactory();
@@ -640,6 +725,7 @@ public void testParser_integerTypeVariableType() throws Exception {
assertEquals(1, value.intValue());
}
+ @Test
public void testParser_intArrayTypeVariableType() throws Exception {
// parse
JsonFactory factory = newFactory();
@@ -676,6 +762,7 @@ public void testParser_intArrayTypeVariableType() throws Exception {
assertTrue(Arrays.equals(new int[] {1}, value));
}
+ @Test
public void testParser_doubleListTypeVariableType() throws Exception {
// parse
JsonFactory factory = newFactory();
@@ -696,7 +783,7 @@ public void testParser_doubleListTypeVariableType() throws Exception {
List arrValue = subArr[1];
assertEquals(1, arrValue.size());
Double dValue = arrValue.get(0);
- assertEquals(1.0, dValue);
+ assertEquals(Double.valueOf(1.0), dValue);
// collection
LinkedList>> list = result.list;
assertEquals(2, list.size());
@@ -714,6 +801,7 @@ public void testParser_doubleListTypeVariableType() throws Exception {
assertEquals(ImmutableList.of(Double.valueOf(1)), value);
}
+ @Test
public void testParser_floatMapTypeVariableType() throws Exception {
// parse
JsonFactory factory = newFactory();
@@ -734,7 +822,7 @@ public void testParser_floatMapTypeVariableType() throws Exception {
Map arrValue = subArr[1];
assertEquals(1, arrValue.size());
Float fValue = arrValue.get("a");
- assertEquals(1.0f, fValue);
+ assertEquals(Float.valueOf(1.0f), fValue);
// collection
LinkedList>> list = result.list;
assertEquals(2, list.size());
@@ -745,7 +833,7 @@ public void testParser_floatMapTypeVariableType() throws Exception {
arrValue = subList.get(1);
assertEquals(1, arrValue.size());
fValue = arrValue.get("a");
- assertEquals(1.0f, fValue);
+ assertEquals(Float.valueOf(1.0f), fValue);
// null value
Map nullValue = result.nullValue;
assertEquals(Data.nullOf(HashMap.class), nullValue);
@@ -753,10 +841,11 @@ public void testParser_floatMapTypeVariableType() throws Exception {
Map value = result.value;
assertEquals(1, value.size());
fValue = value.get("a");
- assertEquals(1.0f, fValue);
+ assertEquals(Float.valueOf(1.0f), fValue);
}
@SuppressWarnings("unchecked")
+ @Test
public void testParser_treemapForTypeVariableType() throws Exception {
// parse
JsonFactory factory = newFactory();
@@ -790,8 +879,13 @@ public static class StringNullValue {
@Key public String value;
}
- static final String NULL_VALUE = "{\"arr\":[null],\"arr2\":[null,[null]],\"value\":null}";
+ static final String NULL_VALUE;
+
+ static {
+ NULL_VALUE = "{\"arr\":[null],\"arr2\":[null,[null]],\"value\":null}";
+ }
+ @Test
public void testParser_nullValue() throws Exception {
// parse
JsonFactory factory = newFactory();
@@ -830,9 +924,13 @@ public static class EnumValue {
@Key public E nullValue;
}
- static final String ENUM_VALUE =
- "{\"nullValue\":null,\"otherValue\":\"other\",\"value\":\"VALUE\"}";
+ static final String ENUM_VALUE;
+ static {
+ ENUM_VALUE = "{\"nullValue\":null,\"otherValue\":\"other\",\"value\":\"VALUE\"}";
+ }
+
+ @Test
public void testParser_enumValue() throws Exception {
// parse
JsonFactory factory = newFactory();
@@ -862,8 +960,13 @@ public static class Z {
public static class TypeVariablesPassedAround extends X> {}
- static final String TYPE_VARS = "{\"y\":{\"z\":{\"f\":[\"abc\"]}}}";
+ static final String TYPE_VARS;
+
+ static {
+ TYPE_VARS = "{\"y\":{\"z\":{\"f\":[\"abc\"]}}}";
+ }
+ @Test
public void testParser_typeVariablesPassAround() throws Exception {
// parse
JsonFactory factory = newFactory();
@@ -878,8 +981,13 @@ public void testParser_typeVariablesPassAround() throws Exception {
assertEquals("abc", f.get(0));
}
- static final String STRING_ARRAY = "[\"a\",\"b\",\"c\"]";
+ static final String STRING_ARRAY;
+ static {
+ STRING_ARRAY = "[\"a\",\"b\",\"c\"]";
+ }
+
+ @Test
public void testParser_stringArray() throws Exception {
JsonFactory factory = newFactory();
JsonParser parser;
@@ -891,8 +999,13 @@ public void testParser_stringArray() throws Exception {
assertTrue(Arrays.equals(new String[] {"a", "b", "c"}, result));
}
- static final String INT_ARRAY = "[1,2,3]";
+ static final String INT_ARRAY;
+
+ static {
+ INT_ARRAY = "[1,2,3]";
+ }
+ @Test
public void testParser_intArray() throws Exception {
JsonFactory factory = newFactory();
JsonParser parser;
@@ -904,8 +1017,13 @@ public void testParser_intArray() throws Exception {
assertTrue(Arrays.equals(new int[] {1, 2, 3}, result));
}
- private static final String EMPTY_ARRAY = "[]";
+ private static final String EMPTY_ARRAY;
+ static {
+ EMPTY_ARRAY = "[]";
+ }
+
+ @Test
public void testParser_emptyArray() throws Exception {
JsonFactory factory = newFactory();
String[] result = factory.createJsonParser(EMPTY_ARRAY).parse(String[].class);
@@ -914,6 +1032,7 @@ public void testParser_emptyArray() throws Exception {
assertEquals(0, result.length);
}
+ @Test
public void testParser_partialEmptyArray() throws Exception {
JsonFactory factory = newFactory();
JsonParser parser;
@@ -927,8 +1046,13 @@ public void testParser_partialEmptyArray() throws Exception {
assertEquals(0, result.length);
}
- private static final String NUMBER_TOP_VALUE = "1";
+ private static final String NUMBER_TOP_VALUE;
+ static {
+ NUMBER_TOP_VALUE = "1";
+ }
+
+ @Test
public void testParser_num() throws Exception {
JsonFactory factory = newFactory();
int result = factory.createJsonParser(NUMBER_TOP_VALUE).parse(int.class);
@@ -937,8 +1061,13 @@ public void testParser_num() throws Exception {
assertEquals(1, result);
}
- private static final String STRING_TOP_VALUE = "\"a\"";
+ private static final String STRING_TOP_VALUE;
+
+ static {
+ STRING_TOP_VALUE = "\"a\"";
+ }
+ @Test
public void testParser_string() throws Exception {
JsonFactory factory = newFactory();
String result = factory.createJsonParser(STRING_TOP_VALUE).parse(String.class);
@@ -947,8 +1076,13 @@ public void testParser_string() throws Exception {
assertEquals("a", result);
}
- private static final String NULL_TOP_VALUE = "null";
+ private static final String NULL_TOP_VALUE;
+ static {
+ NULL_TOP_VALUE = "null";
+ }
+
+ @Test
public void testParser_null() throws Exception {
JsonFactory factory = newFactory();
String result = factory.createJsonParser(NULL_TOP_VALUE).parse(String.class);
@@ -957,8 +1091,13 @@ public void testParser_null() throws Exception {
assertTrue(Data.isNull(result));
}
- private static final String BOOL_TOP_VALUE = "true";
+ private static final String BOOL_TOP_VALUE;
+
+ static {
+ BOOL_TOP_VALUE = "true";
+ }
+ @Test
public void testParser_bool() throws Exception {
JsonFactory factory = newFactory();
boolean result = factory.createJsonParser(BOOL_TOP_VALUE).parse(boolean.class);
@@ -1040,6 +1179,7 @@ public final void testToPrettyString_FeedApproximate() throws Exception {
assertEquals(JSON_FEED, factory.toString(factory.fromString(prettyString, Feed.class)));
}
+ @Test
public void testParser_nullInputStream() throws Exception {
try {
newFactory().createJsonParser((InputStream) null, Charsets.UTF_8);
@@ -1049,6 +1189,7 @@ public void testParser_nullInputStream() throws Exception {
}
}
+ @Test
public void testParser_nullString() throws Exception {
try {
newFactory().createJsonParser((String) null);
@@ -1058,6 +1199,7 @@ public void testParser_nullString() throws Exception {
}
}
+ @Test
public void testParser_nullReader() throws Exception {
try {
newFactory().createJsonParser((Reader) null);
@@ -1067,6 +1209,7 @@ public void testParser_nullReader() throws Exception {
}
}
+ @Test
public void testObjectParserParse_entry() throws Exception {
@SuppressWarnings("serial")
Entry entry =
@@ -1077,6 +1220,7 @@ public void testObjectParserParse_entry() throws Exception {
assertEquals("foo", entry.title);
}
+ @Test
public void testObjectParserParse_stringList() throws Exception {
JsonFactory factory = newFactory();
@SuppressWarnings({"unchecked", "serial"})
@@ -1092,6 +1236,7 @@ public void testObjectParserParse_stringList() throws Exception {
assertTrue(ImmutableList.of("a", "b", "c").equals(result));
}
+ @Test
public void testToString_withFactory() {
GenericJson data = new GenericJson();
data.put("a", "b");
@@ -1099,6 +1244,7 @@ public void testToString_withFactory() {
assertEquals("{\"a\":\"b\"}", data.toString());
}
+ @Test
public void testFactory() {
JsonFactory factory = newFactory();
GenericJson data = new GenericJson();
@@ -1111,6 +1257,7 @@ private JsonParser createParser(String json) throws Exception {
return newFactory().createJsonParser(json);
}
+ @Test
public void testSkipToKey_firstKey() throws Exception {
JsonParser parser = createParser(JSON_THREE_ELEMENTS);
assertEquals("one", parser.skipToKey(ImmutableSet.of("one")));
@@ -1118,6 +1265,7 @@ public void testSkipToKey_firstKey() throws Exception {
assertEquals(1, parser.getIntValue());
}
+ @Test
public void testSkipToKey_lastKey() throws Exception {
JsonParser parser = createParser(JSON_THREE_ELEMENTS);
assertEquals("three", parser.skipToKey(ImmutableSet.of("three")));
@@ -1125,6 +1273,7 @@ public void testSkipToKey_lastKey() throws Exception {
assertEquals(3, parser.getIntValue());
}
+ @Test
public void testSkipToKey_multipleKeys() throws Exception {
JsonParser parser = createParser(JSON_THREE_ELEMENTS);
assertEquals("two", parser.skipToKey(ImmutableSet.of("foo", "three", "two")));
@@ -1132,6 +1281,7 @@ public void testSkipToKey_multipleKeys() throws Exception {
assertEquals(2, parser.getIntValue());
}
+ @Test
public void testSkipToKey_noMatch() throws Exception {
JsonParser parser = createParser(JSON_THREE_ELEMENTS);
assertEquals(null, parser.skipToKey(ImmutableSet.of("foo", "bar", "num")));
@@ -1220,8 +1370,13 @@ public ExtendsGenericJson set(String fieldName, Object value) {
}
}
- static final String EXTENDS_JSON = "{\"numAsString\":\"1\",\"num\":1}";
+ static final String EXTENDS_JSON;
+ static {
+ EXTENDS_JSON = "{\"numAsString\":\"1\",\"num\":1}";
+ }
+
+ @Test
public void testParser_extendsGenericJson() throws Exception {
JsonFactory factory = newFactory();
JsonParser parser;
@@ -1236,9 +1391,15 @@ public static class Simple {
@Key String a;
}
- static final String SIMPLE = "{\"a\":\"b\"}";
- static final String SIMPLE_WRAPPED = "{\"d\":{\"a\":\"b\"}}";
+ static final String SIMPLE;
+ static final String SIMPLE_WRAPPED;
+
+ static {
+ SIMPLE = "{\"a\":\"b\"}";
+ SIMPLE_WRAPPED = "{\"d\":{\"a\":\"b\"}}";
+ }
+ @Test
public void testJsonObjectParser_reader() throws Exception {
JsonFactory factory = newFactory();
JsonObjectParser parser = new JsonObjectParser(factory);
@@ -1246,6 +1407,7 @@ public void testJsonObjectParser_reader() throws Exception {
assertEquals("b", simple.a);
}
+ @Test
public void testJsonObjectParser_inputStream() throws Exception {
JsonFactory factory = newFactory();
JsonObjectParser parser = new JsonObjectParser(factory);
@@ -1257,6 +1419,7 @@ public void testJsonObjectParser_inputStream() throws Exception {
assertEquals("b", simple.a);
}
+ @Test
public void testJsonObjectParser_readerWrapped() throws Exception {
JsonFactory factory = newFactory();
JsonObjectParser parser =
@@ -1265,6 +1428,7 @@ public void testJsonObjectParser_readerWrapped() throws Exception {
assertEquals("b", simple.a);
}
+ @Test
public void testJsonObjectParser_inputStreamWrapped() throws Exception {
JsonFactory factory = newFactory();
JsonObjectParser parser =
@@ -1277,6 +1441,7 @@ public void testJsonObjectParser_inputStreamWrapped() throws Exception {
assertEquals("b", simple.a);
}
+ @Test
public void testJsonHttpContent_simple() throws Exception {
JsonFactory factory = newFactory();
Simple simple = new Simple();
@@ -1287,6 +1452,7 @@ public void testJsonHttpContent_simple() throws Exception {
assertEquals(SIMPLE, out.toString("UTF-8"));
}
+ @Test
public void testJsonHttpContent_wrapped() throws Exception {
JsonFactory factory = newFactory();
Simple simple = new Simple();
@@ -1302,6 +1468,7 @@ public static class V {
@Key String s;
}
+ @Test
public void testParse_void() throws Exception {
subtestParse_void(null);
subtestParse_void("\"a\"");
@@ -1328,14 +1495,25 @@ public static class BooleanTypes {
@Key boolean bool;
}
- public static final String BOOLEAN_TYPE_EMPTY = "{}";
- public static final String BOOLEAN_TYPE_EMPTY_OUTPUT = "{\"bool\":false}";
- public static final String BOOLEAN_TYPE_TRUE = "{\"bool\":true,\"boolObj\":true}";
- public static final String BOOLEAN_TYPE_FALSE = "{\"bool\":false,\"boolObj\":false}";
- public static final String BOOLEAN_TYPE_NULL = "{\"boolObj\":null}";
- public static final String BOOLEAN_TYPE_NULL_OUTPUT = "{\"bool\":false,\"boolObj\":null}";
- public static final String BOOLEAN_TYPE_WRONG = "{\"boolObj\":{}}";
+ public static final String BOOLEAN_TYPE_EMPTY;
+ public static final String BOOLEAN_TYPE_EMPTY_OUTPUT;
+ public static final String BOOLEAN_TYPE_TRUE;
+ public static final String BOOLEAN_TYPE_FALSE;
+ public static final String BOOLEAN_TYPE_NULL;
+ public static final String BOOLEAN_TYPE_NULL_OUTPUT;
+ public static final String BOOLEAN_TYPE_WRONG;
+
+ static {
+ BOOLEAN_TYPE_EMPTY = "{}";
+ BOOLEAN_TYPE_EMPTY_OUTPUT = "{\"bool\":false}";
+ BOOLEAN_TYPE_TRUE = "{\"bool\":true,\"boolObj\":true}";
+ BOOLEAN_TYPE_FALSE = "{\"bool\":false,\"boolObj\":false}";
+ BOOLEAN_TYPE_NULL = "{\"boolObj\":null}";
+ BOOLEAN_TYPE_NULL_OUTPUT = "{\"bool\":false,\"boolObj\":null}";
+ BOOLEAN_TYPE_WRONG = "{\"boolObj\":{}}";
+ }
+ @Test
public void testParse_boolean() throws Exception {
JsonFactory factory = newFactory();
BooleanTypes parsed;
@@ -1414,6 +1592,7 @@ public static class Centipede extends Animal {
"{\"unused\":0, \"bodyColor\":\"green\",\"name\":\"Mr. Icky\",\"legCount\":68,\"type\":"
+ "\"bug\"}";
+ @Test
public void testParser_heterogeneousSchemata() throws Exception {
testParser_heterogeneousSchemata_Helper(DOG, CENTIPEDE);
// TODO(ngmiceli): Test that this uses the optimized flow (once implemented)
@@ -1451,6 +1630,7 @@ private void testParser_heterogeneousSchemata_Helper(String dogJson, String cent
public static final String ANIMAL_WITHOUT_TYPE = "{\"legCount\":3,\"name\":\"Confused\"}";
+ @Test
public void testParser_heterogeneousSchema_missingType() throws Exception {
JsonFactory factory = newFactory();
JsonParser parser;
@@ -1471,6 +1651,7 @@ public static class Human extends Animal {
public static final String HUMAN =
"{\"bestFriend\":" + DOG + ",\"legCount\":2,\"name\":\"Joe\",\"type\":\"human\"}";
+ @Test
public void testParser_heterogeneousSchema_withObject() throws Exception {
JsonFactory factory = newFactory();
JsonParser parser = factory.createJsonParser(HUMAN);
@@ -1508,6 +1689,7 @@ public static class DogGenericJson extends AnimalGenericJson {
+ "\"unusedInfo\":\"this is not being used!\",\"unused\":{\"foo\":200}}";
@SuppressWarnings("unchecked")
+ @Test
public void testParser_heterogeneousSchema_genericJson() throws Exception {
JsonFactory factory = newFactory();
JsonParser parser = factory.createJsonParser(DOG_EXTRA_INFO);
@@ -1536,6 +1718,7 @@ public static class DogWithFamily extends Dog {
@Key public Animal[] children;
}
+ @Test
public void testParser_heterogeneousSchema_withArrays() throws Exception {
JsonFactory factory = newFactory();
JsonParser parser = factory.createJsonParser(DOG_WITH_FAMILY);
@@ -1560,6 +1743,7 @@ public void testParser_heterogeneousSchema_withArrays() throws Exception {
public static final String DOG_WITH_NO_FAMILY_PARSED =
"{\"legCount\":4,\"tricksKnown\":0,\"type\":\"dogwithfamily\"}";
+ @Test
public void testParser_heterogeneousSchema_withNullArrays() throws Exception {
JsonFactory factory = newFactory();
JsonParser parser = factory.createJsonParser(DOG_WITH_NO_FAMILY);
@@ -1590,6 +1774,7 @@ public static class PolymorphicWithMultipleAnnotations {
public static final String MULTIPLE_ANNOTATIONS_JSON =
"{\"a\":\"foo\",\"b\":\"dog\",\"c\":\"bar\",\"d\":\"bug\"}";
+ @Test
public void testParser_polymorphicClass_tooManyAnnotations() throws Exception {
JsonFactory factory = newFactory();
JsonParser parser = factory.createJsonParser(MULTIPLE_ANNOTATIONS_JSON);
@@ -1620,6 +1805,7 @@ public static class NumericTypedSubclass2 extends PolymorphicWithNumericType {}
public static final String POLYMORPHIC_NUMERIC_TYPE_1 = "{\"foo\":\"bar\",\"type\":1}";
public static final String POLYMORPHIC_NUMERIC_TYPE_2 = "{\"foo\":\"bar\",\"type\":2}";
+ @Test
public void testParser_heterogeneousSchema_numericType() throws Exception {
JsonFactory factory = newFactory();
JsonParser parser = factory.createJsonParser(POLYMORPHIC_NUMERIC_TYPE_1);
@@ -1648,6 +1834,7 @@ public static class NumericValueTypedSubclass2 extends PolymorphicWithNumericVal
public static final String POLYMORPHIC_NUMERIC_UNSPECIFIED_TYPE = "{\"foo\":\"bar\"}";
+ @Test
public void testParser_heterogeneousSchema_numericValueType() throws Exception {
JsonFactory factory = newFactory();
JsonParser parser = factory.createJsonParser(POLYMORPHIC_NUMERIC_TYPE_1);
@@ -1679,6 +1866,7 @@ public static class PolymorphicWithIllegalValueType {
Object type;
}
+ @Test
public void testParser_heterogeneousSchema_illegalValueType() throws Exception {
JsonFactory factory = newFactory();
JsonParser parser = factory.createJsonParser(POLYMORPHIC_NUMERIC_TYPE_1);
@@ -1700,6 +1888,7 @@ public static class PolymorphicWithDuplicateTypeKeys {
String type;
}
+ @Test
public void testParser_polymorphicClass_duplicateTypeKeys() throws Exception {
JsonFactory factory = newFactory();
JsonParser parser = factory.createJsonParser(EMPTY_OBJECT);
@@ -1714,6 +1903,7 @@ public void testParser_polymorphicClass_duplicateTypeKeys() throws Exception {
public static final String POLYMORPHIC_WITH_UNKNOWN_KEY =
"{\"legCount\":4,\"name\":\"Fido\",\"tricksKnown\":3,\"type\":\"unknown\"}";
+ @Test
public void testParser_polymorphicClass_noMatchingTypeKey() throws Exception {
JsonFactory factory = newFactory();
JsonParser parser = factory.createJsonParser(POLYMORPHIC_WITH_UNKNOWN_KEY);
@@ -1736,6 +1926,7 @@ public static class PolymorphicSelfReferencing {
public static final String POLYMORPHIC_SELF_REFERENCING = "{\"info\":\"blah\",\"type\":\"self\"}";
+ @Test
public void testParser_polymorphicClass_selfReferencing() throws Exception {
JsonFactory factory = newFactory();
JsonParser parser = factory.createJsonParser(POLYMORPHIC_SELF_REFERENCING);
@@ -1765,6 +1956,7 @@ public static class HumanWithPets extends Human {
+ ",\"second\":{\"legCount\":0,\"tricksKnown\":0,\"type\":\"dog\"}},"
+ "\"type\":\"human with pets\"}";
+ @Test
public void testParser_polymorphicClass_mapOfPolymorphicClasses() throws Exception {
JsonFactory factory = newFactory();
JsonParser parser = factory.createJsonParser(HUMAN_WITH_PETS);
diff --git a/google-http-client-test/src/main/java/com/google/api/client/test/json/AbstractJsonGeneratorTest.java b/google-http-client-test/src/main/java/com/google/api/client/test/json/AbstractJsonGeneratorTest.java
index 1a2a1bb54..96db2b1f5 100644
--- a/google-http-client-test/src/main/java/com/google/api/client/test/json/AbstractJsonGeneratorTest.java
+++ b/google-http-client-test/src/main/java/com/google/api/client/test/json/AbstractJsonGeneratorTest.java
@@ -14,6 +14,8 @@
package com.google.api.client.test.json;
+import static org.junit.Assert.assertEquals;
+
import com.google.api.client.json.JsonGenerator;
import java.io.IOException;
import java.io.StringWriter;
@@ -21,9 +23,12 @@
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
-import junit.framework.TestCase;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
-public abstract class AbstractJsonGeneratorTest extends TestCase {
+@RunWith(JUnit4.class)
+public abstract class AbstractJsonGeneratorTest {
protected abstract JsonGenerator newGenerator(Writer writer) throws IOException;
@@ -34,6 +39,7 @@ public Iterator> iterator() {
}
}
+ @Test
public void testSerialize_simpleMap() throws Exception {
StringWriter writer = new StringWriter();
JsonGenerator generator = newGenerator(writer);
@@ -46,6 +52,7 @@ public void testSerialize_simpleMap() throws Exception {
assertEquals("{\"a\":\"b\"}", writer.toString());
}
+ @Test
public void testSerialize_iterableMap() throws Exception {
StringWriter writer = new StringWriter();
JsonGenerator generator = newGenerator(writer);
diff --git a/google-http-client-test/src/main/java/com/google/api/client/test/json/AbstractJsonParserTest.java b/google-http-client-test/src/main/java/com/google/api/client/test/json/AbstractJsonParserTest.java
index 985637aea..25bb77bb4 100644
--- a/google-http-client-test/src/main/java/com/google/api/client/test/json/AbstractJsonParserTest.java
+++ b/google-http-client-test/src/main/java/com/google/api/client/test/json/AbstractJsonParserTest.java
@@ -13,6 +13,10 @@
*/
package com.google.api.client.test.json;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
import com.google.api.client.json.GenericJson;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.JsonObjectParser;
@@ -21,17 +25,25 @@
import java.io.InputStream;
import java.math.BigDecimal;
import java.nio.charset.StandardCharsets;
-import junit.framework.TestCase;
import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
-public abstract class AbstractJsonParserTest extends TestCase {
+@RunWith(JUnit4.class)
+public abstract class AbstractJsonParserTest {
protected abstract JsonFactory newJsonFactory();
- private static final String TEST_JSON =
- "{\"strValue\": \"bar\", \"intValue\": 123, \"boolValue\": false}";
- private static final String TEST_JSON_BIG_DECIMAL = "{\"bigDecimalValue\": 1559341956102}";
+ private static final String TEST_JSON;
+ private static final String TEST_JSON_BIG_DECIMAL;
+
+ static {
+ TEST_JSON = "{\"strValue\": \"bar\", \"intValue\": 123, \"boolValue\": false}";
+ TEST_JSON_BIG_DECIMAL = "{\"bigDecimalValue\": 1559341956102}";
+ }
+ @Test
public void testParse_basic() throws IOException {
JsonObjectParser parser = new JsonObjectParser(newJsonFactory());
InputStream inputStream = new ByteArrayInputStream(TEST_JSON.getBytes(StandardCharsets.UTF_8));
@@ -45,6 +57,7 @@ public void testParse_basic() throws IOException {
assertEquals(Boolean.FALSE, json.get("boolValue"));
}
+ @Test
public void testGetWrongType() throws IOException {
JsonObjectParser parser = new JsonObjectParser(newJsonFactory());
InputStream inputStream = new ByteArrayInputStream(TEST_JSON.getBytes(StandardCharsets.UTF_8));
@@ -57,6 +70,7 @@ public void testGetWrongType() throws IOException {
assertEquals(Boolean.FALSE, json.get("boolValue"));
}
+ @Test
public void testParse_badJson() throws IOException {
JsonObjectParser parser = new JsonObjectParser(newJsonFactory());
InputStream inputStream = new ByteArrayInputStream("not json".getBytes(StandardCharsets.UTF_8));
@@ -68,6 +82,7 @@ public void testParse_badJson() throws IOException {
}
}
+ @Test
public void testParse_bigDecimal() throws IOException {
JsonObjectParser parser = new JsonObjectParser(newJsonFactory());
InputStream inputStream =
diff --git a/google-http-client-test/src/main/java/com/google/api/client/test/util/store/AbstractDataStoreFactoryTest.java b/google-http-client-test/src/main/java/com/google/api/client/test/util/store/AbstractDataStoreFactoryTest.java
index e1e8e4061..7a5f464c8 100644
--- a/google-http-client-test/src/main/java/com/google/api/client/test/util/store/AbstractDataStoreFactoryTest.java
+++ b/google-http-client-test/src/main/java/com/google/api/client/test/util/store/AbstractDataStoreFactoryTest.java
@@ -14,6 +14,12 @@
package com.google.api.client.test.util.store;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
import com.google.api.client.util.Beta;
import com.google.api.client.util.store.DataStore;
import com.google.api.client.util.store.DataStoreFactory;
@@ -21,7 +27,11 @@
import java.util.Arrays;
import java.util.Collection;
import java.util.Set;
-import junit.framework.TestCase;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
/**
* Tests {@link DataStoreFactory}.
@@ -29,10 +39,17 @@
* @author Yaniv Inbar
*/
@Beta
-public abstract class AbstractDataStoreFactoryTest extends TestCase {
+@RunWith(JUnit4.class)
+public abstract class AbstractDataStoreFactoryTest {
+
+ private static final String STRING_ID;
+ private static final String BOOLEAN_ID;
+
+ static {
+ STRING_ID = "String";
+ BOOLEAN_ID = "Boolean";
+ }
- private static final String STRING_ID = "String";
- private static final String BOOLEAN_ID = "Boolean";
DataStoreFactory dataStore;
DataStore stringTyped;
DataStore boolTyped;
@@ -40,14 +57,14 @@ public abstract class AbstractDataStoreFactoryTest extends TestCase {
/** Returns a new instance of the data store factory to test. */
protected abstract DataStoreFactory newDataStoreFactory() throws Exception;
- @Override
+ @Before
public void setUp() throws Exception {
dataStore = newDataStoreFactory();
stringTyped = dataStore.getDataStore(STRING_ID);
boolTyped = dataStore.getDataStore(BOOLEAN_ID);
}
- @Override
+ @After
public void tearDown() throws Exception {
stringTyped.clear();
assertTrue(stringTyped.values().isEmpty());
@@ -59,6 +76,7 @@ private static void assertContentsAnyOrder(Collection> c, Object... elts) {
assertEquals(Sets.newHashSet(c), Sets.newHashSet(Arrays.asList(elts)));
}
+ @Test
public void testId() throws Exception {
subtestIdNoException("1");
subtestIdNoException("123456789012345678901234567890");
@@ -83,6 +101,7 @@ private void subtestIdNoException(String id) throws Exception {
newDataStoreFactory().getDataStore(id);
}
+ @Test
public void testSet() throws Exception {
// get null
assertNull(stringTyped.get(null));
@@ -123,6 +142,7 @@ public void testSet() throws Exception {
assertTrue(boolTyped.get("k"));
}
+ @Test
public void testValues() throws Exception {
// before
assertTrue(stringTyped.values().isEmpty());
@@ -144,6 +164,7 @@ public void testValues() throws Exception {
assertContentsAnyOrder(boolTyped.values(), true);
}
+ @Test
public void testKeySet() throws Exception {
// before
assertTrue(stringTyped.keySet().isEmpty());
@@ -164,6 +185,7 @@ public void testKeySet() throws Exception {
assertTrue(stringTyped.keySet().isEmpty());
}
+ @Test
public void testDelete() throws Exception {
// store with basic values
stringTyped.set("k", "v").set("k2", "v2");
@@ -186,6 +208,7 @@ public void testDelete() throws Exception {
assertEquals(0, stringTyped.size());
}
+ @Test
public void testClear() throws Exception {
// store with basic values
stringTyped.set("k", "v").set("k2", "v2");
@@ -199,6 +222,7 @@ public void testClear() throws Exception {
assertEquals(0, stringTyped.size());
}
+ @Test
public void testLarge() throws Exception {
// TODO(yanivi): size = 1000? need to speed up JdoDataStoreTest first
int size = 100;
@@ -210,6 +234,7 @@ public void testLarge() throws Exception {
assertEquals("hello" + mid, stringTyped.get(String.valueOf(mid)));
}
+ @Test
public void testContainsKeyAndValue() throws Exception {
// before
assertFalse(stringTyped.containsKey("k"));
diff --git a/google-http-client-test/src/main/resources/META-INF/native-image/com.google.http-client/google-http-client-test/native-image.properties b/google-http-client-test/src/main/resources/META-INF/native-image/com.google.http-client/google-http-client-test/native-image.properties
new file mode 100644
index 000000000..3cbd2b27f
--- /dev/null
+++ b/google-http-client-test/src/main/resources/META-INF/native-image/com.google.http-client/google-http-client-test/native-image.properties
@@ -0,0 +1 @@
+Args=--initialize-at-build-time=org.junit.runner.RunWith,java.lang.annotation.Annotation
diff --git a/google-http-client-test/src/test/java/com/google/api/client/test/util/store/FileDataStoreFactoryTest.java b/google-http-client-test/src/test/java/com/google/api/client/test/util/store/FileDataStoreFactoryTest.java
index 46918d765..78282861e 100644
--- a/google-http-client-test/src/test/java/com/google/api/client/test/util/store/FileDataStoreFactoryTest.java
+++ b/google-http-client-test/src/test/java/com/google/api/client/test/util/store/FileDataStoreFactoryTest.java
@@ -14,27 +14,35 @@
package com.google.api.client.test.util.store;
+import static java.nio.file.Files.createTempDirectory;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
import com.google.api.client.util.store.DataStore;
import com.google.api.client.util.store.FileDataStoreFactory;
import com.google.common.collect.ImmutableSet;
-import com.google.common.io.Files;
import java.io.File;
import java.io.IOException;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
/**
* Tests {@link FileDataStoreFactory}.
*
* @author Yaniv Inbar
*/
+@RunWith(JUnit4.class)
public class FileDataStoreFactoryTest extends AbstractDataStoreFactoryTest {
@Override
protected FileDataStoreFactory newDataStoreFactory() throws IOException {
- File dataDir = Files.createTempDir();
+ File dataDir = createTempDirectory("temp").toFile();
dataDir.deleteOnExit();
return new FileDataStoreFactory(dataDir);
}
+ @Test
public void testSave() throws IOException {
FileDataStoreFactory factory = newDataStoreFactory();
DataStore store = factory.getDataStore("foo");
diff --git a/google-http-client-test/src/test/java/com/google/api/client/test/util/store/MemoryDataStoreFactoryTest.java b/google-http-client-test/src/test/java/com/google/api/client/test/util/store/MemoryDataStoreFactoryTest.java
index a18384a10..3454f8dba 100644
--- a/google-http-client-test/src/test/java/com/google/api/client/test/util/store/MemoryDataStoreFactoryTest.java
+++ b/google-http-client-test/src/test/java/com/google/api/client/test/util/store/MemoryDataStoreFactoryTest.java
@@ -16,12 +16,15 @@
import com.google.api.client.util.store.DataStoreFactory;
import com.google.api.client.util.store.MemoryDataStoreFactory;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
/**
* Tests {@link MemoryDataStoreFactory}.
*
* @author Yaniv Inbar
*/
+@RunWith(JUnit4.class)
public class MemoryDataStoreFactoryTest extends AbstractDataStoreFactoryTest {
@Override
diff --git a/google-http-client-xml/src/test/java/com/google/api/client/xml/AtomTest.java b/google-http-client-xml/src/test/java/com/google/api/client/xml/AtomTest.java
index f93311d46..b33196b0f 100644
--- a/google-http-client-xml/src/test/java/com/google/api/client/xml/AtomTest.java
+++ b/google-http-client-xml/src/test/java/com/google/api/client/xml/AtomTest.java
@@ -32,6 +32,8 @@
import java.util.List;
import org.junit.Assert;
import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
import org.xmlpull.v1.XmlPullParser;
/**
@@ -40,6 +42,7 @@
* @author Yaniv Inbar
* @author Gerald Madlmayr
*/
+@RunWith(JUnit4.class)
public class AtomTest {
private static final String SAMPLE_FEED =
diff --git a/google-http-client-xml/src/test/java/com/google/api/client/xml/GenericXmlListTest.java b/google-http-client-xml/src/test/java/com/google/api/client/xml/GenericXmlListTest.java
index 0172fccb7..e40f0658d 100644
--- a/google-http-client-xml/src/test/java/com/google/api/client/xml/GenericXmlListTest.java
+++ b/google-http-client-xml/src/test/java/com/google/api/client/xml/GenericXmlListTest.java
@@ -24,6 +24,8 @@
import java.util.ArrayList;
import java.util.Collection;
import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlSerializer;
@@ -35,6 +37,7 @@
*
* @author Gerald Madlmayr
*/
+@RunWith(JUnit4.class)
public class GenericXmlListTest {
private static final String MULTI_TYPE_WITH_CLASS_TYPE =
diff --git a/google-http-client-xml/src/test/java/com/google/api/client/xml/GenericXmlTest.java b/google-http-client-xml/src/test/java/com/google/api/client/xml/GenericXmlTest.java
index 02a85cfa9..abc083fcc 100644
--- a/google-http-client-xml/src/test/java/com/google/api/client/xml/GenericXmlTest.java
+++ b/google-http-client-xml/src/test/java/com/google/api/client/xml/GenericXmlTest.java
@@ -28,6 +28,8 @@
import java.util.List;
import java.util.Map;
import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlSerializer;
@@ -41,6 +43,7 @@
* @author Yaniv Inbar
* @author Gerald Madlmayr
*/
+@RunWith(JUnit4.class)
public class GenericXmlTest {
private static final String XML =
diff --git a/google-http-client-xml/src/test/java/com/google/api/client/xml/XmlEnumTest.java b/google-http-client-xml/src/test/java/com/google/api/client/xml/XmlEnumTest.java
index 7cb908d62..b199cb2db 100644
--- a/google-http-client-xml/src/test/java/com/google/api/client/xml/XmlEnumTest.java
+++ b/google-http-client-xml/src/test/java/com/google/api/client/xml/XmlEnumTest.java
@@ -25,6 +25,8 @@
import java.io.StringReader;
import java.util.ArrayList;
import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlSerializer;
@@ -33,6 +35,7 @@
*
* @author Gerald Madlmayr
*/
+@RunWith(JUnit4.class)
public class XmlEnumTest {
private static final String XML =
diff --git a/google-http-client-xml/src/test/java/com/google/api/client/xml/XmlListTest.java b/google-http-client-xml/src/test/java/com/google/api/client/xml/XmlListTest.java
index 930d0de86..c12904faa 100644
--- a/google-http-client-xml/src/test/java/com/google/api/client/xml/XmlListTest.java
+++ b/google-http-client-xml/src/test/java/com/google/api/client/xml/XmlListTest.java
@@ -24,6 +24,8 @@
import java.util.ArrayList;
import java.util.Collection;
import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlSerializer;
@@ -32,6 +34,7 @@
*
* @author Gerald Madlmayr
*/
+@RunWith(JUnit4.class)
public class XmlListTest {
private static final String MULTI_TYPE_WITH_CLASS_TYPE =
diff --git a/google-http-client-xml/src/test/java/com/google/api/client/xml/XmlNamespaceDictionaryTest.java b/google-http-client-xml/src/test/java/com/google/api/client/xml/XmlNamespaceDictionaryTest.java
index 569477010..562bdb224 100644
--- a/google-http-client-xml/src/test/java/com/google/api/client/xml/XmlNamespaceDictionaryTest.java
+++ b/google-http-client-xml/src/test/java/com/google/api/client/xml/XmlNamespaceDictionaryTest.java
@@ -14,13 +14,20 @@
package com.google.api.client.xml;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
import com.google.api.client.util.Key;
import com.google.api.client.xml.atom.Atom;
import com.google.common.collect.ImmutableMap;
import java.io.StringWriter;
import java.util.Collection;
import java.util.TreeSet;
-import junit.framework.TestCase;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
import org.xmlpull.v1.XmlSerializer;
/**
@@ -28,7 +35,8 @@
*
* @author Yaniv Inbar
*/
-public class XmlNamespaceDictionaryTest extends TestCase {
+@RunWith(JUnit4.class)
+public class XmlNamespaceDictionaryTest {
private static final String EXPECTED =
"One"
+ "Two";
- public XmlNamespaceDictionaryTest() {}
-
- public XmlNamespaceDictionaryTest(String name) {
- super(name);
- }
-
+ @Test
public void testSet() {
XmlNamespaceDictionary dictionary = new XmlNamespaceDictionary();
dictionary.set("", "http://www.w3.org/2005/Atom").set("gd", "http://schemas.google.com/g/2005");
@@ -78,6 +81,7 @@ public void testSet() {
assertTrue(dictionary.getAliasToUriMap().isEmpty());
}
+ @Test
public void testSerialize() throws Exception {
Feed feed = new Feed();
feed.entries = new TreeSet();
@@ -93,6 +97,7 @@ public void testSerialize() throws Exception {
assertEquals(EXPECTED, writer.toString());
}
+ @Test
public void testSerializeByName() throws Exception {
Feed feed = new Feed();
feed.entries = new TreeSet();
@@ -108,6 +113,7 @@ public void testSerializeByName() throws Exception {
assertEquals(EXPECTED, writer.toString());
}
+ @Test
public void testSerialize_emptyMap() throws Exception {
ImmutableMap map = ImmutableMap.of();
StringWriter writer = new StringWriter();
@@ -119,6 +125,7 @@ public void testSerialize_emptyMap() throws Exception {
assertEquals(EXPECTED_EMPTY_MAP, writer.toString());
}
+ @Test
public void testSerializeByName_emptyMap() throws Exception {
ImmutableMap map = ImmutableMap.of();
StringWriter writer = new StringWriter();
@@ -130,6 +137,7 @@ public void testSerializeByName_emptyMap() throws Exception {
assertEquals(EXPECTED_EMPTY_MAP, writer.toString());
}
+ @Test
public void testSerializeByName_emptyMapAtomNs() throws Exception {
ImmutableMap map = ImmutableMap.of();
StringWriter writer = new StringWriter();
@@ -141,6 +149,7 @@ public void testSerializeByName_emptyMapAtomNs() throws Exception {
assertEquals(EXPECTED_EMPTY_MAP_ATOM_NS, writer.toString());
}
+ @Test
public void testSerialize_emptyMapNsUndeclared() throws Exception {
ImmutableMap map = ImmutableMap.of();
StringWriter writer = new StringWriter();
@@ -151,6 +160,7 @@ public void testSerialize_emptyMapNsUndeclared() throws Exception {
assertEquals(EXPECTED_EMPTY_MAP_NS_UNDECLARED, writer.toString());
}
+ @Test
public void testSerialize_errorOnUnknown() throws Exception {
Entry entry = new Entry("One", "abc");
StringWriter writer = new StringWriter();
@@ -166,6 +176,7 @@ public void testSerialize_errorOnUnknown() throws Exception {
}
}
+ @Test
public void testSerializeByName_errorOnUnknown() throws Exception {
Entry entry = new Entry("One", "abc");
StringWriter writer = new StringWriter();
@@ -181,6 +192,7 @@ public void testSerializeByName_errorOnUnknown() throws Exception {
}
}
+ @Test
public void testSerialize_unknown() throws Exception {
Feed feed = new Feed();
feed.entries = new TreeSet();
diff --git a/google-http-client-xml/src/test/java/com/google/api/client/xml/XmlTest.java b/google-http-client-xml/src/test/java/com/google/api/client/xml/XmlTest.java
index b1345f15c..d9a381424 100644
--- a/google-http-client-xml/src/test/java/com/google/api/client/xml/XmlTest.java
+++ b/google-http-client-xml/src/test/java/com/google/api/client/xml/XmlTest.java
@@ -28,6 +28,8 @@
import java.util.Collection;
import java.util.List;
import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlSerializer;
@@ -37,6 +39,7 @@
* @author Yaniv Inbar
* @author Gerald Madlmayr
*/
+@RunWith(JUnit4.class)
public class XmlTest {
private static final String SIMPLE_XML = "test";
diff --git a/google-http-client-xml/src/test/resources/META-INF/native-image/com.google.http-client/google-http-client-xml/native-image.properties b/google-http-client-xml/src/test/resources/META-INF/native-image/com.google.http-client/google-http-client-xml/native-image.properties
new file mode 100644
index 000000000..3cbd2b27f
--- /dev/null
+++ b/google-http-client-xml/src/test/resources/META-INF/native-image/com.google.http-client/google-http-client-xml/native-image.properties
@@ -0,0 +1 @@
+Args=--initialize-at-build-time=org.junit.runner.RunWith,java.lang.annotation.Annotation
diff --git a/google-http-client/src/main/java/com/google/api/client/util/store/AbstractDataStoreFactory.java b/google-http-client/src/main/java/com/google/api/client/util/store/AbstractDataStoreFactory.java
index 0136e5a32..d70de7d43 100644
--- a/google-http-client/src/main/java/com/google/api/client/util/store/AbstractDataStoreFactory.java
+++ b/google-http-client/src/main/java/com/google/api/client/util/store/AbstractDataStoreFactory.java
@@ -14,13 +14,15 @@
package com.google.api.client.util.store;
+import static com.google.api.client.util.Preconditions.checkArgument;
+
import com.google.api.client.util.Maps;
-import com.google.api.client.util.Preconditions;
import java.io.IOException;
import java.io.Serializable;
import java.util.Map;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
+import java.util.logging.Logger;
import java.util.regex.Pattern;
/**
@@ -41,11 +43,19 @@ public abstract class AbstractDataStoreFactory implements DataStoreFactory {
* Pattern to control possible values for the {@code id} parameter of {@link
* #getDataStore(String)}.
*/
- private static final Pattern ID_PATTERN = Pattern.compile("\\w{1,30}");
+ private static final Pattern ID_PATTERN;
+
+ static {
+ try {
+ ID_PATTERN = Pattern.compile("\\w{1,30}");
+ } catch (Throwable t) {
+ Logger.getLogger(AbstractDataStoreFactory.class.getName()).severe(t.getMessage());
+ throw t;
+ }
+ }
public final DataStore getDataStore(String id) throws IOException {
- Preconditions.checkArgument(
- ID_PATTERN.matcher(id).matches(), "%s does not match pattern %s", id, ID_PATTERN);
+ checkArgument(ID_PATTERN.matcher(id).matches(), "%s does not match pattern %s", id, ID_PATTERN);
lock.lock();
try {
@SuppressWarnings("unchecked")
diff --git a/google-http-client/src/main/java/com/google/api/client/util/store/FileDataStoreFactory.java b/google-http-client/src/main/java/com/google/api/client/util/store/FileDataStoreFactory.java
index 98c5003ef..16b33b093 100644
--- a/google-http-client/src/main/java/com/google/api/client/util/store/FileDataStoreFactory.java
+++ b/google-http-client/src/main/java/com/google/api/client/util/store/FileDataStoreFactory.java
@@ -37,6 +37,7 @@
import java.util.HashSet;
import java.util.Locale;
import java.util.Set;
+import java.util.logging.Logger;
/**
* Thread-safe file implementation of a credential store.
@@ -54,8 +55,17 @@
*/
public class FileDataStoreFactory extends AbstractDataStoreFactory {
- private static final boolean IS_WINDOWS =
- StandardSystemProperty.OS_NAME.value().toLowerCase(Locale.ENGLISH).startsWith("windows");
+ private static final boolean IS_WINDOWS;
+
+ static {
+ try {
+ IS_WINDOWS =
+ StandardSystemProperty.OS_NAME.value().toLowerCase(Locale.ENGLISH).startsWith("windows");
+ } catch (Throwable ex) {
+ Logger.getLogger(FileDataStoreFactory.class.getName()).severe(ex.getMessage());
+ throw ex;
+ }
+ }
/** Directory to store data. */
private final File dataDirectory;
diff --git a/google-http-client/src/test/java/com/google/api/client/http/AbstractHttpContentTest.java b/google-http-client/src/test/java/com/google/api/client/http/AbstractHttpContentTest.java
index 93f3fa963..0d916512e 100644
--- a/google-http-client/src/test/java/com/google/api/client/http/AbstractHttpContentTest.java
+++ b/google-http-client/src/test/java/com/google/api/client/http/AbstractHttpContentTest.java
@@ -14,17 +14,23 @@
package com.google.api.client.http;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
import java.io.IOException;
import java.io.OutputStream;
import java.util.Arrays;
-import junit.framework.TestCase;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
/**
* Tests {@link AbstractHttpContent}.
*
* @author Yaniv Inbar
*/
-public class AbstractHttpContentTest extends TestCase {
+@RunWith(JUnit4.class)
+public class AbstractHttpContentTest {
static class TestHttpContent extends AbstractHttpContent {
@@ -54,11 +60,13 @@ public boolean retrySupported() {
}
}
+ @Test
public void testRetrySupported() {
AbstractHttpContent content = new TestHttpContent(true, 0);
assertTrue(content.retrySupported());
}
+ @Test
public void testComputeLength() throws Exception {
subtestComputeLength(true, 0, 0);
subtestComputeLength(true, 1, 1);
diff --git a/google-http-client/src/test/java/com/google/api/client/http/BasicAuthenticationTest.java b/google-http-client/src/test/java/com/google/api/client/http/BasicAuthenticationTest.java
index a76081275..be7e3dd83 100644
--- a/google-http-client/src/test/java/com/google/api/client/http/BasicAuthenticationTest.java
+++ b/google-http-client/src/test/java/com/google/api/client/http/BasicAuthenticationTest.java
@@ -14,16 +14,21 @@
package com.google.api.client.http;
+import static org.junit.Assert.assertEquals;
+
import com.google.api.client.testing.http.HttpTesting;
import com.google.api.client.testing.http.MockHttpTransport;
-import junit.framework.TestCase;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
/**
* Tests {@link BasicAuthentication}.
*
* @author Yaniv Inbar
*/
-public class BasicAuthenticationTest extends TestCase {
+@RunWith(JUnit4.class)
+public class BasicAuthenticationTest {
static final String USERNAME = "Aladdin";
@@ -31,12 +36,14 @@ public class BasicAuthenticationTest extends TestCase {
static final String AUTH_HEADER = "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==";
+ @Test
public void testConstructor() {
BasicAuthentication auth = new BasicAuthentication(USERNAME, PASSWORD);
assertEquals(USERNAME, auth.getUsername());
assertEquals(PASSWORD, auth.getPassword());
}
+ @Test
public void testInitialize() throws Exception {
BasicAuthentication auth = new BasicAuthentication(USERNAME, PASSWORD);
HttpRequest request =
diff --git a/google-http-client/src/test/java/com/google/api/client/http/ByteArrayContentTest.java b/google-http-client/src/test/java/com/google/api/client/http/ByteArrayContentTest.java
index da73c5437..66f28c53d 100644
--- a/google-http-client/src/test/java/com/google/api/client/http/ByteArrayContentTest.java
+++ b/google-http-client/src/test/java/com/google/api/client/http/ByteArrayContentTest.java
@@ -14,20 +14,28 @@
package com.google.api.client.http;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
import com.google.api.client.util.IOUtils;
import com.google.api.client.util.StringUtils;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
-import junit.framework.TestCase;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
/**
* Tests {@link ByteArrayContent}.
*
* @author Yaniv Inbar
*/
-public class ByteArrayContentTest extends TestCase {
+@RunWith(JUnit4.class)
+public class ByteArrayContentTest {
private static final byte[] FOO = StringUtils.getBytesUtf8("foo");
+ @Test
public void testConstructor() throws IOException {
subtestConstructor(new ByteArrayContent("type", FOO), "foo");
subtestConstructor(new ByteArrayContent("type", FOO, 0, 3), "foo");
diff --git a/google-http-client/src/test/java/com/google/api/client/http/ConsumingInputStreamTest.java b/google-http-client/src/test/java/com/google/api/client/http/ConsumingInputStreamTest.java
index afcdf2bf5..d86a1d811 100644
--- a/google-http-client/src/test/java/com/google/api/client/http/ConsumingInputStreamTest.java
+++ b/google-http-client/src/test/java/com/google/api/client/http/ConsumingInputStreamTest.java
@@ -22,7 +22,10 @@
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+@RunWith(JUnit4.class)
public class ConsumingInputStreamTest {
@Test
diff --git a/google-http-client/src/test/java/com/google/api/client/http/EmptyContentTest.java b/google-http-client/src/test/java/com/google/api/client/http/EmptyContentTest.java
index 743fc75e1..06e942a38 100644
--- a/google-http-client/src/test/java/com/google/api/client/http/EmptyContentTest.java
+++ b/google-http-client/src/test/java/com/google/api/client/http/EmptyContentTest.java
@@ -14,17 +14,25 @@
package com.google.api.client.http;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
import java.io.ByteArrayOutputStream;
import java.io.IOException;
-import junit.framework.TestCase;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
/**
* Tests {@link EmptyContent}.
*
* @author Yaniv Inbar
*/
-public class EmptyContentTest extends TestCase {
+@RunWith(JUnit4.class)
+public class EmptyContentTest {
+ @Test
public void test() throws IOException {
EmptyContent content = new EmptyContent();
assertEquals(0L, content.getLength());
diff --git a/google-http-client/src/test/java/com/google/api/client/http/ExponentialBackOffPolicyTest.java b/google-http-client/src/test/java/com/google/api/client/http/ExponentialBackOffPolicyTest.java
index 5a0cb0494..159305d43 100644
--- a/google-http-client/src/test/java/com/google/api/client/http/ExponentialBackOffPolicyTest.java
+++ b/google-http-client/src/test/java/com/google/api/client/http/ExponentialBackOffPolicyTest.java
@@ -14,8 +14,13 @@
package com.google.api.client.http;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
import com.google.api.client.util.NanoClock;
-import junit.framework.TestCase;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
/**
* Tests {@link ExponentialBackOffPolicy}.
@@ -23,12 +28,10 @@
* @author Ravi Mistry
*/
@Deprecated
-public class ExponentialBackOffPolicyTest extends TestCase {
-
- public ExponentialBackOffPolicyTest(String name) {
- super(name);
- }
+@RunWith(JUnit4.class)
+public class ExponentialBackOffPolicyTest {
+ @Test
public void testConstructor() {
ExponentialBackOffPolicy backOffPolicy = new ExponentialBackOffPolicy();
assertEquals(
@@ -39,8 +42,9 @@ public void testConstructor() {
backOffPolicy.getCurrentIntervalMillis());
assertEquals(
ExponentialBackOffPolicy.DEFAULT_RANDOMIZATION_FACTOR,
- backOffPolicy.getRandomizationFactor());
- assertEquals(ExponentialBackOffPolicy.DEFAULT_MULTIPLIER, backOffPolicy.getMultiplier());
+ backOffPolicy.getRandomizationFactor(),
+ 0);
+ assertEquals(ExponentialBackOffPolicy.DEFAULT_MULTIPLIER, backOffPolicy.getMultiplier(), 0);
assertEquals(
ExponentialBackOffPolicy.DEFAULT_MAX_INTERVAL_MILLIS, backOffPolicy.getMaxIntervalMillis());
assertEquals(
@@ -48,6 +52,7 @@ public void testConstructor() {
backOffPolicy.getMaxElapsedTimeMillis());
}
+ @Test
public void testBuilder() {
ExponentialBackOffPolicy backOffPolicy = ExponentialBackOffPolicy.builder().build();
assertEquals(
@@ -58,8 +63,9 @@ public void testBuilder() {
backOffPolicy.getCurrentIntervalMillis());
assertEquals(
ExponentialBackOffPolicy.DEFAULT_RANDOMIZATION_FACTOR,
- backOffPolicy.getRandomizationFactor());
- assertEquals(ExponentialBackOffPolicy.DEFAULT_MULTIPLIER, backOffPolicy.getMultiplier());
+ backOffPolicy.getRandomizationFactor(),
+ 0);
+ assertEquals(ExponentialBackOffPolicy.DEFAULT_MULTIPLIER, backOffPolicy.getMultiplier(), 0);
assertEquals(
ExponentialBackOffPolicy.DEFAULT_MAX_INTERVAL_MILLIS, backOffPolicy.getMaxIntervalMillis());
assertEquals(
@@ -82,12 +88,13 @@ public void testBuilder() {
.build();
assertEquals(testInitialInterval, backOffPolicy.getInitialIntervalMillis());
assertEquals(testInitialInterval, backOffPolicy.getCurrentIntervalMillis());
- assertEquals(testRandomizationFactor, backOffPolicy.getRandomizationFactor());
- assertEquals(testMultiplier, backOffPolicy.getMultiplier());
+ assertEquals(testRandomizationFactor, backOffPolicy.getRandomizationFactor(), 0);
+ assertEquals(testMultiplier, backOffPolicy.getMultiplier(), 0);
assertEquals(testMaxInterval, backOffPolicy.getMaxIntervalMillis());
assertEquals(testMaxElapsedTime, backOffPolicy.getMaxElapsedTimeMillis());
}
+ @Test
public void testBackOff() throws Exception {
int testInitialInterval = 500;
double testRandomizationFactor = 0.1;
@@ -130,6 +137,7 @@ public long nanoTime() {
}
}
+ @Test
public void testGetElapsedTimeMillis() {
ExponentialBackOffPolicy backOffPolicy =
new ExponentialBackOffPolicy.Builder().setNanoClock(new MyNanoClock()).build();
@@ -137,6 +145,7 @@ public void testGetElapsedTimeMillis() {
assertEquals("elapsedTimeMillis=" + elapsedTimeMillis, 1000, elapsedTimeMillis);
}
+ @Test
public void testBackOffOverflow() throws Exception {
int testInitialInterval = Integer.MAX_VALUE / 2;
double testMultiplier = 2.1;
diff --git a/google-http-client/src/test/java/com/google/api/client/http/GZipEncodingTest.java b/google-http-client/src/test/java/com/google/api/client/http/GZipEncodingTest.java
index 4963b05bd..e73edc311 100644
--- a/google-http-client/src/test/java/com/google/api/client/http/GZipEncodingTest.java
+++ b/google-http-client/src/test/java/com/google/api/client/http/GZipEncodingTest.java
@@ -14,19 +14,24 @@
package com.google.api.client.http;
+import static org.junit.Assert.assertFalse;
+
import com.google.api.client.testing.util.TestableByteArrayOutputStream;
import com.google.api.client.util.ByteArrayStreamingContent;
import com.google.api.client.util.StringUtils;
import java.io.IOException;
-import junit.framework.TestCase;
import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
/**
* Tests {@link GZipEncoding}.
*
* @author Yaniv Inbar
*/
-public class GZipEncodingTest extends TestCase {
+@RunWith(JUnit4.class)
+public class GZipEncodingTest {
private static final byte[] EXPECED_ZIPPED =
new byte[] {
@@ -42,6 +47,7 @@ public class GZipEncodingTest extends TestCase {
0, 0, 0, 0, 0, 0, 0, 0
};
+ @Test
public void test() throws IOException {
// TODO: remove when no longer using Java < 16.
byte[] expected =
diff --git a/google-http-client/src/test/java/com/google/api/client/http/GenericUrlTest.java b/google-http-client/src/test/java/com/google/api/client/http/GenericUrlTest.java
index dbe1cc931..1e2dfddf1 100644
--- a/google-http-client/src/test/java/com/google/api/client/http/GenericUrlTest.java
+++ b/google-http-client/src/test/java/com/google/api/client/http/GenericUrlTest.java
@@ -14,6 +14,11 @@
package com.google.api.client.http;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.fail;
+
import com.google.api.client.util.Key;
import java.net.MalformedURLException;
import java.net.URI;
@@ -24,24 +29,21 @@
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
-import junit.framework.TestCase;
-import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
/**
* Tests {@link GenericUrl}.
*
* @author Yaniv Inbar
*/
-public class GenericUrlTest extends TestCase {
-
- public GenericUrlTest() {}
-
- public GenericUrlTest(String name) {
- super(name);
- }
+@RunWith(JUnit4.class)
+public class GenericUrlTest {
private static final String MINIMAL = "http://bar";
+ @Test
public void testBuild_minimal() {
GenericUrl url = new GenericUrl();
url.setScheme("http");
@@ -49,6 +51,7 @@ public void testBuild_minimal() {
assertEquals(MINIMAL, url.build());
}
+ @Test
public void testParse_minimal() {
GenericUrl url = new GenericUrl(MINIMAL);
assertEquals("http", url.getScheme());
@@ -56,6 +59,7 @@ public void testParse_minimal() {
private static final String NO_PATH = "http://bar?a=b";
+ @Test
public void testBuild_noPath() {
GenericUrl url = new GenericUrl();
url.setScheme("http");
@@ -64,11 +68,13 @@ public void testBuild_noPath() {
assertEquals(NO_PATH, url.build());
}
+ @Test
public void testBuild_noUserInfo() {
GenericUrl url = new GenericUrl(NO_PATH);
assertNull(url.getUserInfo());
}
+ @Test
public void testBuild_noScheme() {
GenericUrl url = new GenericUrl();
try {
@@ -79,6 +85,7 @@ public void testBuild_noScheme() {
}
}
+ @Test
public void testBuild_noHost() {
GenericUrl url = new GenericUrl();
try {
@@ -90,6 +97,7 @@ public void testBuild_noHost() {
}
}
+ @Test
public void testParse_noPath() {
GenericUrl url = new GenericUrl(NO_PATH);
assertEquals("http", url.getScheme());
@@ -102,6 +110,7 @@ public void testParse_noPath() {
private static final List SHORT_PATH_PARTS = Arrays.asList("", "path");
+ @Test
public void testBuild_shortPath() {
GenericUrl url = new GenericUrl();
url.setScheme("http");
@@ -111,6 +120,7 @@ public void testBuild_shortPath() {
assertEquals(SHORT_PATH, url.build());
}
+ @Test
public void testParse_shortPath() {
GenericUrl url = new GenericUrl(SHORT_PATH);
assertEquals("http", url.getScheme());
@@ -123,6 +133,7 @@ public void testParse_shortPath() {
private static final List LONG_PATH_PARTS = Arrays.asList("", "path", "to", "resource");
+ @Test
public void testBuild_longPath() {
GenericUrl url = new GenericUrl();
url.setScheme("http");
@@ -132,6 +143,7 @@ public void testBuild_longPath() {
assertEquals(LONG_PATH, url.build());
}
+ @Test
public void testParse_longPath() {
GenericUrl url = new GenericUrl(LONG_PATH);
assertEquals("http", url.getScheme());
@@ -172,6 +184,7 @@ public TestUrl(String encodedUrl, boolean verbatim) {
private static final String USER_INFO = "user:";
private static final String FRAGMENT = "";
+ @Test
public void testBuild_full() {
TestUrl url = new TestUrl();
url.setScheme("https");
@@ -189,6 +202,7 @@ public void testBuild_full() {
assertEquals(FULL, url.build());
}
+ @Test
public void testParse_full() {
TestUrl url = new TestUrl(FULL);
subtestFull(url);
@@ -197,27 +211,32 @@ public void testParse_full() {
assertEquals("bar", url.foo);
}
+ @Test
public void testParse_full_verbatim() {
TestUrl url = new TestUrl(FULL, true);
assertNull(url.hidden);
assertEquals("Go%3D%23/%25%26%20?%3Co%3Egle", url.getFirst("q"));
}
+ @Test
public void testConstructor_url() throws MalformedURLException {
GenericUrl url = new GenericUrl(new URL(FULL));
subtestFull(url);
}
+ @Test
public void testConstructor_uri() throws URISyntaxException {
GenericUrl url = new GenericUrl(new URI(FULL));
subtestFull(url);
}
+ @Test
public void testConstructor_string() {
GenericUrl url = new GenericUrl(FULL);
subtestFull(url);
}
+ @Test
public void testConstructor_schemeToLowerCase() throws URISyntaxException, MalformedURLException {
GenericUrl url = new GenericUrl("HTTps://www.google.com:223");
assertEquals("https", url.getScheme());
@@ -274,6 +293,7 @@ public FieldTypesUrl set(String fieldName, Object value) {
private static final String FIELD_TYPES =
"http://bar?B=true&D=-3.14&I=-3&b=true&d=-3.14&i=-3&s=a&a=b";
+ @Test
public void testBuild_fieldTypes() {
FieldTypesUrl url = new FieldTypesUrl();
url.setScheme("http");
@@ -290,6 +310,7 @@ public void testBuild_fieldTypes() {
assertEquals(FIELD_TYPES, url.build());
}
+ @Test
public void testParse_fieldTypes() {
FieldTypesUrl url = new FieldTypesUrl(FIELD_TYPES);
assertEquals("http", url.getScheme());
@@ -308,6 +329,7 @@ public void testParse_fieldTypes() {
private static final String FRAGMENT1 =
"http://bar/path/to/resource#fragme=%23/%25&%20?%3Co%3Ent";
+ @Test
public void testBuild_fragment1() {
GenericUrl url = new GenericUrl();
url.setScheme("http");
@@ -317,6 +339,7 @@ public void testBuild_fragment1() {
assertEquals(FRAGMENT1, url.build());
}
+ @Test
public void testParse_fragment1() {
GenericUrl url = new GenericUrl(FRAGMENT1);
assertEquals("http", url.getScheme());
@@ -327,6 +350,7 @@ public void testParse_fragment1() {
private static final String FRAGMENT2 = "http://bar/path/to/resource?a=b#fragment";
+ @Test
public void testBuild_fragment2() {
GenericUrl url = new GenericUrl();
url.setScheme("http");
@@ -337,6 +361,7 @@ public void testBuild_fragment2() {
assertEquals(FRAGMENT2, url.build());
}
+ @Test
public void testParse_fragment2() {
GenericUrl url = new GenericUrl(FRAGMENT2);
assertEquals("http", url.getScheme());
@@ -346,6 +371,7 @@ public void testParse_fragment2() {
assertEquals("fragment", url.getFragment());
}
+ @Test
public void testBuildAuthority_exception() {
// Test without a scheme.
GenericUrl url = new GenericUrl();
@@ -353,7 +379,7 @@ public void testBuildAuthority_exception() {
try {
url.buildAuthority();
- Assert.fail("no exception was thrown");
+ fail("no exception was thrown");
} catch (NullPointerException expected) {
}
@@ -363,11 +389,12 @@ public void testBuildAuthority_exception() {
try {
url.buildAuthority();
- Assert.fail("no exception was thrown");
+ fail("no exception was thrown");
} catch (NullPointerException expected) {
}
}
+ @Test
public void testBuildAuthority_simple() {
GenericUrl url = new GenericUrl();
url.setScheme("http");
@@ -375,6 +402,7 @@ public void testBuildAuthority_simple() {
assertEquals("http://example.com", url.buildAuthority());
}
+ @Test
public void testBuildAuthority_withPort() {
GenericUrl url = new GenericUrl();
url.setScheme("http");
@@ -383,6 +411,7 @@ public void testBuildAuthority_withPort() {
assertEquals("http://example.com:1234", url.buildAuthority());
}
+ @Test
public void testBuildAuthority_withUserInfo() {
GenericUrl url = new GenericUrl();
url.setScheme("http");
@@ -391,6 +420,7 @@ public void testBuildAuthority_withUserInfo() {
assertEquals("http://first.last:pa%40%40@www.example.com", url.buildAuthority());
}
+ @Test
public void testBuildRelativeUrl_empty() {
GenericUrl url = new GenericUrl();
url.setScheme("foo");
@@ -399,6 +429,7 @@ public void testBuildRelativeUrl_empty() {
assertEquals("", url.buildRelativeUrl());
}
+ @Test
public void testBuildRelativeUrl_simple() {
GenericUrl url = new GenericUrl();
url.setScheme("foo");
@@ -407,6 +438,7 @@ public void testBuildRelativeUrl_simple() {
assertEquals("/example", url.buildRelativeUrl());
}
+ @Test
public void testBuildRelativeUrl_simpleQuery() {
GenericUrl url = new GenericUrl();
url.setScheme("foo");
@@ -416,6 +448,7 @@ public void testBuildRelativeUrl_simpleQuery() {
assertEquals("/example?key=value", url.buildRelativeUrl());
}
+ @Test
public void testBuildRelativeUrl_fragment() {
GenericUrl url = new GenericUrl();
url.setScheme("foo");
@@ -425,6 +458,7 @@ public void testBuildRelativeUrl_fragment() {
assertEquals("/example#test", url.buildRelativeUrl());
}
+ @Test
public void testBuildRelativeUrl_onlyQuery() {
GenericUrl url = new GenericUrl();
url.setScheme("foo");
@@ -437,6 +471,7 @@ public void testBuildRelativeUrl_onlyQuery() {
private static final String BASE_URL = "http://google.com";
private static final String FULL_PATH = "/some/path/someone%2Fis%2F@gmail.com/test/?one=1&two=2";
+ @Test
public void testBuildRelativeUrl_full() {
GenericUrl url = new GenericUrl(BASE_URL + FULL_PATH);
assertEquals(FULL_PATH, url.buildRelativeUrl());
@@ -448,6 +483,7 @@ public void testBuildRelativeUrl_full() {
private static final List PATH_WITH_SLASH_PARTS =
Arrays.asList("", "m8", "feeds", "contacts", "someone/is/@gmail.com", "full", "");
+ @Test
public void testBuild_pathWithSlash() {
GenericUrl url = new GenericUrl();
url.setScheme("http");
@@ -456,12 +492,14 @@ public void testBuild_pathWithSlash() {
assertEquals(PATH_WITH_SLASH, url.build());
}
+ @Test
public void testConstructorUnderscore() {
String url = "http://url_with_underscore.google.com";
GenericUrl parsed = new GenericUrl(url);
assertEquals("url_with_underscore.google.com", parsed.getHost());
}
+ @Test
public void testParse_pathWithSlash() {
GenericUrl url = new GenericUrl(PATH_WITH_SLASH);
assertEquals("http", url.getScheme());
@@ -469,6 +507,7 @@ public void testParse_pathWithSlash() {
assertEquals(PATH_WITH_SLASH_PARTS, url.getPathParts());
}
+ @Test
public void testToPathParts() {
subtestToPathParts(null, (String[]) null);
subtestToPathParts(null, "");
@@ -493,6 +532,7 @@ private void subtestToPathParts(String encodedPath, String... expectedDecodedPar
}
}
+ @Test
public void testAppendPath() {
GenericUrl url = new GenericUrl("http://google.com");
assertNull(url.getPathParts());
@@ -525,6 +565,7 @@ public void testAppendPath() {
private static final String REPEATED_PARAM = PREFIX + REPEATED_PARAM_PATH + "?q=c&q=a&q=b&s=e";
+ @Test
public void testRepeatedParam_build() {
GenericUrl url = new GenericUrl();
url.setScheme("https");
@@ -535,6 +576,7 @@ public void testRepeatedParam_build() {
assertEquals(REPEATED_PARAM, url.build());
}
+ @Test
public void testRepeatedParam_parse() {
GenericUrl url = new GenericUrl(REPEATED_PARAM);
assertEquals("https", url.getScheme());
@@ -552,6 +594,7 @@ public void testRepeatedParam_parse() {
assertEquals(Arrays.asList("c", "a", "b"), new ArrayList