mercredi 18 février 2015

JMock Expectations, iterating through List

I have a list with Strings:



final List<String> serialNumbers=new ArrayList<String>();

for(int i=0;i<numberOfPieces;i++){
serialNumbers.add(Integer.toString(i));
}


Now I want my MockObject to return the next element in the List as a String everytime the mock method is called, how do I do this?



context.checking(new Expectations(){{
exactly(numberOfPieces).of (myMock).getSerialNumber();
// will return serialNumbers i-th element
}});

Aucun commentaire:

Enregistrer un commentaire