From dceff5b2ca30101ef6a550a2ccc6c9dc44345df5 Mon Sep 17 00:00:00 2001 From: Mend Renovate Date: Sat, 25 Jan 2025 05:24:48 +0000 Subject: [PATCH 01/51] build(deps): update dependency com.google.cloud:native-image-shared-config to v1.14.0 --- .kokoro/presubmit/graalvm-native-a.cfg | 2 +- .kokoro/presubmit/graalvm-native-b.cfg | 2 +- pom.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) 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/pom.xml b/pom.xml index 7248a69cb..2a1168b5b 100644 --- a/pom.xml +++ b/pom.xml @@ -93,7 +93,7 @@ com.google.cloud native-image-shared-config - 1.13.0 + 1.14.0 + + + + + 4001 + com/google/api/client/test/util/store/AbstractDataStoreFactoryTest + junit/framework/Test + + + + 5001 + com/google/api/client/test/util/store/AbstractDataStoreFactoryTest + junit/framework/Assert + + + + 5001 + com/google/api/client/test/util/store/AbstractDataStoreFactoryTest + junit/framework/TestCase + + From c5f76a1b952778a786585f33641eabe1b9ace9ff Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Thu, 6 Feb 2025 01:03:57 +0000 Subject: [PATCH 34/51] include appengine classes in runtime this allows native compilation --- google-http-client-appengine/pom.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/google-http-client-appengine/pom.xml b/google-http-client-appengine/pom.xml index d7f740df1..9f617d5e7 100644 --- a/google-http-client-appengine/pom.xml +++ b/google-http-client-appengine/pom.xml @@ -72,7 +72,6 @@ com.google.appengine appengine-api-1.0-sdk - provided com.google.appengine From 7e35ed1086768cbeb55968d978d16f34c601103b Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Thu, 6 Feb 2025 01:04:10 +0000 Subject: [PATCH 35/51] add native config --- .../native-image.properties | 1 + .../reflect-config.json | 416 ++++++++++++++++++ 2 files changed, 417 insertions(+) create mode 100644 google-http-client-appengine/src/test/resources/META-INF/native-image/com.google.http-client/google-http-client-appengine/native-image.properties create mode 100644 google-http-client-appengine/src/test/resources/META-INF/native-image/com.google.http-client/google-http-client-appengine/reflect-config.json 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-appengine/src/test/resources/META-INF/native-image/com.google.http-client/google-http-client-appengine/reflect-config.json b/google-http-client-appengine/src/test/resources/META-INF/native-image/com.google.http-client/google-http-client-appengine/reflect-config.json new file mode 100644 index 000000000..aea286ffb --- /dev/null +++ b/google-http-client-appengine/src/test/resources/META-INF/native-image/com.google.http-client/google-http-client-appengine/reflect-config.json @@ -0,0 +1,416 @@ +[ + { + "name": "com.google.api.client.extensions.appengine.datastore.AppEngineDataStoreFactoryTest", + "methods": [ + { + "name": "", + "parameterTypes": [] + } + ] + }, + { + "name": "com.google.api.client.extensions.appengine.datastore.AppEngineNoMemcacheDataStoreFactoryTest", + "methods": [ + { + "name": "", + "parameterTypes": [] + } + ] + }, + { + "name": "com.google.api.client.extensions.appengine.http.UrlFetchTransportTest", + "allDeclaredFields": true, + "methods": [ + { + "name": "", + "parameterTypes": [] + }, + { + "name": "test", + "parameterTypes": [] + } + ] + }, + { + "name": "com.google.api.client.test.util.store.AbstractDataStoreFactoryTest", + "methods": [ + { + "name": "testClear", + "parameterTypes": [] + }, + { + "name": "testContainsKeyAndValue", + "parameterTypes": [] + }, + { + "name": "testDelete", + "parameterTypes": [] + }, + { + "name": "testId", + "parameterTypes": [] + }, + { + "name": "testKeySet", + "parameterTypes": [] + }, + { + "name": "testLarge", + "parameterTypes": [] + }, + { + "name": "testSet", + "parameterTypes": [] + }, + { + "name": "testValues", + "parameterTypes": [] + } + ] + }, + { + "name": "com.google.appengine.api.appidentity.IAppIdentityServiceFactoryProvider" + }, + { + "name": "com.google.appengine.api.appidentity.dev.LocalAppIdentityService" + }, + { + "name": "com.google.appengine.api.backends.IBackendServiceFactoryProvider" + }, + { + "name": "com.google.appengine.api.blobstore.IBlobstoreServiceFactoryProvider" + }, + { + "name": "com.google.appengine.api.blobstore.dev.LocalBlobstoreService" + }, + { + "name": "com.google.appengine.api.capabilities.ICapabilitiesServiceFactoryProvider" + }, + { + "name": "com.google.appengine.api.capabilities.dev.LocalCapabilitiesService" + }, + { + "name": "com.google.appengine.api.datastore.IDatastoreServiceFactoryProvider" + }, + { + "name": "com.google.appengine.api.datastore.dev.LocalDatastoreV3Service", + "methods": [ + { + "name": "delete", + "parameterTypes": [ + "com.google.appengine.tools.development.LocalRpcService$Status", + "com.google.apphosting.api.DatastorePb$DeleteRequest" + ] + }, + { + "name": "get", + "parameterTypes": [ + "com.google.appengine.tools.development.LocalRpcService$Status", + "com.google.apphosting.api.DatastorePb$GetRequest" + ] + }, + { + "name": "next", + "parameterTypes": [ + "com.google.appengine.tools.development.LocalRpcService$Status", + "com.google.apphosting.api.DatastorePb$NextRequest" + ] + }, + { + "name": "put", + "parameterTypes": [ + "com.google.appengine.tools.development.LocalRpcService$Status", + "com.google.apphosting.api.DatastorePb$PutRequest" + ] + }, + { + "name": "runQuery", + "parameterTypes": [ + "com.google.appengine.tools.development.LocalRpcService$Status", + "com.google.apphosting.api.DatastorePb$Query" + ] + } + ] + }, + { + "name": "com.google.appengine.api.datastore.dev.WriteLatencyAdjuster", + "methods": [ + { + "name": "", + "parameterTypes": [] + } + ] + }, + { + "name": "com.google.appengine.api.images.IImagesServiceFactoryProvider" + }, + { + "name": "com.google.appengine.api.images.dev.LocalImagesService" + }, + { + "name": "com.google.appengine.api.log.ILogServiceFactoryProvider" + }, + { + "name": "com.google.appengine.api.log.dev.LocalLogService" + }, + { + "name": "com.google.appengine.api.mail.IMailServiceFactoryProvider" + }, + { + "name": "com.google.appengine.api.mail.dev.LocalMailService" + }, + { + "name": "com.google.appengine.api.memcache.IMemcacheServiceFactoryProvider" + }, + { + "name": "com.google.appengine.api.memcache.MemcacheServicePb$MemcacheDeleteRequest", + "methods": [ + { + "name": "parseFrom", + "parameterTypes": [ + "byte[]" + ] + } + ] + }, + { + "name": "com.google.appengine.api.memcache.MemcacheServicePb$MemcacheFlushRequest", + "methods": [ + { + "name": "parseFrom", + "parameterTypes": [ + "byte[]" + ] + } + ] + }, + { + "name": "com.google.appengine.api.memcache.MemcacheServicePb$MemcacheGetRequest", + "methods": [ + { + "name": "parseFrom", + "parameterTypes": [ + "byte[]" + ] + } + ] + }, + { + "name": "com.google.appengine.api.memcache.MemcacheServicePb$MemcacheSetRequest", + "methods": [ + { + "name": "parseFrom", + "parameterTypes": [ + "byte[]" + ] + } + ] + }, + { + "name": "com.google.appengine.api.memcache.dev.LocalMemcacheService", + "methods": [ + { + "name": "delete", + "parameterTypes": [ + "com.google.appengine.tools.development.LocalRpcService$Status", + "com.google.appengine.api.memcache.MemcacheServicePb$MemcacheDeleteRequest" + ] + }, + { + "name": "flushAll", + "parameterTypes": [ + "com.google.appengine.tools.development.LocalRpcService$Status", + "com.google.appengine.api.memcache.MemcacheServicePb$MemcacheFlushRequest" + ] + }, + { + "name": "get", + "parameterTypes": [ + "com.google.appengine.tools.development.LocalRpcService$Status", + "com.google.appengine.api.memcache.MemcacheServicePb$MemcacheGetRequest" + ] + }, + { + "name": "set", + "parameterTypes": [ + "com.google.appengine.tools.development.LocalRpcService$Status", + "com.google.appengine.api.memcache.MemcacheServicePb$MemcacheSetRequest" + ] + } + ] + }, + { + "name": "com.google.appengine.api.modules.IModulesServiceFactoryProvider" + }, + { + "name": "com.google.appengine.api.oauth.IOAuthServiceFactoryProvider" + }, + { + "name": "com.google.appengine.api.quota.IQuotaServiceFactoryProvider" + }, + { + "name": "com.google.appengine.api.search.ISearchServiceFactoryProvider" + }, + { + "name": "com.google.appengine.api.taskqueue.IQueueFactoryProvider" + }, + { + "name": "com.google.appengine.api.urlfetch.IURLFetchServiceFactoryProvider" + }, + { + "name": "com.google.appengine.api.users.IUserServiceFactoryProvider" + }, + { + "name": "com.google.appengine.repackaged.com.google.protobuf.ExtensionRegistry", + "methods": [ + { + "name": "getEmptyRegistry", + "parameterTypes": [] + } + ] + }, + { + "name": "com.google.appengine.tools.development.DynamicLatencyAdjuster$Default", + "methods": [ + { + "name": "", + "parameterTypes": [] + } + ] + }, + { + "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": [] + } + ] + }, + { + "name": "com.google.storage.onestore.v3.OnestoreEntity$Path", + "fields": [ + { + "name": "element_" + } + ] + }, + { + "name": "com.google.storage.onestore.v3.OnestoreEntity$Path$Element", + "fields": [ + { + "name": "id_" + }, + { + "name": "name_" + }, + { + "name": "optional_0_" + }, + { + "name": "type_" + } + ] + }, + { + "name": "java.lang.Object", + "allDeclaredFields": true + }, + { + "name": "java.nio.Buffer", + "fields": [ + { + "name": "address" + } + ] + }, + { + "name": "java.util.concurrent.atomic.AtomicBoolean", + "fields": [ + { + "name": "value" + } + ] + }, + { + "name": "libcore.io.Memory" + }, + { + "name": "org.apache.maven.surefire.booter.spi.LegacyMasterProcessChannelProcessorFactory" + }, + { + "name": "org.apache.maven.surefire.booter.spi.SurefireMasterProcessChannelProcessorFactory" + }, + { + "name": "org.robolectric.Robolectric" + }, + { + "name": "sun.misc.Unsafe", + "allDeclaredFields": true + }, + { + "name": "sun.security.provider.MD5", + "methods": [ + { + "name": "", + "parameterTypes": [] + } + ] + }, + { + "name": "sun.security.provider.NativePRNG", + "methods": [ + { + "name": "", + "parameterTypes": [ + "java.security.SecureRandomParameters" + ] + } + ] + }, + { + "name": "sun.security.provider.SHA", + "methods": [ + { + "name": "", + "parameterTypes": [] + } + ] + } +] From 8e90738604ebddcbd72e8255927582a8c3ebf9e4 Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Thu, 6 Feb 2025 01:10:06 +0000 Subject: [PATCH 36/51] add reflect-config for appengine --- .../reflect-config.json | 47 ++ .../reflect-config.json | 416 ------------------ 2 files changed, 47 insertions(+), 416 deletions(-) create mode 100644 google-http-client-appengine/src/main/resources/META-INF/native-image/com.google.http-client/google-http-client-appengine/reflect-config.json delete mode 100644 google-http-client-appengine/src/test/resources/META-INF/native-image/com.google.http-client/google-http-client-appengine/reflect-config.json 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/resources/META-INF/native-image/com.google.http-client/google-http-client-appengine/reflect-config.json b/google-http-client-appengine/src/test/resources/META-INF/native-image/com.google.http-client/google-http-client-appengine/reflect-config.json deleted file mode 100644 index aea286ffb..000000000 --- a/google-http-client-appengine/src/test/resources/META-INF/native-image/com.google.http-client/google-http-client-appengine/reflect-config.json +++ /dev/null @@ -1,416 +0,0 @@ -[ - { - "name": "com.google.api.client.extensions.appengine.datastore.AppEngineDataStoreFactoryTest", - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] - }, - { - "name": "com.google.api.client.extensions.appengine.datastore.AppEngineNoMemcacheDataStoreFactoryTest", - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] - }, - { - "name": "com.google.api.client.extensions.appengine.http.UrlFetchTransportTest", - "allDeclaredFields": true, - "methods": [ - { - "name": "", - "parameterTypes": [] - }, - { - "name": "test", - "parameterTypes": [] - } - ] - }, - { - "name": "com.google.api.client.test.util.store.AbstractDataStoreFactoryTest", - "methods": [ - { - "name": "testClear", - "parameterTypes": [] - }, - { - "name": "testContainsKeyAndValue", - "parameterTypes": [] - }, - { - "name": "testDelete", - "parameterTypes": [] - }, - { - "name": "testId", - "parameterTypes": [] - }, - { - "name": "testKeySet", - "parameterTypes": [] - }, - { - "name": "testLarge", - "parameterTypes": [] - }, - { - "name": "testSet", - "parameterTypes": [] - }, - { - "name": "testValues", - "parameterTypes": [] - } - ] - }, - { - "name": "com.google.appengine.api.appidentity.IAppIdentityServiceFactoryProvider" - }, - { - "name": "com.google.appengine.api.appidentity.dev.LocalAppIdentityService" - }, - { - "name": "com.google.appengine.api.backends.IBackendServiceFactoryProvider" - }, - { - "name": "com.google.appengine.api.blobstore.IBlobstoreServiceFactoryProvider" - }, - { - "name": "com.google.appengine.api.blobstore.dev.LocalBlobstoreService" - }, - { - "name": "com.google.appengine.api.capabilities.ICapabilitiesServiceFactoryProvider" - }, - { - "name": "com.google.appengine.api.capabilities.dev.LocalCapabilitiesService" - }, - { - "name": "com.google.appengine.api.datastore.IDatastoreServiceFactoryProvider" - }, - { - "name": "com.google.appengine.api.datastore.dev.LocalDatastoreV3Service", - "methods": [ - { - "name": "delete", - "parameterTypes": [ - "com.google.appengine.tools.development.LocalRpcService$Status", - "com.google.apphosting.api.DatastorePb$DeleteRequest" - ] - }, - { - "name": "get", - "parameterTypes": [ - "com.google.appengine.tools.development.LocalRpcService$Status", - "com.google.apphosting.api.DatastorePb$GetRequest" - ] - }, - { - "name": "next", - "parameterTypes": [ - "com.google.appengine.tools.development.LocalRpcService$Status", - "com.google.apphosting.api.DatastorePb$NextRequest" - ] - }, - { - "name": "put", - "parameterTypes": [ - "com.google.appengine.tools.development.LocalRpcService$Status", - "com.google.apphosting.api.DatastorePb$PutRequest" - ] - }, - { - "name": "runQuery", - "parameterTypes": [ - "com.google.appengine.tools.development.LocalRpcService$Status", - "com.google.apphosting.api.DatastorePb$Query" - ] - } - ] - }, - { - "name": "com.google.appengine.api.datastore.dev.WriteLatencyAdjuster", - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] - }, - { - "name": "com.google.appengine.api.images.IImagesServiceFactoryProvider" - }, - { - "name": "com.google.appengine.api.images.dev.LocalImagesService" - }, - { - "name": "com.google.appengine.api.log.ILogServiceFactoryProvider" - }, - { - "name": "com.google.appengine.api.log.dev.LocalLogService" - }, - { - "name": "com.google.appengine.api.mail.IMailServiceFactoryProvider" - }, - { - "name": "com.google.appengine.api.mail.dev.LocalMailService" - }, - { - "name": "com.google.appengine.api.memcache.IMemcacheServiceFactoryProvider" - }, - { - "name": "com.google.appengine.api.memcache.MemcacheServicePb$MemcacheDeleteRequest", - "methods": [ - { - "name": "parseFrom", - "parameterTypes": [ - "byte[]" - ] - } - ] - }, - { - "name": "com.google.appengine.api.memcache.MemcacheServicePb$MemcacheFlushRequest", - "methods": [ - { - "name": "parseFrom", - "parameterTypes": [ - "byte[]" - ] - } - ] - }, - { - "name": "com.google.appengine.api.memcache.MemcacheServicePb$MemcacheGetRequest", - "methods": [ - { - "name": "parseFrom", - "parameterTypes": [ - "byte[]" - ] - } - ] - }, - { - "name": "com.google.appengine.api.memcache.MemcacheServicePb$MemcacheSetRequest", - "methods": [ - { - "name": "parseFrom", - "parameterTypes": [ - "byte[]" - ] - } - ] - }, - { - "name": "com.google.appengine.api.memcache.dev.LocalMemcacheService", - "methods": [ - { - "name": "delete", - "parameterTypes": [ - "com.google.appengine.tools.development.LocalRpcService$Status", - "com.google.appengine.api.memcache.MemcacheServicePb$MemcacheDeleteRequest" - ] - }, - { - "name": "flushAll", - "parameterTypes": [ - "com.google.appengine.tools.development.LocalRpcService$Status", - "com.google.appengine.api.memcache.MemcacheServicePb$MemcacheFlushRequest" - ] - }, - { - "name": "get", - "parameterTypes": [ - "com.google.appengine.tools.development.LocalRpcService$Status", - "com.google.appengine.api.memcache.MemcacheServicePb$MemcacheGetRequest" - ] - }, - { - "name": "set", - "parameterTypes": [ - "com.google.appengine.tools.development.LocalRpcService$Status", - "com.google.appengine.api.memcache.MemcacheServicePb$MemcacheSetRequest" - ] - } - ] - }, - { - "name": "com.google.appengine.api.modules.IModulesServiceFactoryProvider" - }, - { - "name": "com.google.appengine.api.oauth.IOAuthServiceFactoryProvider" - }, - { - "name": "com.google.appengine.api.quota.IQuotaServiceFactoryProvider" - }, - { - "name": "com.google.appengine.api.search.ISearchServiceFactoryProvider" - }, - { - "name": "com.google.appengine.api.taskqueue.IQueueFactoryProvider" - }, - { - "name": "com.google.appengine.api.urlfetch.IURLFetchServiceFactoryProvider" - }, - { - "name": "com.google.appengine.api.users.IUserServiceFactoryProvider" - }, - { - "name": "com.google.appengine.repackaged.com.google.protobuf.ExtensionRegistry", - "methods": [ - { - "name": "getEmptyRegistry", - "parameterTypes": [] - } - ] - }, - { - "name": "com.google.appengine.tools.development.DynamicLatencyAdjuster$Default", - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] - }, - { - "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": [] - } - ] - }, - { - "name": "com.google.storage.onestore.v3.OnestoreEntity$Path", - "fields": [ - { - "name": "element_" - } - ] - }, - { - "name": "com.google.storage.onestore.v3.OnestoreEntity$Path$Element", - "fields": [ - { - "name": "id_" - }, - { - "name": "name_" - }, - { - "name": "optional_0_" - }, - { - "name": "type_" - } - ] - }, - { - "name": "java.lang.Object", - "allDeclaredFields": true - }, - { - "name": "java.nio.Buffer", - "fields": [ - { - "name": "address" - } - ] - }, - { - "name": "java.util.concurrent.atomic.AtomicBoolean", - "fields": [ - { - "name": "value" - } - ] - }, - { - "name": "libcore.io.Memory" - }, - { - "name": "org.apache.maven.surefire.booter.spi.LegacyMasterProcessChannelProcessorFactory" - }, - { - "name": "org.apache.maven.surefire.booter.spi.SurefireMasterProcessChannelProcessorFactory" - }, - { - "name": "org.robolectric.Robolectric" - }, - { - "name": "sun.misc.Unsafe", - "allDeclaredFields": true - }, - { - "name": "sun.security.provider.MD5", - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] - }, - { - "name": "sun.security.provider.NativePRNG", - "methods": [ - { - "name": "", - "parameterTypes": [ - "java.security.SecureRandomParameters" - ] - } - ] - }, - { - "name": "sun.security.provider.SHA", - "methods": [ - { - "name": "", - "parameterTypes": [] - } - ] - } -] From bf7444342d37b305d6e13a7aba48f40b5ecae3bb Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Wed, 5 Feb 2025 21:44:32 -0500 Subject: [PATCH 37/51] use JUnit4 in GSON tests --- .../api/client/json/gson/GsonFactoryTest.java | 66 ++-- .../test/json/AbstractJsonFactoryTest.java | 353 ++++++++++++++---- .../test/json/AbstractJsonGeneratorTest.java | 10 +- .../test/json/AbstractJsonParserTest.java | 16 +- 4 files changed, 335 insertions(+), 110 deletions(-) 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..b4a596131 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}. @@ -33,33 +38,34 @@ */ public class GsonFactoryTest extends AbstractJsonFactoryTest { - private static final String GSON_LINE_SEPARATOR = "\n"; - - private static final String JSON_ENTRY_PRETTY = - "{" + GSON_LINE_SEPARATOR + " \"title\": \"foo\"" + GSON_LINE_SEPARATOR + "}"; - private static final String JSON_FEED_PRETTY = - "{" - + GSON_LINE_SEPARATOR - + " \"entries\": [" - + GSON_LINE_SEPARATOR - + " {" - + GSON_LINE_SEPARATOR - + " \"title\": \"foo\"" - + GSON_LINE_SEPARATOR - + " }," - + GSON_LINE_SEPARATOR - + " {" - + GSON_LINE_SEPARATOR - + " \"title\": \"bar\"" - + GSON_LINE_SEPARATOR - + " }" - + GSON_LINE_SEPARATOR - + " ]" - + GSON_LINE_SEPARATOR - + "}"; - - public GsonFactoryTest(String name) { - super(name); + private static final String GSON_LINE_SEPARATOR; + private static final String JSON_ENTRY_PRETTY; + private static final String JSON_FEED_PRETTY; + + static { + GSON_LINE_SEPARATOR = "\n"; + JSON_ENTRY_PRETTY = + "{" + GSON_LINE_SEPARATOR + " \"title\": \"foo\"" + GSON_LINE_SEPARATOR + "}"; + JSON_FEED_PRETTY = + "{" + + GSON_LINE_SEPARATOR + + " \"entries\": [" + + GSON_LINE_SEPARATOR + + " {" + + GSON_LINE_SEPARATOR + + " \"title\": \"foo\"" + + GSON_LINE_SEPARATOR + + " }," + + GSON_LINE_SEPARATOR + + " {" + + GSON_LINE_SEPARATOR + + " \"title\": \"bar\"" + + GSON_LINE_SEPARATOR + + " }" + + GSON_LINE_SEPARATOR + + " ]" + + GSON_LINE_SEPARATOR + + "}"; } @Override @@ -67,12 +73,14 @@ 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 +93,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 +111,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 +124,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-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..920b2cc28 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,8 @@ 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 +111,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 +119,7 @@ public void testParse_emptyGenericJson() throws Exception { assertTrue(json.isEmpty()); } + @Test public void testParser_partialEmpty() throws Exception { JsonFactory factory = newFactory(); JsonParser parser; @@ -118,15 +134,22 @@ 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 +163,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 +175,7 @@ public void testParseFeed() throws Exception { } @SuppressWarnings("unchecked") + @Test public void testParseEntryAsMap() throws Exception { JsonParser parser = newFactory().createJsonParser(JSON_ENTRY); parser.nextToken(); @@ -159,6 +184,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 +192,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 +200,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 +209,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 +219,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 +229,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 +237,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 +246,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 +265,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 +311,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 +374,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 +428,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 +460,14 @@ 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 +485,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 +521,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 +545,14 @@ 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 +573,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 +602,16 @@ public static class WildCardTypes { @Key public Collection[] 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 +666,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 INT_ARRAY_TYPE_VARIABLE_TYPE = - "{\"arr\":[null,[null,[1]]],\"list\":[null,[null,[1]]],\"nullValue\":null,\"value\":[1]}"; + static final String FLOAT_MAP_TYPE_VARIABLE_TYPE; - static final String DOUBLE_LIST_TYPE_VARIABLE_TYPE = - "{\"arr\":[null,[null,[1.0]]],\"list\":[null,[null,[1.0]]]," - + "\"nullValue\":null,\"value\":[1.0]}"; + static { + INTEGER_TYPE_VARIABLE_TYPE = + "{\"arr\":[null,[null,1]],\"list\":[null,[null,1]],\"nullValue\":null,\"value\":1}"; - 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}}"; + INT_ARRAY_TYPE_VARIABLE_TYPE = + "{\"arr\":[null,[null,[1]]],\"list\":[null,[null,[1]]],\"nullValue\":null,\"value\":[1]}"; + + DOUBLE_LIST_TYPE_VARIABLE_TYPE = + "{\"arr\":[null,[null,[1.0]]],\"list\":[null,[null,[1.0]]]," + + "\"nullValue\":null,\"value\":[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 +727,7 @@ public void testParser_integerTypeVariableType() throws Exception { assertEquals(1, value.intValue()); } + @Test public void testParser_intArrayTypeVariableType() throws Exception { // parse JsonFactory factory = newFactory(); @@ -676,6 +764,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 +785,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 +803,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 +824,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 +835,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 +843,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 +881,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 +926,14 @@ 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 +963,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 +984,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 +1002,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 +1020,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 +1035,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 +1049,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 +1064,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 +1079,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 +1094,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 +1182,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 +1192,7 @@ public void testParser_nullInputStream() throws Exception { } } + @Test public void testParser_nullString() throws Exception { try { newFactory().createJsonParser((String) null); @@ -1058,6 +1202,7 @@ public void testParser_nullString() throws Exception { } } + @Test public void testParser_nullReader() throws Exception { try { newFactory().createJsonParser((Reader) null); @@ -1067,6 +1212,7 @@ public void testParser_nullReader() throws Exception { } } + @Test public void testObjectParserParse_entry() throws Exception { @SuppressWarnings("serial") Entry entry = @@ -1077,6 +1223,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 +1239,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 +1247,7 @@ public void testToString_withFactory() { assertEquals("{\"a\":\"b\"}", data.toString()); } + @Test public void testFactory() { JsonFactory factory = newFactory(); GenericJson data = new GenericJson(); @@ -1111,6 +1260,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 +1268,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 +1276,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 +1284,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 +1373,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 +1394,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 +1410,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 +1422,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 +1431,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 +1444,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 +1455,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 +1471,7 @@ public static class V { @Key String s; } + @Test public void testParse_void() throws Exception { subtestParse_void(null); subtestParse_void("\"a\""); @@ -1328,14 +1498,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 +1595,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 +1633,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 +1654,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 +1692,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 +1721,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 +1746,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 +1777,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 +1808,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 +1837,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 +1869,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 +1891,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 +1906,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 +1929,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 +1959,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..993dee5ab 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; @@ -22,8 +24,12 @@ 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 +40,7 @@ public Iterator> iterator() { } } + @Test public void testSerialize_simpleMap() throws Exception { StringWriter writer = new StringWriter(); JsonGenerator generator = newGenerator(writer); @@ -46,6 +53,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..30cae14b7 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 @@ -23,15 +23,22 @@ import java.nio.charset.StandardCharsets; import junit.framework.TestCase; import org.junit.Assert; +import org.junit.Test; public abstract class AbstractJsonParserTest extends TestCase { 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 +52,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 +65,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 +77,7 @@ public void testParse_badJson() throws IOException { } } + @Test public void testParse_bigDecimal() throws IOException { JsonObjectParser parser = new JsonObjectParser(newJsonFactory()); InputStream inputStream = From 818da9ad5ab4e799c36654044cbb4250e9790d26 Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Thu, 6 Feb 2025 02:54:52 +0000 Subject: [PATCH 38/51] fix clirr --- .../clirr-ignored-differences.xml | 45 +++++++++++++++++-- 1 file changed, 41 insertions(+), 4 deletions(-) diff --git a/google-http-client-test/clirr-ignored-differences.xml b/google-http-client-test/clirr-ignored-differences.xml index b3e02eaff..f7c8ef4a2 100644 --- a/google-http-client-test/clirr-ignored-differences.xml +++ b/google-http-client-test/clirr-ignored-differences.xml @@ -1,7 +1,20 @@ @@ -10,16 +23,40 @@ 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 + 5001 com/google/api/client/test/util/store/AbstractDataStoreFactoryTest - junit/framework/Assert + junit/framework/* 5001 - com/google/api/client/test/util/store/AbstractDataStoreFactoryTest - junit/framework/TestCase + com/google/api/client/test/json/AbstractJsonFactoryTest + junit/framework/* + + + + 5001 + com/google/api/client/test/json/AbstractJsonGeneratorTest + junit/framework/* + + + + 7004 + com/google/api/client/test/json/AbstractJsonFactoryTest + * From d6f991c4c86f4a64bcfbeafd52ebb41d36ba9bae Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Wed, 5 Feb 2025 21:57:53 -0500 Subject: [PATCH 39/51] port abstract json parser test to JUnit4 --- .../api/client/test/json/AbstractJsonParserTest.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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 30cae14b7..8b8e93fa7 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; @@ -24,8 +28,11 @@ 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(); From 1322e423849e336e55266e0cfdf03a8ee55add45 Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Wed, 5 Feb 2025 22:00:08 -0500 Subject: [PATCH 40/51] remove unused imports --- .../google/api/client/test/json/AbstractJsonGeneratorTest.java | 1 - .../com/google/api/client/test/json/AbstractJsonParserTest.java | 1 - 2 files changed, 2 deletions(-) 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 993dee5ab..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 @@ -23,7 +23,6 @@ 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; 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 8b8e93fa7..e746ae02d 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 @@ -25,7 +25,6 @@ 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; From 3b8c44c4e0634125d69e595e9f66b13f2bb17f34 Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Thu, 6 Feb 2025 03:03:46 +0000 Subject: [PATCH 41/51] update clirr again --- .../clirr-ignored-differences.xml | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/google-http-client-test/clirr-ignored-differences.xml b/google-http-client-test/clirr-ignored-differences.xml index f7c8ef4a2..34c8e4f44 100644 --- a/google-http-client-test/clirr-ignored-differences.xml +++ b/google-http-client-test/clirr-ignored-differences.xml @@ -15,6 +15,7 @@ [ERROR] 4001: com.google.api.client.test.json.AbstractJsonGeneratorTest: Removed junit.framework.Test from the set of implemented interfaces [ERROR] 5001: com.google.api.client.test.json.AbstractJsonGeneratorTest: Removed junit.framework.Assert from the list of superclasses [ERROR] 5001: com.google.api.client.test.json.AbstractJsonGeneratorTest: Removed junit.framework.TestCase from the list of superclasses +[ERROR] 4001: com.google.api.client.test.json.AbstractJsonParserTest: Removed junit.framework.Test from the set of implemented interfaces [ERROR] 5001: com.google.api.client.test.json.AbstractJsonParserTest: Removed junit.framework.Assert from the list of superclasses [ERROR] 5001: com.google.api.client.test.json.AbstractJsonParserTest: Removed junit.framework.TestCase from the list of superclasses --> @@ -35,6 +36,12 @@ com/google/api/client/test/json/AbstractJsonGeneratorTest junit/framework/Test + + + 4001 + com/google/api/client/test/json/AbstractJsonParserTest + junit/framework/Test + 5001 @@ -53,6 +60,12 @@ com/google/api/client/test/json/AbstractJsonGeneratorTest junit/framework/* + + + 5001 + com/google/api/client/test/json/AbstractJsonParserTest + junit/framework/* + 7004 From bf0c6b41040bb11e64ab6a4d3e4e1daf2d4e4a69 Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Thu, 6 Feb 2025 03:08:13 +0000 Subject: [PATCH 42/51] add native config to gson module --- .../google-http-client-gson/native-image.properties | 1 + 1 file changed, 1 insertion(+) create mode 100644 google-http-client-gson/src/test/resources/META-INF/native-image/com.google.http-client/google-http-client-gson/native-image.properties 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 From 411304b0a1072370fb0da271c2132d023afa4fa1 Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Wed, 5 Feb 2025 22:11:05 -0500 Subject: [PATCH 43/51] convert jackson module to JUnit4 --- .../json/jackson2/JacksonFactoryTest.java | 46 +++++++++++-------- .../json/jackson2/JacksonGeneratorTest.java | 6 ++- 2 files changed, 33 insertions(+), 19 deletions(-) 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..5551dcc75 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}. @@ -28,25 +33,26 @@ */ public class JacksonFactoryTest extends AbstractJsonFactoryTest { - private static final String JSON_ENTRY_PRETTY = - "{" + StringUtils.LINE_SEPARATOR + " \"title\" : \"foo\"" + StringUtils.LINE_SEPARATOR + "}"; - private static final String JSON_FEED_PRETTY = - "{" - + StringUtils.LINE_SEPARATOR - + " \"entries\" : [ {" - + StringUtils.LINE_SEPARATOR - + " \"title\" : \"foo\"" - + StringUtils.LINE_SEPARATOR - + " }, {" - + StringUtils.LINE_SEPARATOR - + " \"title\" : \"bar\"" - + StringUtils.LINE_SEPARATOR - + " } ]" - + StringUtils.LINE_SEPARATOR - + "}"; + private static final String JSON_ENTRY_PRETTY; + private static final String JSON_FEED_PRETTY; - public JacksonFactoryTest(String name) { - super(name); + static { + JSON_ENTRY_PRETTY = + "{" + StringUtils.LINE_SEPARATOR + " \"title\" : \"foo\"" + StringUtils.LINE_SEPARATOR + "}"; + JSON_FEED_PRETTY = + "{" + + StringUtils.LINE_SEPARATOR + + " \"entries\" : [ {" + + StringUtils.LINE_SEPARATOR + + " \"title\" : \"foo\"" + + StringUtils.LINE_SEPARATOR + + " }, {" + + StringUtils.LINE_SEPARATOR + + " \"title\" : \"bar\"" + + StringUtils.LINE_SEPARATOR + + " } ]" + + StringUtils.LINE_SEPARATOR + + "}"; } @Override @@ -54,12 +60,14 @@ 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 +80,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/java/com/google/api/client/json/jackson2/JacksonGeneratorTest.java b/google-http-client-jackson2/src/test/java/com/google/api/client/json/jackson2/JacksonGeneratorTest.java index 4b0af8478..d5cf01a3d 100644 --- a/google-http-client-jackson2/src/test/java/com/google/api/client/json/jackson2/JacksonGeneratorTest.java +++ b/google-http-client-jackson2/src/test/java/com/google/api/client/json/jackson2/JacksonGeneratorTest.java @@ -21,7 +21,11 @@ public class JacksonGeneratorTest extends AbstractJsonGeneratorTest { - private static final JacksonFactory FACTORY = new JacksonFactory(); + private static final JacksonFactory FACTORY; + + static { + FACTORY = new JacksonFactory(); + } @Override protected JsonGenerator newGenerator(Writer writer) throws IOException { From f787ea4a2bd2d2e53596998c0d2b9a4ac4df5365 Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Wed, 5 Feb 2025 22:19:21 -0500 Subject: [PATCH 44/51] make jackson factory instantiation native friendly --- .../api/client/json/jackson2/JacksonFactory.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/google-http-client-jackson2/src/main/java/com/google/api/client/json/jackson2/JacksonFactory.java b/google-http-client-jackson2/src/main/java/com/google/api/client/json/jackson2/JacksonFactory.java index 1079fb725..e76228805 100644 --- a/google-http-client-jackson2/src/main/java/com/google/api/client/json/jackson2/JacksonFactory.java +++ b/google-http-client-jackson2/src/main/java/com/google/api/client/json/jackson2/JacksonFactory.java @@ -39,10 +39,10 @@ public final class JacksonFactory extends JsonFactory { /** JSON factory. */ - private final com.fasterxml.jackson.core.JsonFactory factory = - new com.fasterxml.jackson.core.JsonFactory(); + private final com.fasterxml.jackson.core.JsonFactory factory; - { + public JacksonFactory() { + factory = new com.fasterxml.jackson.core.JsonFactory(); // don't auto-close JSON content in order to ensure consistent behavior across JSON factories // TODO(rmistry): Should we disable the JsonGenerator.Feature.AUTO_CLOSE_TARGET feature? factory.configure( @@ -60,7 +60,10 @@ public static JacksonFactory getDefaultInstance() { /** Holder for the result of {@link #getDefaultInstance()}. */ static class InstanceHolder { - static final JacksonFactory INSTANCE = new JacksonFactory(); + static final JacksonFactory INSTANCE; + static { + INSTANCE = new JacksonFactory(); + } } @Override From 505f931bba156f58634074082676292583ff902a Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Thu, 6 Feb 2025 03:36:22 +0000 Subject: [PATCH 45/51] config test-only build-time initialization --- .../google-http-client-jackson2/native-image.properties | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) 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..2f7413dd5 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,5 @@ 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.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 From 94aab3894d82346891964bfc5f96524b16f2465e Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Wed, 5 Feb 2025 22:39:07 -0500 Subject: [PATCH 46/51] adapt protocol buffers module to JUnit 4 --- .../google/api/client/protobuf/ProtocolBuffers.java | 9 +++++++-- .../api/client/protobuf/ProtocolBuffersTest.java | 10 ++++++++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/google-http-client-protobuf/src/main/java/com/google/api/client/protobuf/ProtocolBuffers.java b/google-http-client-protobuf/src/main/java/com/google/api/client/protobuf/ProtocolBuffers.java index b9b383d1d..db9b64a33 100644 --- a/google-http-client-protobuf/src/main/java/com/google/api/client/protobuf/ProtocolBuffers.java +++ b/google-http-client-protobuf/src/main/java/com/google/api/client/protobuf/ProtocolBuffers.java @@ -37,10 +37,15 @@ public class ProtocolBuffers { /** {@code "application/x-protobuf"} content type. */ - public static final String CONTENT_TYPE = "application/x-protobuf"; + public static final String CONTENT_TYPE; /** {@code "application/x-protobuffer"} content type. */ - public static final String ALT_CONTENT_TYPE = "application/x-protobuffer"; + public static final String ALT_CONTENT_TYPE; + + static { + CONTENT_TYPE = "application/x-protobuf"; + ALT_CONTENT_TYPE = "application/x-protobuffer"; + } /** * Parses protocol buffer content from an input stream (closing the input stream) into a protocol 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() From 35543d3483a9dff6c5834c5690e7043e82de04d7 Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Thu, 6 Feb 2025 03:42:04 +0000 Subject: [PATCH 47/51] initialize test classes at test time --- .../google-http-client-protobuf/native-image.properties | 1 + 1 file changed, 1 insertion(+) create mode 100644 google-http-client-protobuf/src/main/resources/META-INF/native-image/com.google.http-client/google-http-client-protobuf/native-image.properties 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 From 715fc0d8c4b856209f9878128e0bb831f19a715a Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Wed, 5 Feb 2025 22:50:44 -0500 Subject: [PATCH 48/51] convert xml module to JUnit4 --- .../com/google/api/client/xml/AtomTest.java | 31 +++-- .../api/client/xml/GenericXmlListTest.java | 51 ++++---- .../google/api/client/xml/GenericXmlTest.java | 77 ++++++----- .../google/api/client/xml/XmlEnumTest.java | 45 ++++--- .../google/api/client/xml/XmlListTest.java | 56 ++++---- .../xml/XmlNamespaceDictionaryTest.java | 63 ++++++--- .../com/google/api/client/xml/XmlTest.java | 122 +++++++++++------- 7 files changed, 271 insertions(+), 174 deletions(-) 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..64842b1c5 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,20 +42,25 @@ * @author Yaniv Inbar * @author Gerald Madlmayr */ +@RunWith(JUnit4.class) public class AtomTest { - private static final String SAMPLE_FEED = - " Example Feed 2003-12-13T18:31:02Z " - + "John Doe urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6" - + " Atom-Powered Robots Run Amok urn:uuid:1225c695-cfb8-4ebb-aaaa" - + "-80da344efa6a 2003-12-13T18:30:02Z Some text" - + ". Atom-Powered Robots Run Amok! urn:uuid:1225c695-cfb8-4ebb" - + "-aaaa-80da344efa62 2003-12-13T18:32:02Z Some " - + "other text. "; + private static final String SAMPLE_FEED; + + static { + SAMPLE_FEED = + " Example Feed 2003-12-13T18:31:02Z " + + "John Doe urn:uuid:60a76c80-d399-11d9-b93C-0003939e0af6" + + " Atom-Powered Robots Run Amok urn:uuid:1225c695-cfb8-4ebb-aaaa" + + "-80da344efa6a 2003-12-13T18:30:02Z Some text" + + ". Atom-Powered Robots Run Amok! urn:uuid:1225c695-cfb8-4ebb" + + "-aaaa-80da344efa62 2003-12-13T18:32:02Z Some " + + "other text. "; + } /** Test for checking the Slug Header */ @Test 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..b48785e94 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,30 +37,35 @@ * * @author Gerald Madlmayr */ +@RunWith(JUnit4.class) public class GenericXmlListTest { - private static final String MULTI_TYPE_WITH_CLASS_TYPE = - "content1rep10" - + "rep11value1content2rep20rep21" - + "value2content3rep30rep31" - + "value3"; - private static final String MULTIPLE_STRING_ELEMENT = - "rep1rep2"; - private static final String MULTIPLE_INTEGER_ELEMENT = - "12"; - private static final String ARRAY_TYPE_WITH_PRIMITIVE_ADDED_NESTED = - "1something2"; - private static final String MULTIPLE_ENUM_ELEMENT = - "ENUM_1ENUM_2"; - private static final String COLLECTION_OF_ARRAY = - "abcd"; + private static final String MULTI_TYPE_WITH_CLASS_TYPE; + private static final String MULTIPLE_STRING_ELEMENT; + private static final String MULTIPLE_INTEGER_ELEMENT; + private static final String MULTIPLE_ENUM_ELEMENT; + private static final String COLLECTION_OF_ARRAY; + + static { + MULTI_TYPE_WITH_CLASS_TYPE = + "content1rep10" + + "rep11value1content2rep20rep21" + + "value2content3rep30rep31" + + "value3"; + MULTIPLE_STRING_ELEMENT = + "rep1rep2"; + MULTIPLE_INTEGER_ELEMENT = + "12"; + MULTIPLE_ENUM_ELEMENT = + "ENUM_1ENUM_2"; + COLLECTION_OF_ARRAY = + "abcd"; + } /** The purpose of this test is to map an XML with an Array of {@link XmlTest.AnyType} objects. */ @SuppressWarnings("unchecked") 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..f2cda9a19 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,39 +43,52 @@ * @author Yaniv Inbar * @author Gerald Madlmayr */ +@RunWith(JUnit4.class) public class GenericXmlTest { - private static final String XML = - "OneTwo"; - private static final String ANY_GENERIC_TYPE_XML = - "rep1rep2content"; - private static final String SIMPLE_XML = "test"; - private static final String SIMPLE_XML_NUMERIC = "1"; - private static final String ANY_TYPE_XML = - "contentrep1rep2content"; - private static final String ANY_TYPE_XML_PRIMITIVE_INT = - "112" - + ""; - private static final String ANY_TYPE_XML_PRIMITIVE_STR = - "1+11+12" - + "+1"; - private static final String ALL_TYPE = - ""; - private static final String ANY_TYPE_XML_NESTED_ARRAY = - "content

rep1

rep2

rep3

rep4

content
"; + private static final String XML; + private static final String ANY_GENERIC_TYPE_XML; + private static final String SIMPLE_XML; + private static final String SIMPLE_XML_NUMERIC; + private static final String ANY_TYPE_XML; + private static final String ANY_TYPE_XML_PRIMITIVE_INT; + private static final String ANY_TYPE_XML_PRIMITIVE_STR; + private static final String ALL_TYPE; + private static final String ANY_TYPE_XML_NESTED_ARRAY; + + static { + XML = + "OneTwo"; + ANY_GENERIC_TYPE_XML = + "rep1rep2content"; + SIMPLE_XML = "test"; + SIMPLE_XML_NUMERIC = "1"; + ANY_TYPE_XML = + "contentrep1rep2content"; + ANY_TYPE_XML_PRIMITIVE_INT = + "112" + + ""; + ANY_TYPE_XML_PRIMITIVE_STR = + "1+11+12" + + "+1"; + ALL_TYPE = + ""; + ANY_TYPE_XML_NESTED_ARRAY = + "content

rep1

rep2

rep3

rep4

content
"; + } public GenericXmlTest() {} 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..0fa40f848 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,25 +35,34 @@ * * @author Gerald Madlmayr */ +@RunWith(JUnit4.class) public class XmlEnumTest { - private static final String XML = - "ENUM_2contentrep1rep2ENUM_1"; - private static final String XML_ENUM_ELEMENT_ONLY = - "ENUM_2"; - private static final String XML_ENUM_ATTRIBUTE_ONLY = - ""; - private static final String XML_ENUM_INCORRECT = - "ENUM_3"; - private static final String XML_ENUM_ELEMENT_ONLY_NESTED = - "ENUM_2something"; + private static final String XML; + private static final String XML_ENUM_ELEMENT_ONLY; + private static final String XML_ENUM_ATTRIBUTE_ONLY; + private static final String XML_ENUM_INCORRECT; + private static final String XML_ENUM_ELEMENT_ONLY_NESTED; + + static { + XML = + "ENUM_2contentrep1rep2ENUM_1"; + XML_ENUM_ELEMENT_ONLY = + "ENUM_2"; + XML_ENUM_ATTRIBUTE_ONLY = + ""; + XML_ENUM_INCORRECT = + "ENUM_3"; + XML_ENUM_ELEMENT_ONLY_NESTED = + "ENUM_2something"; + } @Test public void testParseAnyType() throws Exception { 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..1706bfb18 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,30 +34,40 @@ * * @author Gerald Madlmayr */ +@RunWith(JUnit4.class) public class XmlListTest { - private static final String MULTI_TYPE_WITH_CLASS_TYPE = - "content1rep10rep11value1content2rep20rep21value2content3rep30rep31value3"; - private static final String MULTIPLE_STRING_ELEMENT = - "rep1rep2"; - private static final String MULTIPLE_STRING_ELEMENT_IN_COLLECTION = - "rep1rep2"; - private static final String MULTIPLE_INTEGER_ELEMENT = - "12"; - private static final String MULTIPLE_ENUM_ELEMENT = - "ENUM_1ENUM_2"; - private static final String COLLECTION_OF_ARRAY = - "abcd"; + private static final String MULTI_TYPE_WITH_CLASS_TYPE; + private static final String MULTIPLE_STRING_ELEMENT; + private static final String MULTIPLE_STRING_ELEMENT_IN_COLLECTION; + private static final String MULTIPLE_INTEGER_ELEMENT; + private static final String MULTIPLE_ENUM_ELEMENT; + private static final String COLLECTION_OF_ARRAY; + + static { + MULTI_TYPE_WITH_CLASS_TYPE = + "content1rep10rep11value1content2rep20rep21value2content3rep30rep31value3"; + MULTIPLE_STRING_ELEMENT = + "rep1rep2"; + MULTIPLE_STRING_ELEMENT_IN_COLLECTION = + "rep1rep2"; + MULTIPLE_INTEGER_ELEMENT = + "12"; + MULTIPLE_ENUM_ELEMENT = + "ENUM_1ENUM_2"; + COLLECTION_OF_ARRAY = + "abcd"; + } /** The purpose of this test is to map an XML with an Array of {@link XmlTest.AnyType} objects. */ @SuppressWarnings("unchecked") 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..958406df4 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,6 +14,11 @@ 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; @@ -21,6 +26,9 @@ 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,29 +36,35 @@ * * @author Yaniv Inbar */ -public class XmlNamespaceDictionaryTest extends TestCase { - - private static final String EXPECTED = - "OneTwo"; - private static final String EXPECTED_EMPTY_MAP = - ""; - private static final String EXPECTED_EMPTY_MAP_NS_UNDECLARED = - ""; - private static final String EXPECTED_EMPTY_MAP_ATOM_NS = - ""; - private static final String EXPECTED_UNKNOWN_NS = - "One" - + "Two"; +@RunWith(JUnit4.class) +public class XmlNamespaceDictionaryTest { + + private static final String EXPECTED; + private static final String EXPECTED_EMPTY_MAP; + private static final String EXPECTED_EMPTY_MAP_NS_UNDECLARED; + private static final String EXPECTED_EMPTY_MAP_ATOM_NS; + private static final String EXPECTED_UNKNOWN_NS; + + static { + EXPECTED = + "OneTwo"; + EXPECTED_EMPTY_MAP = + ""; + EXPECTED_EMPTY_MAP_NS_UNDECLARED = + ""; + EXPECTED_EMPTY_MAP_ATOM_NS = + ""; + EXPECTED_UNKNOWN_NS = + "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 +92,7 @@ public void testSet() { assertTrue(dictionary.getAliasToUriMap().isEmpty()); } + @Test public void testSerialize() throws Exception { Feed feed = new Feed(); feed.entries = new TreeSet(); @@ -93,6 +108,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 +124,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 +136,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 +148,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 +160,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 +171,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 +187,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 +203,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..2b815c50e 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,58 +39,78 @@ * @author Yaniv Inbar * @author Gerald Madlmayr */ +@RunWith(JUnit4.class) public class XmlTest { - private static final String SIMPLE_XML = "test"; - private static final String SIMPLE_XML_NUMERIC = "1"; - private static final String START_WITH_TEXT = "start_with_text"; - private static final String MISSING_END_ELEMENT = - "" + "missing_end_element"; - private static final String START_WITH_END_ELEMENT = - "

start_with_end_elemtn"; - private static final String START_WITH_END_ELEMENT_NESTED = - "

start_with_end_element_nested
"; - private static final String ANY_TYPE_XML = - "contentrep1rep2" - + "content"; - private static final String ANY_TYPE_MISSING_XML = - "contentcontent"; - private static final String ANY_TYPE_XML_PRIMITIVE_INT = - "112" - + ""; - private static final String ANY_TYPE_XML_PRIMITIVE_STR = - "1+11+12" - + "+1"; - private static final String NESTED_NS = - "2011-08-09T04:38" - + ":14.017Z"; - private static final String NESTED_NS_SERIALIZED = - "2011-08-09T04:38:14.017Z"; - private static final String INF_TEST = - "-INFINF-INFINF" - + ""; - private static final String ALL_TYPE = - ""; - private static final String ALL_TYPE_WITH_DATA = - "" - + "ENUM_1ENUM_2Title

Test

112str1arr1arr2
"; - private static final String ANY_TYPE_XML_NESTED_ARRAY = - "content

rep1

rep2

rep3

rep4

content
"; + private static final String SIMPLE_XML; + private static final String SIMPLE_XML_NUMERIC; + private static final String START_WITH_TEXT; + private static final String MISSING_END_ELEMENT; + private static final String START_WITH_END_ELEMENT; + private static final String START_WITH_END_ELEMENT_NESTED; + private static final String ANY_TYPE_XML; + private static final String ANY_TYPE_MISSING_XML; + private static final String ANY_TYPE_XML_PRIMITIVE_INT; + private static final String ANY_TYPE_XML_PRIMITIVE_STR; + private static final String NESTED_NS; + private static final String NESTED_NS_SERIALIZED; + private static final String INF_TEST; + private static final String ALL_TYPE; + private static final String ALL_TYPE_WITH_DATA; + private static final String ANY_TYPE_XML_NESTED_ARRAY; + + static { + SIMPLE_XML = "test"; + SIMPLE_XML_NUMERIC = "1"; + START_WITH_TEXT = "start_with_text
"; + MISSING_END_ELEMENT = + "" + "missing_end_element"; + START_WITH_END_ELEMENT = + "

start_with_end_elemtn"; + START_WITH_END_ELEMENT_NESTED = + "

start_with_end_element_nested
"; + ANY_TYPE_XML = + "contentrep1rep2" + + "content"; + ANY_TYPE_MISSING_XML = + "contentcontent"; + ANY_TYPE_XML_PRIMITIVE_INT = + "112" + + ""; + ANY_TYPE_XML_PRIMITIVE_STR = + "1+11+12" + + "+1"; + NESTED_NS = + "2011-08-09T04:38" + + ":14.017Z"; + NESTED_NS_SERIALIZED = + "2011-08-09T04:38:14.017Z"; + INF_TEST = + "-INFINF-INFINF" + + ""; + ALL_TYPE = + ""; + ALL_TYPE_WITH_DATA = + "" + + "ENUM_1ENUM_2Title

Test

112str1arr1arr2
"; + ANY_TYPE_XML_NESTED_ARRAY = + "content

rep1

rep2

rep3

rep4

content
"; + } /** * The purpose of this test is to map a single element to a single field of a destination object. From dd335e89f56d7b4f4f38f761763189419de388eb Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Thu, 6 Feb 2025 03:53:19 +0000 Subject: [PATCH 49/51] add test time initialization entries to xml module --- .../google-http-client-xml/native-image.properties | 1 + 1 file changed, 1 insertion(+) create mode 100644 google-http-client-xml/src/test/resources/META-INF/native-image/com.google.http-client/google-http-client-xml/native-image.properties 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 From 6209970654c0b8d65624d98e1b49da29a99ee356 Mon Sep 17 00:00:00 2001 From: diegomarquezp Date: Thu, 6 Feb 2025 04:02:22 +0000 Subject: [PATCH 50/51] format --- .../api/client/json/jackson2/JacksonFactory.java | 1 + .../api/client/json/jackson2/JacksonFactoryTest.java | 6 +++++- .../api/client/test/json/AbstractJsonFactoryTest.java | 11 ++++------- .../api/client/test/json/AbstractJsonParserTest.java | 3 +-- .../test/util/store/AbstractDataStoreFactoryTest.java | 1 + .../api/client/xml/XmlNamespaceDictionaryTest.java | 1 - .../test/java/com/google/api/client/xml/XmlTest.java | 3 +-- .../client/util/store/AbstractDataStoreFactory.java | 3 +-- .../api/client/util/store/FileDataStoreFactory.java | 5 ++--- 9 files changed, 16 insertions(+), 18 deletions(-) diff --git a/google-http-client-jackson2/src/main/java/com/google/api/client/json/jackson2/JacksonFactory.java b/google-http-client-jackson2/src/main/java/com/google/api/client/json/jackson2/JacksonFactory.java index e76228805..a78cc3647 100644 --- a/google-http-client-jackson2/src/main/java/com/google/api/client/json/jackson2/JacksonFactory.java +++ b/google-http-client-jackson2/src/main/java/com/google/api/client/json/jackson2/JacksonFactory.java @@ -61,6 +61,7 @@ public static JacksonFactory getDefaultInstance() { /** Holder for the result of {@link #getDefaultInstance()}. */ static class InstanceHolder { static final JacksonFactory INSTANCE; + static { INSTANCE = new JacksonFactory(); } 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 5551dcc75..d80bb8390 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 @@ -38,7 +38,11 @@ public class JacksonFactoryTest extends AbstractJsonFactoryTest { static { JSON_ENTRY_PRETTY = - "{" + StringUtils.LINE_SEPARATOR + " \"title\" : \"foo\"" + StringUtils.LINE_SEPARATOR + "}"; + "{" + + StringUtils.LINE_SEPARATOR + + " \"title\" : \"foo\"" + + StringUtils.LINE_SEPARATOR + + "}"; JSON_FEED_PRETTY = "{" + StringUtils.LINE_SEPARATOR 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 920b2cc28..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 @@ -101,7 +101,6 @@ public void testParse_empty() throws Exception { } } - @Test public void testParse_emptyMap() throws Exception { JsonParser parser = newFactory().createJsonParser(EMPTY_OBJECT); @@ -139,8 +138,7 @@ public void testParser_partialEmpty() throws Exception { static { JSON_ENTRY = "{\"title\":\"foo\"}"; - JSON_FEED = - "{\"entries\":[" + "{\"title\":\"foo\"}," + "{\"title\":\"bar\"}]}"; + JSON_FEED = "{\"entries\":[" + "{\"title\":\"foo\"}," + "{\"title\":\"bar\"}]}"; } @Test @@ -461,6 +459,7 @@ public static class AnyType { } static final String ANY_TYPE; + static { ANY_TYPE = "{\"arr\":[1],\"bool\":true,\"nul\":null,\"num\":5," @@ -548,8 +547,7 @@ public static class MapOfMapType { static final String MAP_TYPE; static { - MAP_TYPE = - "{\"value\":[{\"map1\":{\"k1\":1,\"k2\":2},\"map2\":{\"kk1\":3,\"kk2\":4}}]}"; + MAP_TYPE = "{\"value\":[{\"map1\":{\"k1\":1,\"k2\":2},\"map2\":{\"kk1\":3,\"kk2\":4}}]}"; } @Test @@ -929,8 +927,7 @@ public static class EnumValue { static final String ENUM_VALUE; static { - ENUM_VALUE = - "{\"nullValue\":null,\"otherValue\":\"other\",\"value\":\"VALUE\"}"; + ENUM_VALUE = "{\"nullValue\":null,\"otherValue\":\"other\",\"value\":\"VALUE\"}"; } @Test 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 e746ae02d..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 @@ -39,8 +39,7 @@ public abstract class AbstractJsonParserTest { private static final String TEST_JSON_BIG_DECIMAL; static { - TEST_JSON = - "{\"strValue\": \"bar\", \"intValue\": 123, \"boolValue\": false}"; + TEST_JSON = "{\"strValue\": \"bar\", \"intValue\": 123, \"boolValue\": false}"; TEST_JSON_BIG_DECIMAL = "{\"bigDecimalValue\": 1559341956102}"; } 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 36ee9eefa..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 @@ -49,6 +49,7 @@ public abstract class AbstractDataStoreFactoryTest { STRING_ID = "String"; BOOLEAN_ID = "Boolean"; } + DataStoreFactory dataStore; DataStore stringTyped; DataStore boolTyped; 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 958406df4..34022a873 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 @@ -25,7 +25,6 @@ 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; 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 2b815c50e..539bd00a7 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 @@ -63,8 +63,7 @@ public class XmlTest { SIMPLE_XML = "test"; SIMPLE_XML_NUMERIC = "1"; START_WITH_TEXT = "start_with_text
"; - MISSING_END_ELEMENT = - "" + "missing_end_element"; + MISSING_END_ELEMENT = "" + "missing_end_element"; START_WITH_END_ELEMENT = "

start_with_end_elemtn"; START_WITH_END_ELEMENT_NESTED = 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 b5db4e8d9..86593e2fa 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 @@ -54,8 +54,7 @@ public abstract class AbstractDataStoreFactory implements DataStoreFactory { } public final DataStore getDataStore(String id) throws IOException { - 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 1e2648116..4433812e4 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 @@ -24,7 +24,6 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.Serializable; -import java.lang.System.Logger.Level; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; @@ -38,7 +37,6 @@ 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. @@ -57,12 +55,13 @@ public class FileDataStoreFactory extends AbstractDataStoreFactory { 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()); + // Logger.getLogger(FileDataStoreFactory.class.getName()).severe(ex.getMessage()); ex.printStackTrace(); System.out.println("*********************************************************"); System.out.println(ex.getMessage()); From 3d4c01f3480d5fd6d0d86d75ad32b081e6d667db Mon Sep 17 00:00:00 2001 From: Diego Alonso Marquez Palacios Date: Wed, 5 Feb 2025 23:04:49 -0500 Subject: [PATCH 51/51] restore debug setup --- .../api/client/util/store/AbstractDataStoreFactory.java | 3 ++- .../google/api/client/util/store/FileDataStoreFactory.java | 6 +----- 2 files changed, 3 insertions(+), 6 deletions(-) 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 b5db4e8d9..e6a8c9b4e 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 @@ -22,6 +22,7 @@ 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; /** @@ -48,7 +49,7 @@ public abstract class AbstractDataStoreFactory implements DataStoreFactory { try { ID_PATTERN = Pattern.compile("\\w{1,30}"); } catch (Throwable t) { - System.out.println(t.getMessage()); + Logger.getLogger(AbstractDataStoreFactory.class.getName()).severe(t.getMessage()); throw t; } } 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 1e2648116..a53d14d8f 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 @@ -24,7 +24,6 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.Serializable; -import java.lang.System.Logger.Level; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; @@ -62,10 +61,7 @@ public class FileDataStoreFactory extends AbstractDataStoreFactory { IS_WINDOWS = StandardSystemProperty.OS_NAME.value().toLowerCase(Locale.ENGLISH).startsWith("windows"); } catch (Throwable ex) { - //Logger.getLogger(FileDataStoreFactory.class.getName()).severe(ex.getMessage()); - ex.printStackTrace(); - System.out.println("*********************************************************"); - System.out.println(ex.getMessage()); + Logger.getLogger(FileDataStoreFactory.class.getName()).severe(ex.getMessage()); throw ex; } }