我有一个代码,它有两个不同类型的新List对象:
List<TypeOne> typeOneList = new ArrayList<TypeOne>();
List<TypeTwo> typeTwoList = new ArrayList<TypeTwo>();
如何使用PowerMock.expectNew()返回两个不同的ArrayList对象?像..
PowerMock.expectNew(ArrayList.class).andReturn(typeOneList);
PowerMock.expectNew(ArrayList.class).andReturn(typeTwoList);
我们如何区分上述语句中的对象所对应的语句?
谢谢!
答案 0 :(得分:0)
好。您必须按照您想要的顺序定义以下方式..
PowerMock.expectNew(ArrayList.class).andReturn(typeOneList); //first expect list object of TypeOne
PowerMock.expectNew(ArrayList.class).andReturn(typeTwoList); //then expect list object of TypeTwo
当下面的代码执行时,和powermock会按照预期的顺序返回对象:
List<TypeOne> typeOneList = new ArrayList<TypeOne>();
List<TypeTwo> typeTwoList = new ArrayList<TypeTwo>();