@Test public void shouldPerformAddition() { Calculator calculator = new Calculator(new RoundingStrategy(), "unused", ENABLE_COSIN_FEATURE, 0.01, calculusEngine, false); int result = calculator.doComputation(makeTestComputation()); assertEquals(5, result); // Where did this number come from? }
@Test public void shouldPerformAddition() { Calculator calculator = newCalculator(); int result = calculator.doComputation(makeAdditionComputation(2, 3)); assertEquals(5, result); }
interface Service { Data get(); }
when(service.get()).thenReturn(cannedData);
interface Service { void get(Callback callback); }
doAnswer(new Answer<Void>() { public Void answer(InvocationOnMock invocation) { Callback callback = (Callback) invocation.getArguments()[0]; callback.onSuccess(cannedData); return null; } }).when(service).get(any(Callback.class));
interface Translator { String translate(String msg); }
when(translator.translate(any(String.class))).thenAnswer(reverseMsg()) ... // extracted a method to put a descriptive name private static Answer<String> reverseMsg() { return new Answer<String>() { public String answer(InvocationOnMock invocation) { return reverseString((String) invocation.getArguments()[0])); } } }