コード例 #1
0
        static void thatAnswerToVoidAndNotVoidMethods()
        {
            // Given
            fflib_ApexMocks mocks = new fflib_ApexMocks();
            fflib_MyList mockList = (fflib_MyList)mocks.mock(typeof(fflib_MyList));
            mocks.startStubbing();
            ((fflib_MyList)mocks.doAnswer(new fflib_AnswerTest.FirstAnswer(), mockList)).get(3);
            ((fflib_MyList)mocks.doAnswer(new fflib_AnswerTest.BasicAnswer(), mockList)).addMore("Hi hi Hello Hi hi");
            ((fflib_MyList)mocks.doAnswer(new fflib_AnswerTest.SecondAnswer(), mockList)).get2(4, "Hi hi Hello Hi hi");
            mocks.stopStubbing();

            // When
            string answer1 = mockList.get(3);
            string answer2 = mockList.get2(4, "Hi hi Hello Hi hi");
            mockList.addMore("Hi hi Hello Hi hi");

            // Then
            object methodCalled = actualInvocation.getMethod();
            System.assert(methodCalled is fflib_QualifiedMethod, "the object returned is not a method as expected");
            string expectedMethodSignature = fflib_MyList.getStubClassName()+ ".addMore(String)";
            System.assertEquals(expectedMethodSignature, ((fflib_QualifiedMethod)methodCalled).toString(),
			"the last method called should be the addMore, so should be the last to set the actualInvocation variable.");
            System.assertEquals("this is the first answer", answer1, "the answer was not the one expected");
            System.assertEquals("and this is the second one", answer2, "the answer was not the one expected");
        }
コード例 #2
0
        static void thatAnswerToDifferentVoidMethods()
        {
            // Given
            fflib_ApexMocks mocks = new fflib_ApexMocks();
            fflib_MyList mockList = (fflib_MyList)mocks.mock(typeof(fflib_MyList));
            fflib_AnswerTest.FirstAnswer answer1 = new fflib_AnswerTest.FirstAnswer();
            fflib_AnswerTest.SecondAnswer answer2 = new fflib_AnswerTest.SecondAnswer();
            System.assertEquals(null, answer1.getMessage(), "the answer message should be null at this stage");
            System.assertEquals(null, answer2.getMessage(), "the answer message should be null at this stage");
            mocks.startStubbing();
            ((fflib_MyList)mocks.doAnswer(answer1, mockList)).addMore("Hi hi Hello Hi hi");
            ((fflib_MyList)mocks.doAnswer(answer2, mockList)).add("Hello");
            mocks.stopStubbing();

            // When
            mockList.addMore("Hi hi Hello Hi hi");
            mockList.add("Hello");

            // Then
            System.assertEquals("this is the first answer", answer1.getMessage(), "the answer was not the one expected");
            System.assertEquals("and this is the second one", answer2.getMessage(), "the answer was not the one expected");
        }
コード例 #3
0
        static void thatAnswerToVoidMethod()
        {
            // Given
            fflib_ApexMocks mocks = new fflib_ApexMocks();
            fflib_MyList mockList = (fflib_MyList)mocks.mock(typeof(fflib_MyList));
            mocks.startStubbing();
            ((fflib_MyList)mocks.doAnswer(new fflib_AnswerTest.BasicAnswer(), mockList)).addMore("Hi hi Hello Hi hi");
            mocks.stopStubbing();

            // When
            mockList.addMore("Hi hi Hello Hi hi");

            // Then
            object methodCalled = actualInvocation.getMethod();
            System.assert(methodCalled is fflib_QualifiedMethod, "the object returned is not a method as expected");
            string expectedMethodSignature = fflib_MyList.getStubClassName()+ ".addMore(String)";
            System.assertEquals(expectedMethodSignature, ((fflib_QualifiedMethod)methodCalled).toString(), "Unexpected method name: "+ methodCalled);
        }