use of org.mockito.invocation.InvocationOnMock in project glide by bumptech.
the class EngineJobTest method testRemovingCallbackDuringOnExceptionIsIgnoredIfCallbackHasAlreadyBeenCalled.
@Test
public void testRemovingCallbackDuringOnExceptionIsIgnoredIfCallbackHasAlreadyBeenCalled() {
harness = new EngineJobHarness();
final EngineJob<Object> job = harness.getJob();
final ResourceCallback cb = mock(ResourceCallback.class);
doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocationOnMock) throws Throwable {
job.removeCallback(cb);
return null;
}
}).when(cb).onLoadFailed(any(GlideException.class));
GlideException exception = new GlideException("test");
job.addCallback(cb);
job.start(harness.decodeJob);
job.onLoadFailed(exception);
verify(cb, times(1)).onLoadFailed(eq(exception));
}
use of org.mockito.invocation.InvocationOnMock in project glide by bumptech.
the class EngineJobTest method testNotifiesNewCallbackOfResourceIfCallbackIsAddedDuringOnResourceReady.
@Test
public void testNotifiesNewCallbackOfResourceIfCallbackIsAddedDuringOnResourceReady() {
final EngineJob<Object> job = harness.getJob();
final ResourceCallback existingCallback = mock(ResourceCallback.class);
final ResourceCallback newCallback = mock(ResourceCallback.class);
doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocationOnMock) throws Throwable {
job.addCallback(newCallback);
return null;
}
}).when(existingCallback).onResourceReady(anyResource(), isADataSource());
job.addCallback(existingCallback);
job.start(harness.decodeJob);
job.onResourceReady(harness.resource, harness.dataSource);
verify(newCallback).onResourceReady(eq(harness.engineResource), eq(harness.dataSource));
}
use of org.mockito.invocation.InvocationOnMock in project glide by bumptech.
the class EngineJobTest method testRemovingCallbackDuringOnResourceReadyPreventsResourceFromBeingAcquiredForCallback.
@Test
public void testRemovingCallbackDuringOnResourceReadyPreventsResourceFromBeingAcquiredForCallback() {
final EngineJob<Object> job = harness.getJob();
final ResourceCallback notYetCalled = mock(ResourceCallback.class);
doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocationOnMock) throws Throwable {
job.removeCallback(notYetCalled);
return null;
}
}).when(harness.cb).onResourceReady(anyResource(), isADataSource());
job.addCallback(notYetCalled);
job.start(harness.decodeJob);
job.onResourceReady(harness.resource, harness.dataSource);
// Once for notifying, once for called.
verify(harness.engineResource, times(2)).acquire();
}
use of org.mockito.invocation.InvocationOnMock in project glide by bumptech.
the class EngineJobTest method testRemovingCallbackDuringOnResourceReadyPreventsCallbackFromBeingCalledIfNotYetCalled.
@Test
public void testRemovingCallbackDuringOnResourceReadyPreventsCallbackFromBeingCalledIfNotYetCalled() {
final EngineJob<Object> job = harness.getJob();
final ResourceCallback notYetCalled = mock(ResourceCallback.class);
doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocationOnMock) throws Throwable {
job.removeCallback(notYetCalled);
return null;
}
}).when(harness.cb).onResourceReady(anyResource(), isADataSource());
job.addCallback(notYetCalled);
job.start(harness.decodeJob);
job.onResourceReady(harness.resource, harness.dataSource);
verify(notYetCalled, never()).onResourceReady(anyResource(), isADataSource());
}
use of org.mockito.invocation.InvocationOnMock in project spring-security by spring-projects.
the class WebExpressionVoterTests method grantsAccessIfExpressionIsTrueDeniesIfFalse.
@Test
public void grantsAccessIfExpressionIsTrueDeniesIfFalse() {
WebExpressionVoter voter = new WebExpressionVoter();
Expression ex = mock(Expression.class);
EvaluationContextPostProcessor postProcessor = mock(EvaluationContextPostProcessor.class);
when(postProcessor.postProcess(any(EvaluationContext.class), any(FilterInvocation.class))).thenAnswer(new Answer<EvaluationContext>() {
public EvaluationContext answer(InvocationOnMock invocation) throws Throwable {
return invocation.getArgumentAt(0, EvaluationContext.class);
}
});
WebExpressionConfigAttribute weca = new WebExpressionConfigAttribute(ex, postProcessor);
EvaluationContext ctx = mock(EvaluationContext.class);
SecurityExpressionHandler eh = mock(SecurityExpressionHandler.class);
FilterInvocation fi = new FilterInvocation("/path", "GET");
voter.setExpressionHandler(eh);
when(eh.createEvaluationContext(user, fi)).thenReturn(ctx);
when(ex.getValue(ctx, Boolean.class)).thenReturn(Boolean.TRUE).thenReturn(Boolean.FALSE);
ArrayList attributes = new ArrayList();
attributes.addAll(SecurityConfig.createList("A", "B", "C"));
attributes.add(weca);
assertThat(voter.vote(user, fi, attributes)).isEqualTo(AccessDecisionVoter.ACCESS_GRANTED);
// Second time false
assertThat(voter.vote(user, fi, attributes)).isEqualTo(AccessDecisionVoter.ACCESS_DENIED);
}
Aggregations