This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Testing and the fly likes expectLastCall().atLeastOnce() what is the use. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » Testing
Bookmark "expectLastCall().atLeastOnce() what is the use." Watch "expectLastCall().atLeastOnce() what is the use." New topic

expectLastCall().atLeastOnce() what is the use.

vivek dhiman
Ranch Hand

Joined: Aug 05, 2011
Posts: 111


In EasyMock i have seen expectLastCall().atLeastOnce() method but not sure whats the use of it exactly as if i use it inside my test does make any effect. javadoc not providing much help to see the behavior practically.

Steve Luke

Joined: Jan 28, 2003
Posts: 4168

The expectLastCall() method refers to the last expect() called. So for example if you did the second line would be modifying the object returned from the first line so when the method is called it returns a specific value.

Normally an expect() would indicate the method should be called exactly one. But you can tell it to expect the method a certain number of times using the times() method. Our you can say the method must be called at least once, but maybe more than once using the. AtLeastOnce() method.

So in your code you have this

You are saying the method getPath() should be called, when it is called it should return "/content" and it must be called at least once but it is allowed to be called 2 or 3 or any number of times greater than 1.

With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
subject: expectLastCall().atLeastOnce() what is the use.
Similar Threads
newbie question on easyMocking the DataSource
How to set properties on a Mocked Object using EasyMock?
How to mock Hibernate Session?
EasyMock dummy question
EasyMockClassExtension not mocking class