@Test
public void testOnReceiveWhenIntentNotNull() {

    CTGeofenceReceiver receiver = new CTGeofenceReceiver();
    CTGeofenceReceiver spy = Mockito.spy(receiver);
    when(spy.goAsync()).thenReturn(pendingResult);
    final Boolean[] isFinished = {false};
    doAnswer(new Answer() {
        @Override
        public Object answer(InvocationOnMock invocation) throws Throwable {
            isFinished[0] = true;
            return null;
        }
    }).when(pendingResult).finish();
    Intent intent = new Intent();
    spy.onReceive(application, intent);
    await().until(new Callable<Boolean>() {
        @Override
        public Boolean call() throws Exception {
            return isFinished[0];
        }
    });
    verify(pendingResult).finish();
}