Rx单元测试需要考虑

时间:2018-02-06 16:41:10

标签: java android unit-testing rx-java

我有以下方法,我不知道如何进行单元测试:

private Completable checkMachineStatus(){
        return deviceDriver.getNotification(new OperationKey("HMINotification"),
                HMI_DESCRIPTION, REQUIRED_HMI_BYTE_NUMBER)
                .takeWhile(data -> {
                    MachineStatus status = MachineStatus.getMachineState(data.array()[MACHINE_STATUS_CHECK_POSITION]);
                    return status != MachineStatus.READY;
                }).ignoreElements();
    }

getNotification方法是一个Observable

我想做的是:

    @Test
    public void testPowerBrewSuccess() {
        when(deviceDriver.getNotification(any(OperationKey.class), any(CharacteristicDescription.class), any(Integer.class)))
                .thenReturn(byteBufferObservable);
        when(byteBufferObservable.takeWhile(any())).thenReturn(predicateObservable);
        when(predicateObservable.ignoreElements()).thenReturn(Completable.complete());

        brew.brew(BrewParameters.POWER).test();
        verify(deviceDriver).getNotification(any(OperationKey.class), any(CharacteristicDescription.class), any(Integer.class));
    }

但是在执行takeWhile操作时失败了。

0 个答案:

没有答案