public class Calculator { public int add(int a, int b) { return a + b; } }
public void testAdd() { assertEquals(3, calculator.add(2, 1)); assertEquals(2, calculator.add(2, 0)); assertEquals(1, calculator.add(2, -1)); }
public class Calculator { private AdderFactory adderFactory; public Calculator(AdderFactor adderFactory) { this.adderFactory = adderFactory; } public int add(int a, int b) { Adder adder = adderFactory.createAdder(); ReturnValue returnValue = adder.compute(new Number(a), new Number(b)); return returnValue.convertToInteger(); } }