From 2016e407355b7f3071cbfd03b97ab03aa6678ed7 Mon Sep 17 00:00:00 2001 From: Alice Li Date: Thu, 16 May 2024 15:30:03 -0400 Subject: [PATCH] fix lint errors --- .../com/google/api/core/ApiFuturesTest.java | 9 +- .../api/core/SettableApiFutureTest.java | 12 +- .../api/pathtemplate/PathTemplateTest.java | 273 +++++++++--------- .../TemplatedResourceNameTest.java | 1 + .../UntypedResourceNameTest.java | 1 - 5 files changed, 157 insertions(+), 139 deletions(-) diff --git a/api-common-java/src/test/java/com/google/api/core/ApiFuturesTest.java b/api-common-java/src/test/java/com/google/api/core/ApiFuturesTest.java index 6c6fcee4a3..eaff30e5e7 100644 --- a/api-common-java/src/test/java/com/google/api/core/ApiFuturesTest.java +++ b/api-common-java/src/test/java/com/google/api/core/ApiFuturesTest.java @@ -188,10 +188,11 @@ void testTransformAsyncWithExecutor() throws Exception { ApiFutures.transformAsync( inputFuture, (ApiAsyncFunction) input -> ApiFutures.immediateFuture(input + 1), - (Executor) command -> { - counter.incrementAndGet(); - command.run(); - }); + (Executor) + command -> { + counter.incrementAndGet(); + command.run(); + }); assertThat(outputFuture.get()).isEqualTo(1); assertThat(counter.get()).isEqualTo(1); } diff --git a/api-common-java/src/test/java/com/google/api/core/SettableApiFutureTest.java b/api-common-java/src/test/java/com/google/api/core/SettableApiFutureTest.java index c9a8847d9f..52c0db990a 100644 --- a/api-common-java/src/test/java/com/google/api/core/SettableApiFutureTest.java +++ b/api-common-java/src/test/java/com/google/api/core/SettableApiFutureTest.java @@ -59,11 +59,13 @@ void testCancel() { @Test void testException() { - Assertions.assertThrows(Exception.class, () -> { - SettableApiFuture future = SettableApiFuture.create(); - future.setException(new Exception()); - future.get(); - }); + Assertions.assertThrows( + Exception.class, + () -> { + SettableApiFuture future = SettableApiFuture.create(); + future.setException(new Exception()); + future.get(); + }); } @Test diff --git a/api-common-java/src/test/java/com/google/api/pathtemplate/PathTemplateTest.java b/api-common-java/src/test/java/com/google/api/pathtemplate/PathTemplateTest.java index a11ddb3fc9..468814cf94 100644 --- a/api-common-java/src/test/java/com/google/api/pathtemplate/PathTemplateTest.java +++ b/api-common-java/src/test/java/com/google/api/pathtemplate/PathTemplateTest.java @@ -303,15 +303,26 @@ void complexResourceIdEqualsWildcard() { @Test @Disabled - //TODO: This test was passing erroneously, see https://github.com/googleapis/sdk-platform-java/issues/2778 + // TODO: This test was passing erroneously, see + // https://github.com/googleapis/sdk-platform-java/issues/2778 void complexResourceIdEqualsPathWildcard() { - Exception exception = Assertions.assertThrows(ValidationException.class, () -> PathTemplate.create("projects/{project=*}/zones/{zone_a=**}~{zone_b}")); - Assertions.assertEquals(String.format( - "parse error: wildcard path not allowed in complex ID resource '%s'", "zone_a"), exception.getMessage()); - - exception = Assertions.assertThrows(ValidationException.class, () -> PathTemplate.create("projects/{project=*}/zones/{zone_a}.{zone_b=**}")); - Assertions.assertEquals(String.format( - "parse error: wildcard path not allowed in complex ID resource '%s'", "zone_b"), exception.getMessage()); + Exception exception = + Assertions.assertThrows( + ValidationException.class, + () -> PathTemplate.create("projects/{project=*}/zones/{zone_a=**}~{zone_b}")); + Assertions.assertEquals( + String.format( + "parse error: wildcard path not allowed in complex ID resource '%s'", "zone_a"), + exception.getMessage()); + + exception = + Assertions.assertThrows( + ValidationException.class, + () -> PathTemplate.create("projects/{project=*}/zones/{zone_a}.{zone_b=**}")); + Assertions.assertEquals( + String.format( + "parse error: wildcard path not allowed in complex ID resource '%s'", "zone_b"), + exception.getMessage()); } @Test @@ -332,35 +343,50 @@ void complexResourceIdMissingMatches() { @Test void complexResourceIdNoSeparator() { - Exception exception = Assertions.assertThrows(ValidationException.class, () -> PathTemplate.create("projects/{project}/zones/{zone_a}{zone_b}")); - Assertions.assertEquals(String.format( - "parse error: missing or 2+ consecutive delimiter characters in '%s'", - "{zone_a}{zone_b}"), exception.getMessage()); - - exception = Assertions.assertThrows(ValidationException.class, () -> PathTemplate.create("projects/{project}/zones/{zone_a}_{zone_b}{zone_c}")); - Assertions.assertEquals(String.format( - "parse error: missing or 2+ consecutive delimiter characters in '%s'", - "{zone_a}_{zone_b}{zone_c}"), exception.getMessage()); + Exception exception = + Assertions.assertThrows( + ValidationException.class, + () -> PathTemplate.create("projects/{project}/zones/{zone_a}{zone_b}")); + Assertions.assertEquals( + String.format( + "parse error: missing or 2+ consecutive delimiter characters in '%s'", + "{zone_a}{zone_b}"), + exception.getMessage()); + + exception = + Assertions.assertThrows( + ValidationException.class, + () -> PathTemplate.create("projects/{project}/zones/{zone_a}_{zone_b}{zone_c}")); + Assertions.assertEquals( + String.format( + "parse error: missing or 2+ consecutive delimiter characters in '%s'", + "{zone_a}_{zone_b}{zone_c}"), + exception.getMessage()); } @Disabled - // TODO: This test was passing erroneously, see https://github.com/googleapis/sdk-platform-java/issues/2776 + // TODO: This test was passing erroneously, see + // https://github.com/googleapis/sdk-platform-java/issues/2776 @ParameterizedTest @MethodSource("invalidDelimiters") void complexResourceIdInvalidDelimiter(String invalidDelimiter) { - ValidationException exception = Assertions.assertThrows(ValidationException.class, () -> - PathTemplate.create(String.format("projects/{project=*}/zones/{zone_a}%s{zone_b}", invalidDelimiter)) - ); - Assertions.assertEquals( - String.format( - "parse error: invalid complex resource ID delimiter character in '%s'", - String.format("zone_a}%s{zone_b}", invalidDelimiter)), - exception.getMessage() - ); - } - static Stream invalidDelimiters() { - return Stream.of("|", "!", "@", "a", "1", ",", "{", ")"); - } + ValidationException exception = + Assertions.assertThrows( + ValidationException.class, + () -> + PathTemplate.create( + String.format( + "projects/{project=*}/zones/{zone_a}%s{zone_b}", invalidDelimiter))); + Assertions.assertEquals( + String.format( + "parse error: invalid complex resource ID delimiter character in '%s'", + String.format("zone_a}%s{zone_b}", invalidDelimiter)), + exception.getMessage()); + } + + static Stream invalidDelimiters() { + return Stream.of("|", "!", "@", "a", "1", ",", "{", ")"); + } @Test void complexResourceIdMixedSeparators() { @@ -406,9 +432,10 @@ void collectionWildcardMatchingInParent() { @Test void collectionWildcardMatchingInvalid() { - ValidationException exception = Assertions.assertThrows(ValidationException.class, () -> - PathTemplate.create("v1/publishers/{publisher}/books/-") - ); + ValidationException exception = + Assertions.assertThrows( + ValidationException.class, + () -> PathTemplate.create("v1/publishers/{publisher}/books/-")); }; @Test @@ -474,83 +501,76 @@ void complexResourcePathTemplateVariables() { @Test void complexResourceBasicInvalidIds() { - ValidationException exception = Assertions.assertThrows(ValidationException.class, () -> - PathTemplate.create("projects/*/zones/~{zone_a}") - ); + ValidationException exception = + Assertions.assertThrows( + ValidationException.class, () -> PathTemplate.create("projects/*/zones/~{zone_a}")); Assertions.assertEquals( String.format("parse error: invalid begin or end character in '%s'", "~{zone_a}"), - exception.getMessage() - ); - exception = Assertions.assertThrows(ValidationException.class, () -> - PathTemplate.create("projects/*/zones/{zone_a}~") - ); + exception.getMessage()); + exception = + Assertions.assertThrows( + ValidationException.class, () -> PathTemplate.create("projects/*/zones/{zone_a}~")); Assertions.assertEquals( String.format("parse error: invalid begin or end character in '%s'", "{zone_a}~"), - exception.getMessage() - ); - exception = Assertions.assertThrows(ValidationException.class, () -> - PathTemplate.create("projects/*/zones/.{zone_a}") - ); + exception.getMessage()); + exception = + Assertions.assertThrows( + ValidationException.class, () -> PathTemplate.create("projects/*/zones/.{zone_a}")); Assertions.assertEquals( String.format("parse error: invalid begin or end character in '%s'", ".{zone_a}"), - exception.getMessage() - ); - exception = Assertions.assertThrows(ValidationException.class, () -> - PathTemplate.create("projects/*/zones/{zone_a}.") - ); + exception.getMessage()); + exception = + Assertions.assertThrows( + ValidationException.class, () -> PathTemplate.create("projects/*/zones/{zone_a}.")); Assertions.assertEquals( String.format("parse error: invalid begin or end character in '%s'", "{zone_a}."), - exception.getMessage() - ); - exception = Assertions.assertThrows(ValidationException.class, () -> - PathTemplate.create("projects/*/zones/-{zone_a}") - ); + exception.getMessage()); + exception = + Assertions.assertThrows( + ValidationException.class, () -> PathTemplate.create("projects/*/zones/-{zone_a}")); Assertions.assertEquals( String.format("parse error: invalid begin or end character in '%s'", "-{zone_a}"), - exception.getMessage() - ); - exception = Assertions.assertThrows(ValidationException.class, () -> - PathTemplate.create("projects/*/zones/{zone_a}-") - ); + exception.getMessage()); + exception = + Assertions.assertThrows( + ValidationException.class, () -> PathTemplate.create("projects/*/zones/{zone_a}-")); Assertions.assertEquals( String.format("parse error: invalid begin or end character in '%s'", "{zone_a}-"), - exception.getMessage() - ); - exception = Assertions.assertThrows(ValidationException.class, () -> - PathTemplate.create("projects/*/zones/_{zone_a}") - ); + exception.getMessage()); + exception = + Assertions.assertThrows( + ValidationException.class, () -> PathTemplate.create("projects/*/zones/_{zone_a}")); Assertions.assertEquals( String.format("parse error: invalid begin or end character in '%s'", "_{zone_a}"), - exception.getMessage() - ); - exception = Assertions.assertThrows(ValidationException.class, () -> - PathTemplate.create("projects/*/zones/{zone_a}_") - ); + exception.getMessage()); + exception = + Assertions.assertThrows( + ValidationException.class, () -> PathTemplate.create("projects/*/zones/{zone_a}_")); Assertions.assertEquals( String.format("parse error: invalid begin or end character in '%s'", "{zone_a}_"), - exception.getMessage() - ); - + exception.getMessage()); } @Test void complexResourceMultipleDelimiters() { - ValidationException exception = Assertions.assertThrows(ValidationException.class, () -> - PathTemplate.create("projects/*/zones/{zone_a}~.{zone_b}") - ); + ValidationException exception = + Assertions.assertThrows( + ValidationException.class, + () -> PathTemplate.create("projects/*/zones/{zone_a}~.{zone_b}")); Assertions.assertEquals( - String.format( "parse error: missing or 2+ consecutive delimiter characters in '%s'", + String.format( + "parse error: missing or 2+ consecutive delimiter characters in '%s'", "{zone_a}~.{zone_b}"), - exception.getMessage() - ); - exception = Assertions.assertThrows(ValidationException.class, () -> - PathTemplate.create("projects/*/zones/{zone_a}~{zone_b}..{zone_c}") - ); + exception.getMessage()); + exception = + Assertions.assertThrows( + ValidationException.class, + () -> PathTemplate.create("projects/*/zones/{zone_a}~{zone_b}..{zone_c}")); Assertions.assertEquals( - String.format("parse error: missing or 2+ consecutive delimiter characters in '%s'", + String.format( + "parse error: missing or 2+ consecutive delimiter characters in '%s'", "{zone_a}~{zone_b}..{zone_c}"), - exception.getMessage() - ); + exception.getMessage()); String pathString = "projects/project_123/zones/lorum~ipsum"; PathTemplate template = PathTemplate.create("projects/*/zones/{zone_.~-a}~{zone_b}"); template.validate(pathString, ""); @@ -578,13 +598,11 @@ void validateFailure() { String templateString = "buckets/*/objects/*"; String pathString = "buckets/bucket/invalid/object"; PathTemplate template = PathTemplate.create(templateString); - ValidationException exception = Assertions.assertThrows(ValidationException.class, () -> - template.validate(pathString, "") - ); + ValidationException exception = + Assertions.assertThrows(ValidationException.class, () -> template.validate(pathString, "")); Assertions.assertEquals( String.format(": Parameter \"%s\" must be in the form \"%s\"", pathString, templateString), - exception.getMessage() - ); + exception.getMessage()); } @Test @@ -602,13 +620,12 @@ void validateMatchFailure() { String templateString = "buckets/*/objects/*"; String pathString = "buckets/bucket/invalid/object"; PathTemplate template = PathTemplate.create(templateString); - ValidationException exception = Assertions.assertThrows(ValidationException.class, () -> - template.validatedMatch(pathString, "") - ); + ValidationException exception = + Assertions.assertThrows( + ValidationException.class, () -> template.validatedMatch(pathString, "")); Assertions.assertEquals( String.format(": Parameter \"%s\" must be in the form \"%s\"", pathString, templateString), - exception.getMessage() - ); + exception.getMessage()); } // Instantiate @@ -638,9 +655,9 @@ void instantiateNotEscapeForUnboundedWildcard() { @Test void instantiateFailWhenTooFewVariables() { PathTemplate template = PathTemplate.create("buckets/*/*/*/objects/*"); - ValidationException exception = Assertions.assertThrows(ValidationException.class, () -> - template.instantiate("$0", "f", "1", "o") - ); + ValidationException exception = + Assertions.assertThrows( + ValidationException.class, () -> template.instantiate("$0", "f", "1", "o")); } @Test @@ -668,13 +685,12 @@ void instantiateWithHostName() { @Test void instantiateEscapeUnsafeCharNoEncoding() { PathTemplate template = PathTemplate.createWithoutUrlEncoding("buckets/*/objects/*"); - ValidationException exception = Assertions.assertThrows(ValidationException.class, () -> - template.instantiate("$0", "f/o/o", "$1", "b/a/r") - ); + ValidationException exception = + Assertions.assertThrows( + ValidationException.class, () -> template.instantiate("$0", "f/o/o", "$1", "b/a/r")); Assertions.assertEquals( String.format("Invalid character \"/\" in path section \"f/o/o\"."), - exception.getMessage() - ); + exception.getMessage()); } @Test @@ -788,19 +804,19 @@ void instantiateWithASegmentStartsWithADelimiter() { @Test void instantiateWithASegmentContainingComplexResourceNamesAndStartsWithADelimiter() { - ValidationException exception = Assertions.assertThrows(ValidationException.class, () -> - PathTemplate.create( - "v1beta1/{parent=projects/*/locations/*/clusters/*}/.{well}-{known}/openid-configuration") - ); + ValidationException exception = + Assertions.assertThrows( + ValidationException.class, + () -> + PathTemplate.create( + "v1beta1/{parent=projects/*/locations/*/clusters/*}/.{well}-{known}/openid-configuration")); Assertions.assertEquals( String.format("parse error: invalid begin or end character in '%s'", ".{well}-{known}"), - exception.getMessage() - ); + exception.getMessage()); } @Test - void - instantiateWithASegmentContainingNoComplexResourceNamesAndStartsWithMultipleDelimiters() { + void instantiateWithASegmentContainingNoComplexResourceNamesAndStartsWithMultipleDelimiters() { PathTemplate pathTemplate = PathTemplate.create( "v1beta1/{parent=projects/*/locations/*/clusters/*}/.-~well-known/openid-configuration"); @@ -811,13 +827,13 @@ void instantiateWithASegmentContainingComplexResourceNamesAndStartsWithADelimite @Test void instantiateWithASegmentOnlyContainingOneDelimiter() { - ValidationException exception = Assertions.assertThrows(ValidationException.class, () -> - PathTemplate.create("v1/publishers/{publisher}/books/.") - ); + ValidationException exception = + Assertions.assertThrows( + ValidationException.class, + () -> PathTemplate.create("v1/publishers/{publisher}/books/.")); Assertions.assertEquals( String.format("parse error: invalid begin or end character in '%s'", "."), - exception.getMessage() - ); + exception.getMessage()); } @Test @@ -839,19 +855,19 @@ void instantiateWithASegmentEndsWithADelimiter() { @Test void instantiateWithASegmentContainingComplexResourceNamesAndEndsWithADelimiter() { - ValidationException exception = Assertions.assertThrows(ValidationException.class, () -> - PathTemplate.create( - "v1beta1/{parent=projects/*/locations/*/clusters/*}/{well}-{known}./openid-configuration") - ); + ValidationException exception = + Assertions.assertThrows( + ValidationException.class, + () -> + PathTemplate.create( + "v1beta1/{parent=projects/*/locations/*/clusters/*}/{well}-{known}./openid-configuration")); Assertions.assertEquals( String.format("parse error: invalid begin or end character in '%s'", "{well}-{known}."), - exception.getMessage() - ); + exception.getMessage()); } @Test - void - instantiateWithASegmentContainingNoComplexResourceNamesAndEndsWithMultipleDelimiters() { + void instantiateWithASegmentContainingNoComplexResourceNamesAndEndsWithMultipleDelimiters() { PathTemplate pathTemplate = PathTemplate.create( "v1beta1/{parent=projects/*/locations/*/clusters/*}/well-known.-~/openid-configuration"); @@ -865,9 +881,8 @@ void instantiateWithASegmentContainingComplexResourceNamesAndEndsWithADelimiter( @Test void testMultiplePathWildcardFailure() { - Assertions.assertThrows(IllegalArgumentException.class, () -> - PathTemplate.create("bar/**/{name=foo/**}:verb") - ); + Assertions.assertThrows( + IllegalArgumentException.class, () -> PathTemplate.create("bar/**/{name=foo/**}:verb")); } @Test diff --git a/api-common-java/src/test/java/com/google/api/pathtemplate/TemplatedResourceNameTest.java b/api-common-java/src/test/java/com/google/api/pathtemplate/TemplatedResourceNameTest.java index bb3fe90d5d..d086a81f44 100644 --- a/api-common-java/src/test/java/com/google/api/pathtemplate/TemplatedResourceNameTest.java +++ b/api-common-java/src/test/java/com/google/api/pathtemplate/TemplatedResourceNameTest.java @@ -32,6 +32,7 @@ import com.google.common.truth.Truth; import org.junit.jupiter.api.Test; + /** * Tests for {@link TemplatedResourceName}. As resource names are mostly a wrapper around path * templates, not much needs to be done here. diff --git a/api-common-java/src/test/java/com/google/api/resourcenames/UntypedResourceNameTest.java b/api-common-java/src/test/java/com/google/api/resourcenames/UntypedResourceNameTest.java index bbe331ff0b..eb00a16eaa 100644 --- a/api-common-java/src/test/java/com/google/api/resourcenames/UntypedResourceNameTest.java +++ b/api-common-java/src/test/java/com/google/api/resourcenames/UntypedResourceNameTest.java @@ -38,7 +38,6 @@ import org.junit.jupiter.api.Test; /** Tests for {@link UntypedResourceNameTest}. */ - public class UntypedResourceNameTest { private static final String NAME_STRING = "sunshine"; private static final String EMPTY_STRING = "";