コード例 #1
0
        private static void thatThrownExceptionIfCalledMoreThanAtMostNumberOfTimesWithMatchers()
        {
            // 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("fred");
            mockList.add("fred");

            // Then
            try
            {
                ((fflib_MyList.IList)mocks.verify(mockList, mocks.atMost(3))).add(fflib_Match.anyString());
                System.assert(false, "an exception was expected because we are asserting that the method is called 3 times when instead is called four times");
            }
            catch (fflib_ApexMocks.ApexMocksException ex)
            {
                string expectedMessage = "Expected : 3 or fewer times, Actual: 4 -- 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");
            }
        }
コード例 #2
0
        private static void thatVerifiesAtMostSameNumberOfTimesWithMatchers()
        {
            // 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("fred");

            // Then
            ((fflib_MyList.IList)mocks.verify(mockList, mocks.atMost(3))).add(fflib_Match.anyString());
        }
コード例 #3
0
        private static void thatVerifiesAtMostNumberOfTimes()
        {
            // 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");
            mockList.add("fred");

            // Then
            ((fflib_MyList.IList)mocks.verify(mockList, mocks.atMost(5))).add("bob");
        }