private static void thatThrownExceptionIfCalledLessThanAtLeastOnce() { // 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.atLeastOnce())).add("rob"); System.assert(false, "an exception was expected because we are asserting that the method is called one times when instead is not called"); } catch (fflib_ApexMocks.ApexMocksException ex) { string expectedMessage = "Expected : 1 or more times, Actual: 0 -- 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 thatVerifiesAtLeastOnceNumberOfTimesWithMatchers() { // Given fflib_ApexMocks mocks = new fflib_ApexMocks(); fflib_MyList mockList = (fflib_MyList)mocks.mock(typeof(fflib_MyList)); // When mockList.add("bob"); mockList.add("fred", "fred", "fred", "fred"); // Then ((fflib_MyList.IList)mocks.verify(mockList, mocks.atLeastOnce())).add(fflib_Match.anyString()); }
private static void thatVerifiesAtLeastOnce() { // 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"); mockList.add("bob"); // Then ((fflib_MyList.IList)mocks.verify(mockList, mocks.atLeastOnce())).add("bob"); }