I would like to test my method and I need to mock the vector of Items and Rows to go through each of them.
I prepared the result vector that I would like to get always when I call getRows() from Item class (within the test).
The problem is that the result of getRows method in test is always empty so it means that doReturn statement is not working correctly here.
Am I wrong with something?
class MyServiceTest {
@Mock
private Item mockedItem;
@Mock
private Row mockedRow;
@InjectMocks
@Spy
private MyService myService;
@Test
public void testMyMethod() {
Vector<Row> rows = new Vector<Row>();
Row row = new Row();
rows.add(row);
doReturn(rows).when(mockedItem).getRows();
...
//some code to test the service
}
}
class MyService {
protected SomeObject myMethod(Vector<Item> items) {
for(Item item : items) {
for(Row row : item.getRows()) {
//cannot get here while debugging the test
//some code
}
}
...
}
}
class Item {
...
public Vector<Row> getRows(){
//return some vector of rows
}
}
Aucun commentaire:
Enregistrer un commentaire