@Test public void testAcceptsExceptionsAsValidExpectations() throws Exception { StaticInvocation divide = new StaticInvocation(calculator, Calculator.DIVIDE); Call call = new Call(divide); call.addInput("7", "0"); call.expect(ShouldBe.instanceOf(ArithmeticException.class)); call.execute(); assertTrue(call.wasRight()); }
@Test public void testReportsASuccessIfOuputMatchesExpectation() throws Exception { Call call = new Call(new StaticInvocation(calculator, Calculator.SUM)); call.addInput("5", "2"); call.expect(ShouldBe.equal(7)); call.will(Annotate.right(annotatable)).when(ResultIs.right()); call.execute(); verify(annotatable).annotate(any(RightAnnotation.class)); }
@Test public void testReportsAFailureIfOuputIsUnexpected() throws Exception { Call call = new Call(new StaticInvocation(calculator, Calculator.ADD)); call.addInput("3"); call.expect(ShouldBe.equal(3)); call.will(Annotate.wrong(annotatable)).when(ResultIs.wrong()); call.execute(); verify(annotatable).annotate(any(WrongAnnotation.class)); }
public boolean equal() { return ShouldBe.literal(expectedValue).meets(actualValue); }