private static void thatThrownExceptionIfCalledLessThanAtLeastNumberOfTimes() { // Given fflib_ApexMocks mocks = new fflib_ApexMocks(); fflib_MyList mockList = (fflib_MyList)mocks.mock(typeof(fflib_MyList)); // When mockList.add("bob"); mockList.add("fred"); mockList.add("bob"); // Then try { ((fflib_MyList.IList)mocks.verify(mockList, mocks.atLeast(3))).add("bob"); System.assert(false, "an exception was expected because we are asserting that the method is called 3 times when instead is called only twice"); } catch (fflib_ApexMocks.ApexMocksException ex) { string expectedMessage = "Expected : 3 or more times, Actual: 2 -- Wanted but not invoked: " + fflib_MyList.getStubClassName() + ".add(String)."; string actualMessage = ex.getMessage(); System.assertEquals(expectedMessage, actualMessage, "the exception has been caught as expected, however the message is not as expected"); } }
private static void thatVerifiesAtLeastNumberOfTimesWithMatchers() { // Given fflib_ApexMocks mocks = new fflib_ApexMocks(); fflib_MyList mockList = (fflib_MyList)mocks.mock(typeof(fflib_MyList)); // When mockList.add("bob"); mockList.add("fred"); // Then ((fflib_MyList.IList)mocks.verify(mockList, mocks.atLeast(2))).add(fflib_Match.anyString()); }