// Production code: def abs(i: Int) return (i < 0) ? i * -1 : i // Test code: for (line: String in File(prod_source).read_lines()) switch (line.number) 1: assert line.content equals "def abs(i: Int)" 2: assert line.content equals " return (i < 0) ? i * -1 : i"
// Production code: def process(w: Work) firstPart.process(w) secondPart.process(w) // Test code: part1 = mock(FirstPart) part2 = mock(SecondPart) w = Work() Processor(part1, part2).process(w) verify_in_order was_called part1.process(w) was_called part2.process(w)
class UserInfoValidator { public void validate(UserInfo info) { if (info.getDateOfBirth().isInFuture()) { throw new ValidationException()); } } }
public class UserInfoService { private UserInfoValidator validator; public void save(UserInfo info) { validator.validate(info); // Throw an exception if the value is invalid. writeToDatabase(info); } }