final
List<User> users= new ArrayList<User>();//here I add users to this list
inal
UserService service = context.mock(UserService.class);
now, in my test method when method "findAll" is called I'm returning
a iterator to my list:
context
.checking(new Expectations() {{one(service).findAll(); will(returnValue(
users));}});
here I assert if I have e.g. 2 users in a list.
But now I want to test saving and deleting, i.e., my UserService implementation class
works with a database. How can I do this, if I want to test my save class that recieve user
as a parameter, save it to database and return the same user object:
final User user = new User (1, "Mark");
context
.checking(new Expectations() {{one(service).save(user); will(returnValue(user));
}});
Now, my users list should be expaded by this saved user, how can I do this ? It is the same
with deleting, I want to remove that user from a list. I supose that now when I call again findAll()
I need to have one user more in the list because this method returns all users from database.
--
Thx in advance, Milan Milanovic