Skip to content
This repository has been archived by the owner on Sep 26, 2023. It is now read-only.

Commit

Permalink
chore: remove usages of internal Mockito APIs (#1578)
Browse files Browse the repository at this point in the history
  • Loading branch information
cushon committed Dec 10, 2021
1 parent 65aed62 commit 762bdc7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
Expand Up @@ -36,11 +36,11 @@

import com.google.api.gax.rpc.StatusCode.Code;
import com.google.api.gax.rpc.testing.FakeStatusCode;
import com.google.common.collect.Sets;
import java.util.Collections;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.mockito.internal.util.collections.Sets;

@RunWith(JUnit4.class)
public class ApiResultRetryAlgorithmTest {
Expand Down Expand Up @@ -78,7 +78,8 @@ public void testShouldRetryWithContextWithoutRetryableCodes() {
public void testShouldRetryWithContextWithRetryableCodes() {
ApiCallContext context = mock(ApiCallContext.class);
when(context.getRetryableCodes())
.thenReturn(Sets.newSet(StatusCode.Code.DEADLINE_EXCEEDED, StatusCode.Code.UNAVAILABLE));
.thenReturn(
Sets.newHashSet(StatusCode.Code.DEADLINE_EXCEEDED, StatusCode.Code.UNAVAILABLE));

StatusCode unavailable = mock(StatusCode.class);
when(unavailable.getCode()).thenReturn(Code.UNAVAILABLE);
Expand Down
14 changes: 7 additions & 7 deletions gax/src/test/java/com/google/api/gax/rpc/RetryingTest.java
Expand Up @@ -44,6 +44,7 @@
import com.google.api.gax.rpc.testing.FakeStatusCode;
import com.google.api.gax.rpc.testing.FakeTransportChannel;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Sets;
import com.google.common.truth.Truth;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.UncheckedExecutionException;
Expand All @@ -54,7 +55,6 @@
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.mockito.Mockito;
import org.mockito.internal.util.collections.Sets;
import org.threeten.bp.Duration;

@RunWith(JUnit4.class)
Expand Down Expand Up @@ -138,7 +138,7 @@ public void retryUsingContext() {
FAILING_RETRY_SETTINGS,
FakeCallContext.createDefault()
.withRetrySettings(FAST_RETRY_SETTINGS)
.withRetryableCodes(Sets.newSet(StatusCode.Code.INTERNAL)));
.withRetryableCodes(Sets.newHashSet(StatusCode.Code.INTERNAL)));
}

@Test(expected = ApiException.class)
Expand Down Expand Up @@ -179,7 +179,7 @@ public void retryUsingContextTotalTimeoutExceeded() {
FAILING_RETRY_SETTINGS,
FakeCallContext.createDefault()
.withRetrySettings(retrySettings)
.withRetryableCodes(Sets.newSet(StatusCode.Code.INTERNAL)));
.withRetryableCodes(Sets.newHashSet(StatusCode.Code.INTERNAL)));
fail("missing expected exception");
} catch (ApiException e) {
assertEquals(Code.INTERNAL, e.getStatusCode().getCode());
Expand Down Expand Up @@ -212,7 +212,7 @@ public void retryUsingContextMaxAttemptsExceeded() {
FAILING_RETRY_SETTINGS,
FakeCallContext.createDefault()
.withRetrySettings(FAST_RETRY_SETTINGS.toBuilder().setMaxAttempts(2).build())
.withRetryableCodes(Sets.newSet(StatusCode.Code.INTERNAL)));
.withRetryableCodes(Sets.newHashSet(StatusCode.Code.INTERNAL)));
fail("missing expected exception");
} catch (ApiException e) {
assertEquals(Code.INTERNAL, e.getStatusCode().getCode());
Expand Down Expand Up @@ -244,7 +244,7 @@ public void retryUsingContextWithinMaxAttempts() {
FAILING_RETRY_SETTINGS,
FakeCallContext.createDefault()
.withRetrySettings(FAST_RETRY_SETTINGS.toBuilder().setMaxAttempts(3).build())
.withRetryableCodes(Sets.newSet(StatusCode.Code.INTERNAL)));
.withRetryableCodes(Sets.newHashSet(StatusCode.Code.INTERNAL)));
}

@Test
Expand Down Expand Up @@ -278,7 +278,7 @@ public void retryUsingContextWithOnlyMaxAttempts() {
FAILING_RETRY_SETTINGS,
FakeCallContext.createDefault()
.withRetrySettings(retrySettings)
.withRetryableCodes(Sets.newSet(StatusCode.Code.INTERNAL)));
.withRetryableCodes(Sets.newHashSet(StatusCode.Code.INTERNAL)));
Mockito.verify(callInt, Mockito.times(3))
.futureCall(Mockito.<Integer>any(), Mockito.<ApiCallContext>any());
}
Expand Down Expand Up @@ -363,7 +363,7 @@ public void retryUsingContextNoRecover() {
FakeCallContext.createDefault()
.withRetrySettings(FAST_RETRY_SETTINGS)
.withRetryableCodes(
Sets.newSet(Code.UNAVAILABLE, Code.DEADLINE_EXCEEDED, Code.UNKNOWN)));
Sets.newHashSet(Code.UNAVAILABLE, Code.DEADLINE_EXCEEDED, Code.UNKNOWN)));
Assert.fail("Callable should have thrown an exception");
} catch (ApiException expected) {
Truth.assertThat(expected).isSameInstanceAs(throwable);
Expand Down

0 comments on commit 762bdc7

Please sign in to comment.