I can't seem to figure out how to mock a simple setter method using Mockito. I have the following class:
class MyClass {
private SomeObject someObject;
public void setSomeObject(SomeObject someObject) {
this.someObject = someObject;
}
public someObject getSomeObject() {
return someObject;
}
}
Now I just want that when "setSomeObject" is called that a new instance of "SomeObject" is set. Also the parameter within the setter should be ignored.
I need something like this:
MyClass mockedClass = mock(MyClass.class);
when(mockedClass.setSomeObject([ignoreWhatsInHere]))
.then(mockedClass.setSomeObject(new SomeObject();
However, I can't seem to get the syntax working for this. I can only get the mocks to work using getters(), because then I can return something. But I can't figure out how to do the same for setters().
All help appreciated.