use of org.mockito.invocation.InvocationOnMock in project fresco by facebook.
the class JobSchedulerTest method setUp.
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mFakeClockForTime = new FakeClock();
mFakeClockForWorker = new FakeClock();
mFakeClockForScheduled = new FakeClock();
mFakeClockForTime.incrementBy(1000);
mFakeClockForWorker.incrementBy(1000);
mFakeClockForScheduled.incrementBy(1000);
PowerMockito.mockStatic(SystemClock.class);
when(SystemClock.uptimeMillis()).thenAnswer(new Answer<Long>() {
@Override
public Long answer(InvocationOnMock invocation) throws Throwable {
return mFakeClockForTime.now();
}
});
mTestExecutorService = new TestExecutorService(mFakeClockForWorker);
mTestScheduledExecutorService = new TestScheduledExecutorService(mFakeClockForScheduled);
PowerMockito.mockStatic(JobScheduler.JobStartExecutorSupplier.class);
when(JobScheduler.JobStartExecutorSupplier.get()).thenReturn(mTestScheduledExecutorService);
mTestJobRunnable = new TestJobRunnable();
mJobScheduler = new JobScheduler(mTestExecutorService, mTestJobRunnable, INTERVAL);
}
use of org.mockito.invocation.InvocationOnMock in project HikariCP by brettwooldridge.
the class MockDataSource method createMockConnection.
public static Connection createMockConnection() throws SQLException {
// Setup mock connection
final Connection mockConnection = mock(Connection.class);
// Autocommit is always true by default
when(mockConnection.getAutoCommit()).thenReturn(true);
// Handle Connection.createStatement()
Statement statement = mock(Statement.class);
when(mockConnection.createStatement()).thenReturn(statement);
when(mockConnection.createStatement(anyInt(), anyInt())).thenReturn(statement);
when(mockConnection.createStatement(anyInt(), anyInt(), anyInt())).thenReturn(statement);
when(mockConnection.isValid(anyInt())).thenReturn(true);
// Handle Connection.prepareStatement()
PreparedStatement mockPreparedStatement = mock(PreparedStatement.class);
when(mockConnection.prepareStatement(anyString())).thenReturn(mockPreparedStatement);
when(mockConnection.prepareStatement(anyString(), anyInt())).thenReturn(mockPreparedStatement);
when(mockConnection.prepareStatement(anyString(), any(int[].class))).thenReturn(mockPreparedStatement);
when(mockConnection.prepareStatement(anyString(), any(String[].class))).thenReturn(mockPreparedStatement);
when(mockConnection.prepareStatement(anyString(), anyInt(), anyInt())).thenReturn(mockPreparedStatement);
when(mockConnection.prepareStatement(anyString(), anyInt(), anyInt(), anyInt())).thenReturn(mockPreparedStatement);
doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
return null;
}
}).doNothing().when(mockPreparedStatement).setInt(anyInt(), anyInt());
ResultSet mockResultSet = mock(ResultSet.class);
when(mockPreparedStatement.executeQuery()).thenReturn(mockResultSet);
when(mockResultSet.getString(anyInt())).thenReturn("aString");
when(mockResultSet.next()).thenReturn(true);
// Handle Connection.prepareCall()
CallableStatement mockCallableStatement = mock(CallableStatement.class);
when(mockConnection.prepareCall(anyString())).thenReturn(mockCallableStatement);
when(mockConnection.prepareCall(anyString(), anyInt(), anyInt())).thenReturn(mockCallableStatement);
when(mockConnection.prepareCall(anyString(), anyInt(), anyInt(), anyInt())).thenReturn(mockCallableStatement);
return mockConnection;
}
use of org.mockito.invocation.InvocationOnMock in project glide by bumptech.
the class RequestManagerTest method setUp.
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
connectivityMonitor = mock(ConnectivityMonitor.class);
ConnectivityMonitorFactory factory = mock(ConnectivityMonitorFactory.class);
when(factory.build(isA(Context.class), isA(ConnectivityMonitor.ConnectivityListener.class))).thenAnswer(new Answer<ConnectivityMonitor>() {
@Override
public ConnectivityMonitor answer(InvocationOnMock invocation) throws Throwable {
connectivityListener = (ConnectivityListener) invocation.getArguments()[1];
return connectivityMonitor;
}
});
requestTracker = mock(RequestTracker.class);
manager = new RequestManager(Glide.get(RuntimeEnvironment.application), lifecycle, treeNode, requestTracker, factory);
}
use of org.mockito.invocation.InvocationOnMock in project glide by bumptech.
the class EngineKeyTest method testDiffersIfSignatureDiffers.
@Test
public void testDiffersIfSignatureDiffers() throws UnsupportedEncodingException, NoSuchAlgorithmException {
EngineKey first = harness.build();
Key signature = mock(Key.class);
doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocationOnMock) throws Throwable {
MessageDigest digest = (MessageDigest) invocationOnMock.getArguments()[0];
digest.update("signature".getBytes("UTF-8"));
return null;
}
}).when(signature).updateDiskCacheKey(any(MessageDigest.class));
harness.signature = signature;
EngineKey second = harness.build();
KeyAssertions.assertDifferent(first, second, false);
}
use of org.mockito.invocation.InvocationOnMock in project glide by bumptech.
the class EngineTest method testHandlesNonEngineResourcesFromCacheIfPresent.
@Test
public void testHandlesNonEngineResourcesFromCacheIfPresent() {
final Object expected = new Object();
@SuppressWarnings("rawtypes") Resource fromCache = mockResource();
when(fromCache.get()).thenReturn(expected);
when(harness.cache.remove(eq(harness.cacheKey))).thenReturn(fromCache);
doAnswer(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocationOnMock) throws Throwable {
Resource<?> resource = (Resource<?>) invocationOnMock.getArguments()[0];
assertEquals(expected, resource.get());
return null;
}
}).when(harness.cb).onResourceReady(anyResource(), isADataSource());
harness.doLoad();
verify(harness.cb).onResourceReady(anyResource(), isADataSource());
}
Aggregations