I'm trying to write getter and setter mock methods which seem to be doing some database operation internally. Getter returns a String and setter takes String as argument. I would like to pass whatever I get from getter to the setter instead of passing a mock String so as to keep track of data flow.
Is there a way to pass the same String what actual setter is getting, to the mock method.
Please direct if there's a solution already available for this.
Yes, you can create a MockUp
subclass with suitable @Mock
method implementations for the getters/setters of interest. The setter would simply store the value in an instance field, which the getter would read. The same mechanism can be implemented with Delegate
objects, if use of the "Expectations" API is preferred.