@Test(expected = UnexpectedInvocation.class) public void unverifiedStaticInvocationForSpecifiedMockInstance(final AnotherDependency mock2) { mock2.doSomething(); AnotherDependency.staticMethod(); new FullVerifications(mock2) { { mock2.doSomething(); } }; }
@Test public void verifyAllInvocationsToOnlyOneOfTwoMockedTypes(AnotherDependency mock2) { exerciseCodeUnderTest(); mock2.doSomething(); new FullVerifications(mock) { { mock.prepare(); mock.setSomething(anyInt); minTimes = 1; maxTimes = 2; mock.editABunchMoreStuff(); mock.save(); times = 1; } }; new FullVerifications(mock.getClass()) { { mock.prepare(); mock.setSomething(anyInt); minTimes = 1; maxTimes = 2; mock.editABunchMoreStuff(); mock.save(); times = 1; } }; }
@Test public void verifyStaticInvocationForSpecifiedMockInstance(final AnotherDependency mock2) { mock2.doSomething(); AnotherDependency.staticMethod(); mock2.doSomethingElse(1); mock.editABunchMoreStuff(); mock2.doSomethingElse(2); new FullVerificationsInOrder(mock2) { { mock2.doSomething(); AnotherDependency.staticMethod(); mock2.doSomethingElse(anyInt); mock2.doSomethingElse(anyInt); } }; }
@Test public void verifyAllInvocationsToOneOfTwoMocksInIteratingBlock(AnotherDependency mock2) { mock2.doSomething(); mock.setSomething(123); mock.save(); mock2.doSomethingElse(1); mock.setSomething(45); mock.save(); mock2.doSomethingElse(2); new FullVerifications(2, mock) { { mock.setSomething(anyInt); mock.save(); } }; }
@Test public void verifyNoInvocationsOccurredOnMockedDependencyWithOneHavingOccurred( AnotherDependency mock2) { mock2.doSomething(); mock.editABunchMoreStuff(); try { new FullVerifications(mock) {}; fail(); } catch (UnexpectedInvocation e) { assertTrue(e.getMessage().contains("editABunchMoreStuff()")); } }
@Test(expected = UnexpectedInvocation.class) public void verifyAllInvocationsWithSomeMissing(final AnotherDependency mock2) { exerciseCodeUnderTest(); mock2.doSomething(); new FullVerifications(mock, mock2) { { mock.prepare(); mock.setSomething(anyInt); mock.save(); mock2.doSomething(); } }; }
@Test public void verifyNoInvocationsOnOneOfTwoMockedDependenciesBeyondThoseRecordedAsExpected( final AnotherDependency mock2) { new NonStrictExpectations() { { mock.setSomething(anyInt); minTimes = 1; mock2.doSomething(); times = 1; } }; mock.prepare(); mock.setSomething(1); mock.setSomething(2); mock.save(); mock2.doSomething(); new FullVerifications(mock2) {}; }
@Test public void verifyNoInvocationsOccurredOnOneOfTwoMockedDependencies(AnotherDependency mock2) { mock2.doSomething(); new FullVerifications(mock) {}; }