<code> private final ExecutorService executorService = Executors.newSingleThreadExecutor();
</code>
<code> private final ExecutorService executorService = Executors.newSingleThreadExecutor();
</code>
private final ExecutorService executorService = Executors.newSingleThreadExecutor();
<code> private void subscribeToUpdates() {
this.disposable.add(
StepsUpdate
.observeOn(Schedulers.from(executorService))
.subscribe(
l -> {
Timber.d("Current step updated to: %s", l);
}));
}
</code>
<code> private void subscribeToUpdates() {
this.disposable.add(
StepsUpdate
.observeOn(Schedulers.from(executorService))
.subscribe(
l -> {
Timber.d("Current step updated to: %s", l);
}));
}
</code>
private void subscribeToUpdates() {
this.disposable.add(
StepsUpdate
.observeOn(Schedulers.from(executorService))
.subscribe(
l -> {
Timber.d("Current step updated to: %s", l);
}));
}
I am subscribing to StepsUpdate that emit steps when updated this code working fine.
<code>public class CurrStepCloudEmitterTest {
private CurrStepCloudEmitter currStepCloudEmitter;
private PublishSubject<String> StepsUpdate;
private static MockedStatic<Timber> mockTimber;
private ExecutorService mockExecutorService;
private TestScheduler testScheduler;
@Before
public void init() {
recipeStepsUpdate = PublishSubject.create();
mockExecutorService = Executors.newSingleThreadExecutor();
testScheduler = new TestScheduler();
RxJavaPlugins.setComputationSchedulerHandler(mockExecutorService -> testScheduler);
RxJavaPlugins.setIoSchedulerHandler(mockExecutorService -> testScheduler);
RxJavaPlugins.setNewThreadSchedulerHandler(mockExecutorService -> testScheduler);
RxJavaPlugins.setSingleSchedulerHandler(mockExecutorService -> testScheduler);
mockTimber = mockStatic(Timber.class);
}
@After
public void tearDown() {
mockTimber.close();
mockExecutorService.shutdownNow();
RxJavaPlugins.reset();
}
@Test
public void subscribeToStepUpdate()
throws InterruptedException {
CurrStepCloudEmitter =
new currStepCloudEmitter(StepsUpdate,
"66a72db19c828d00180c5750");
StepsUpdate.onNext("1");
testScheduler.triggerActions();
mockTimber.verify(() -> Timber.d("Current step updated to: %s", "1"), times(1));
}
</code>
<code>public class CurrStepCloudEmitterTest {
private CurrStepCloudEmitter currStepCloudEmitter;
private PublishSubject<String> StepsUpdate;
private static MockedStatic<Timber> mockTimber;
private ExecutorService mockExecutorService;
private TestScheduler testScheduler;
@Before
public void init() {
recipeStepsUpdate = PublishSubject.create();
mockExecutorService = Executors.newSingleThreadExecutor();
testScheduler = new TestScheduler();
RxJavaPlugins.setComputationSchedulerHandler(mockExecutorService -> testScheduler);
RxJavaPlugins.setIoSchedulerHandler(mockExecutorService -> testScheduler);
RxJavaPlugins.setNewThreadSchedulerHandler(mockExecutorService -> testScheduler);
RxJavaPlugins.setSingleSchedulerHandler(mockExecutorService -> testScheduler);
mockTimber = mockStatic(Timber.class);
}
@After
public void tearDown() {
mockTimber.close();
mockExecutorService.shutdownNow();
RxJavaPlugins.reset();
}
@Test
public void subscribeToStepUpdate()
throws InterruptedException {
CurrStepCloudEmitter =
new currStepCloudEmitter(StepsUpdate,
"66a72db19c828d00180c5750");
StepsUpdate.onNext("1");
testScheduler.triggerActions();
mockTimber.verify(() -> Timber.d("Current step updated to: %s", "1"), times(1));
}
</code>
public class CurrStepCloudEmitterTest {
private CurrStepCloudEmitter currStepCloudEmitter;
private PublishSubject<String> StepsUpdate;
private static MockedStatic<Timber> mockTimber;
private ExecutorService mockExecutorService;
private TestScheduler testScheduler;
@Before
public void init() {
recipeStepsUpdate = PublishSubject.create();
mockExecutorService = Executors.newSingleThreadExecutor();
testScheduler = new TestScheduler();
RxJavaPlugins.setComputationSchedulerHandler(mockExecutorService -> testScheduler);
RxJavaPlugins.setIoSchedulerHandler(mockExecutorService -> testScheduler);
RxJavaPlugins.setNewThreadSchedulerHandler(mockExecutorService -> testScheduler);
RxJavaPlugins.setSingleSchedulerHandler(mockExecutorService -> testScheduler);
mockTimber = mockStatic(Timber.class);
}
@After
public void tearDown() {
mockTimber.close();
mockExecutorService.shutdownNow();
RxJavaPlugins.reset();
}
@Test
public void subscribeToStepUpdate()
throws InterruptedException {
CurrStepCloudEmitter =
new currStepCloudEmitter(StepsUpdate,
"66a72db19c828d00180c5750");
StepsUpdate.onNext("1");
testScheduler.triggerActions();
mockTimber.verify(() -> Timber.d("Current step updated to: %s", "1"), times(1));
}
this is the test I am writing but giving error as
<code>Wanted but not invoked:
Timber.class.d(
"Current step updated to: %s",
"1"
);
-> at timber.log.Timber.d(Timber.java:38)
Actually, there were zero interactions with this mock.
</code>
<code>Wanted but not invoked:
Timber.class.d(
"Current step updated to: %s",
"1"
);
-> at timber.log.Timber.d(Timber.java:38)
Actually, there were zero interactions with this mock.
</code>
Wanted but not invoked:
Timber.class.d(
"Current step updated to: %s",
"1"
);
-> at timber.log.Timber.d(Timber.java:38)
Actually, there were zero interactions with this mock.
I debug it and there is a problem with schedular only I don’t know how to test the executive service.I thought of attaching the executorService Schedulers to test schedulers but it didn’t work.Can you guys help me with the test how I can test the subscribeToUpdates.