Skip to content

Commit

Permalink
Merge pull request #3765 from sjudd:update_mockito_2_23_4
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 258830209
  • Loading branch information
glide-copybara-robot committed Jul 18, 2019
2 parents 338ca69 + 288866e commit 8258d3c
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 29 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ DAGGER_VERSION=2.15

JUNIT_VERSION=4.13-SNAPSHOT
# Matches the version in Google.
MOCKITO_VERSION=1.9.5
MOCKITO_VERSION=2.23.4
MOCKITO_ANDROID_VERSION=2.24.0
ROBOLECTRIC_VERSION=4.3-beta-1
MOCKWEBSERVER_VERSION=3.0.0-RC1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public void setUp() {
when(factory.buildDecoder(any(GifDecoder.BitmapProvider.class))).thenReturn(decoder);
when(factory.buildParser()).thenReturn(parser);
when(factory.buildEncoder()).thenReturn(gifEncoder);
when(factory.buildFrameResource(any(Bitmap.class), any(BitmapPool.class)))
when(factory.buildFrameResource(anyBitmapOrNull(), any(BitmapPool.class)))
.thenReturn(frameResource);

// TODO Util.anyResource once Util is moved to testutil module (remove unchecked above!)
Expand Down Expand Up @@ -178,7 +178,7 @@ public void testAdvancesDecoderBeforeAttemptingToGetFirstFrame() {
@Test
public void testSetsDelayOnEncoderAfterAddingFrame() {
when(gifEncoder.start(any(OutputStream.class))).thenReturn(true);
when(gifEncoder.addFrame(any(Bitmap.class))).thenReturn(true);
when(gifEncoder.addFrame(anyBitmapOrNull())).thenReturn(true);

when(decoder.getFrameCount()).thenReturn(1);
when(decoder.getNextFrame()).thenReturn(Bitmap.createBitmap(100, 100, Bitmap.Config.RGB_565));
Expand All @@ -191,7 +191,7 @@ public void testSetsDelayOnEncoderAfterAddingFrame() {

InOrder order = inOrder(gifEncoder, decoder);
order.verify(decoder).advance();
order.verify(gifEncoder).addFrame(any(Bitmap.class));
order.verify(gifEncoder).addFrame(anyBitmapOrNull());
order.verify(gifEncoder).setDelay(eq(expectedDelay));
order.verify(decoder).advance();
}
Expand All @@ -218,7 +218,7 @@ public void testReturnsFalseIfAddingFrameFails() {
when(decoder.getNextFrame()).thenReturn(Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888));

when(gifEncoder.start(any(OutputStream.class))).thenReturn(true);
when(gifEncoder.addFrame(any(Bitmap.class))).thenReturn(false);
when(gifEncoder.addFrame(anyBitmapOrNull())).thenReturn(false);

assertFalse(encoder.encode(resource, file, options));
}
Expand Down Expand Up @@ -333,4 +333,8 @@ private String getEncodedData() {
private static Context anyContext() {
return any(Context.class);
}

private static Bitmap anyBitmapOrNull() {
return any();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public void testNewLoadIsNotStartedIfResourceIsActive() {

harness.doLoad();

verify(harness.job, never()).start(any(DecodeJob.class));
verify(harness.job, never()).start(anyDecodeJobOrNull());
}

@Test
Expand Down Expand Up @@ -250,7 +250,7 @@ public void testNewLoadIsNotStartedIfResourceIsCached() {

harness.doLoad();

verify(harness.job, never()).start(any(DecodeJob.class));
verify(harness.job, never()).start(anyDecodeJobOrNull());
}

@Test
Expand Down Expand Up @@ -460,7 +460,7 @@ public Object answer(InvocationOnMock invocationOnMock) {
}
})
.when(harness.job)
.start(any(DecodeJob.class));
.start(anyDecodeJobOrNull());
harness.doLoad();
harness.doLoad();
verify(harness.cb).onResourceReady(any(Resource.class), eq(DataSource.MEMORY_CACHE));
Expand All @@ -479,7 +479,7 @@ public Object answer(InvocationOnMock invocationOnMock) {
}
})
.when(harness.job)
.start(any(DecodeJob.class));
.start(anyDecodeJobOrNull());
harness.doLoad();
harness.getEngine().onResourceReleased(harness.cacheKey, harness.resource);
harness.doLoad();
Expand All @@ -495,8 +495,8 @@ public void load_withOnlyRetrieveFromCache_andPreviousNormalLoad_startsNewLoad()
harness.onlyRetrieveFromCache = true;
harness.doLoad();

verify(first).start(any(DecodeJob.class));
verify(second).start(any(DecodeJob.class));
verify(first).start(anyDecodeJobOrNull());
verify(second).start(anyDecodeJobOrNull());
}

@Test
Expand All @@ -509,8 +509,8 @@ public void load_withNormalLoad_afterPreviousRetrieveFromCache_startsNewLoad() {
harness.onlyRetrieveFromCache = false;
harness.doLoad();

verify(first).start(any(DecodeJob.class));
verify(second).start(any(DecodeJob.class));
verify(first).start(anyDecodeJobOrNull());
verify(second).start(anyDecodeJobOrNull());
}

@Test
Expand All @@ -528,8 +528,8 @@ public void load_afterFinishedOnlyRetrieveFromCache_withPendingNormal_doesNotSta
harness.onlyRetrieveFromCache = false;
harness.doLoad();

verify(firstNormal).start(any(DecodeJob.class));
verify(secondNormal, never()).start(any(DecodeJob.class));
verify(firstNormal).start(anyDecodeJobOrNull());
verify(secondNormal, never()).start(anyDecodeJobOrNull());
}

@Test
Expand All @@ -547,8 +547,8 @@ public void load_afterCancelledOnlyRetrieveFromCache_withPendingNormal_doesNotSt
harness.onlyRetrieveFromCache = false;
harness.doLoad();

verify(firstNormal).start(any(DecodeJob.class));
verify(secondNormal, never()).start(any(DecodeJob.class));
verify(firstNormal).start(anyDecodeJobOrNull());
verify(secondNormal, never()).start(anyDecodeJobOrNull());
}

@Test
Expand All @@ -560,7 +560,7 @@ public void load_withOnlyRetrieveFromCache_withOtherRetrieveFromCachePending_doe
harness.job = second;
harness.doLoad();

verify(second, never()).start(any(DecodeJob.class));
verify(second, never()).start(anyDecodeJobOrNull());
}

@Test
Expand All @@ -573,7 +573,7 @@ public void load_withOnlyRetrieveFromCache_afterPreviousFinishedOnlyFromCacheLoa
harness.job = second;
harness.doLoad();

verify(second).start(any(DecodeJob.class));
verify(second).start(anyDecodeJobOrNull());
}

@Test
Expand All @@ -586,7 +586,7 @@ public void load_withOnlyRetrieveFromCache_afterPreviousCancelledOnlyFromCacheLo
harness.job = second;
harness.doLoad();

verify(second).start(any(DecodeJob.class));
verify(second).start(anyDecodeJobOrNull());
}

@Test
Expand All @@ -599,7 +599,7 @@ public void onEngineJobComplete_withOldJobForKey_doesNotRemoveJob() {
harness.job = mock(EngineJob.class);
harness.doLoad();

verify(harness.job, never()).start(any(DecodeJob.class));
verify(harness.job, never()).start(anyDecodeJobOrNull());
}

@Test
Expand All @@ -610,7 +610,7 @@ public void onEngineJobCancelled_withOldJobForKey_doesNotRemoveJob() {
harness.job = mock(EngineJob.class);
harness.doLoad();

verify(harness.job, never()).start(any(DecodeJob.class));
verify(harness.job, never()).start(anyDecodeJobOrNull());
}

@Test
Expand All @@ -624,7 +624,7 @@ public void onEngineJobComplete_withOnlyRetrieveFromCacheAndOldJobForKey_doesNot
harness.job = mock(EngineJob.class);
harness.doLoad();

verify(harness.job, never()).start(any(DecodeJob.class));
verify(harness.job, never()).start(anyDecodeJobOrNull());
}

@Test
Expand All @@ -636,7 +636,12 @@ public void onEngineJobCancelled_withOnlyRetrieveFromCacheAndOldJobForKey_doesNo
harness.job = mock(EngineJob.class);
harness.doLoad();

verify(harness.job, never()).start(any(DecodeJob.class));
verify(harness.job, never()).start(anyDecodeJobOrNull());
}

@SuppressWarnings({"unchecked", "rawtypes"})
private static DecodeJob anyDecodeJobOrNull() {
return any();
}

private static class EngineTestHarness {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public void clear_notifiesTarget() {
SingleRequest<List> request = builder.build();
request.clear();

verify(builder.target).onLoadCleared(any(Drawable.class));
verify(builder.target).onLoadCleared(anyDrawableOrNull());
}

@Test
Expand All @@ -175,7 +175,7 @@ public void testDoesNotNotifyTargetTwiceIfClearedTwiceInARow() {
request.clear();
request.clear();

verify(builder.target, times(1)).onLoadCleared(any(Drawable.class));
verify(builder.target, times(1)).onLoadCleared(anyDrawableOrNull());
}

@Test
Expand Down Expand Up @@ -1015,6 +1015,10 @@ SingleRequest<List> build() {
}
}

private static Drawable anyDrawableOrNull() {
return any();
}

// TODO do we want to move these to Util?
@SuppressWarnings("unchecked")
private static <T> Transition<T> mockTransition() {
Expand All @@ -1032,7 +1036,7 @@ private static GlideException isAGlideException() {

@SuppressWarnings("unchecked")
private static <T> Transition<T> anyTransition() {
return any(Transition.class);
return any();
}

private static Executor anyExecutor() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,13 @@ public void testAlwaysReturnsFalse() {
@Test
public void testStartsAnimationOnAnimate() {
Animation animation = mock(Animation.class);
when(viewTransitionAnimationFactory.build(any(Context.class))).thenReturn(animation);
when(viewTransitionAnimationFactory.build(anyContextOrNull())).thenReturn(animation);
viewAnimation.transition(null, adapter);
verify(view).clearAnimation();
verify(view).startAnimation(eq(animation));
}

private static Context anyContextOrNull() {
return any();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void testFactoryReturnsActualAnimationIfNotIsFromMemoryCacheAndIsFirstRes
factory.build(DataSource.DATA_DISK_CACHE, true /*isFirstResource*/);

Animation animation = mock(Animation.class);
when(viewTransitionAnimationFactory.build(any(Context.class))).thenReturn(animation);
when(viewTransitionAnimationFactory.build(anyContextOrNull())).thenReturn(animation);

Transition.ViewAdapter adapter = mock(Transition.ViewAdapter.class);
View view = mock(View.class);
Expand All @@ -59,4 +59,8 @@ public void testFactoryReturnsActualAnimationIfNotIsFromMemoryCacheAndIsFirstRes

verify(view).startAnimation(eq(animation));
}

private static Context anyContextOrNull() {
return any();
}
}

0 comments on commit 8258d3c

Please sign in to comment.