间谍对象未返回期望值

时间:2019-01-24 16:22:03

标签: mockito junit4

试图测试以下类的方法processOrders并对其进行了存根测试,并且间谍未通过doReturn返回值0来返回期望值6。

下面需要更改什么?

public class Orders { 
    public static void main(String[] s) { 
        ........
    }
    public void processOrders(List<OrdersVoBean> lstOrders, int orderId) {
        ........
        int maxOrderItemId = isExistOrderItem(orderId, ordDesc);
        ........
    }

    public int isExistOrderItem(int orderId, String orderDesc ) {
        ...... 
        return maxOrderItemId;
    }
}

@RunWith(MockitoJUnitRunner.class)
public class OrdersTest {
    ..........

    @Before
    public void setUp() {
        ........
    }

    @Test
    public void testProcessOrders() {
        .............
        Orders spy = spy(new Orders());
        doReturn(Integer.valueOf(6)).when(spy).isExistOrderItem(any(Integer.class), any(String.class));
        spy.processOrders(new ArrayList<OrdersVoBean>(), 200);
        ..................
    }

}

0 个答案:

没有答案