Sometimes parameter objects are modified inside methods. One way to test for this is to create two instances, pass one in to the method, and then compare the one passed in to see if it is equal to the unmodified one. This assumes that you have a correct implementation of equals().
public class LegacyTest {
private Legacy legacy;
private PassedIn passedIn;
private PassedIn untouched;
@Before
public void setUp()
throws Exception {
legacy = new Legacy();
passedIn = new PassedIn();
untouched = new PassedIn();
}
@Test
public void passedInDidNotChange() {
assertEquals(untouched, passedIn);
legacy.method(passedIn);
assertEquals(untouched, passedIn);
}
}
No comments:
Post a Comment