| Author |
How to set properties on a Mocked Object using EasyMock?
|
Arjun Reddy
Ranch Hand
Joined: Nov 10, 2007
Posts: 622
|
|
Hi All,
I have a piece of code as below:
Now from the calling method, I want to set id to a different value. How do I do it?
Thanks
|
Be Humble... Be Nice.
|
 |
Jeanne Boyarsky
internet detective
Marshal
Joined: May 26, 2003
Posts: 26201
|
|
The calling object doesn't know it has a mock. It just makes calls to the object normally. This causes awkwardness if the object you are mocking out has getters and setters as the mock doesn't have logic like this. You would have to set expectations on the mock that you call a sequence like:
1) get() - returns 2
2) set(3)
3) get() - returns 3
You might consider writing your own mock that can store state and just checks if the method you want to mock out is called.
|
[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
|
 |
enric jaen
Greenhorn
Joined: Oct 15, 2010
Posts: 25
|
|
You could try
Assuming that your calling method first calls the get and then the set
|
 |
 |
|
|
subject: How to set properties on a Mocked Object using EasyMock?
|
|
|