java - Mockito.spy not changing real object -
calling method on spy object somehow has no effect on real spied object:
public class aaa { public int a; public void seta(int aa) { this.a = aa; } public int geta() { return a; } } public class proof { @test public void wtf() { aaa obj = new aaa(); aaa spy = mockito.spy(obj); spy.seta(22); assertthat(obj.geta(), equalto(22)); } }
how can be? suppose proof
test should pass.
as seen in mockito doc:
mockito does not delegate calls passed real instance, instead creates copy of it.
this means original object obj
isn't modify happens in spied object spy
.
Comments
Post a Comment