Я исправил это, создав обработчик в тестовом классе и передав его в тестовый класс:
public class AutoInstallPieForegroundServiceTest {
@Mock
private InertiaAppDao inertiaAppDao;
@Mock
private ChainOfTrustHelper chainOfTrustHelper;
@Mock
private ProvisionHelper provisionHelper;
@Mock
InertiaAppDataRepository inertiaAppDataRepository;
@Mock
private Handler mHandler;
@Mock
private Executor executor;
@Mock
private InertiaLogger inertiaLogger;
AutoInstallPieForegroundService autoInstallPieForegroundService;
@Before
public void setup() {
MockitoAnnotations.initMocks(this);
mHandler = spy(new Handler(getMainLooper()));
}
@Test
public void Should_CallProvisionHelper() {
when(chainOfTrustHelper.validate()).thenReturn(Job.Result.SUCCESS);
when(provisionHelper.provision()).thenReturn(Job.Result.SUCCESS);
autoInstallPieForegroundService = new AutoInstallPieForegroundService( inertiaLogger, mHandler, chainOfTrustHelper,
provisionHelper, inertiaAppDao);
autoInstallPieForegroundService.doContainerWork();
verify(provisionHelper, atLeastOnce()).provision();
}
@Test
public void Should_CallChainOfTrustHelper() {
when(chainOfTrustHelper.validate()).thenReturn(Job.Result.RESCHEDULE);
autoInstallPieForegroundService = new AutoInstallPieForegroundService( inertiaLogger, mHandler, chainOfTrustHelper,
provisionHelper, inertiaAppDao);
autoInstallPieForegroundService.doContainerWork();
verify(chainOfTrustHelper, atLeastOnce()).validate();
}
@Test
public void Should_CallInertiaAppDao() {
when(chainOfTrustHelper.validate()).thenReturn(Job.Result.RESCHEDULE);
autoInstallPieForegroundService = new AutoInstallPieForegroundService( inertiaLogger, mHandler, chainOfTrustHelper,
provisionHelper, inertiaAppDao);
autoInstallPieForegroundService.doContainerWork();
verify(inertiaAppDao, atLeastOnce()).getInstallCount();
}
}