├── .github
├── ISSUE_TEMPLATE
│ ├── bug_report.md
│ └── feature_request.md
└── workflows
│ ├── deploy.and.test.yml
│ └── manage.sf.api.versions.yml
├── .gitignore
├── LICENSE
├── README.md
├── config
└── project-scratch-def.json
├── sfdx-project.json
└── sfdx-source
└── apex-mocks
├── main
└── classes
│ ├── fflib_Answer.cls
│ ├── fflib_Answer.cls-meta.xml
│ ├── fflib_AnyOrder.cls
│ ├── fflib_AnyOrder.cls-meta.xml
│ ├── fflib_ApexMocks.cls
│ ├── fflib_ApexMocks.cls-meta.xml
│ ├── fflib_ApexMocksConfig.cls
│ ├── fflib_ApexMocksConfig.cls-meta.xml
│ ├── fflib_ApexMocksUtils.cls
│ ├── fflib_ApexMocksUtils.cls-meta.xml
│ ├── fflib_ArgumentCaptor.cls
│ ├── fflib_ArgumentCaptor.cls-meta.xml
│ ├── fflib_IDGenerator.cls
│ ├── fflib_IDGenerator.cls-meta.xml
│ ├── fflib_IMatcher.cls
│ ├── fflib_IMatcher.cls-meta.xml
│ ├── fflib_InOrder.cls
│ ├── fflib_InOrder.cls-meta.xml
│ ├── fflib_Inheritor.cls
│ ├── fflib_Inheritor.cls-meta.xml
│ ├── fflib_InvocationOnMock.cls
│ ├── fflib_InvocationOnMock.cls-meta.xml
│ ├── fflib_Match.cls
│ ├── fflib_Match.cls-meta.xml
│ ├── fflib_MatcherDefinitions.cls
│ ├── fflib_MatcherDefinitions.cls-meta.xml
│ ├── fflib_MatchersReturnValue.cls
│ ├── fflib_MatchersReturnValue.cls-meta.xml
│ ├── fflib_MethodArgValues.cls
│ ├── fflib_MethodArgValues.cls-meta.xml
│ ├── fflib_MethodCountRecorder.cls
│ ├── fflib_MethodCountRecorder.cls-meta.xml
│ ├── fflib_MethodReturnValue.cls
│ ├── fflib_MethodReturnValue.cls-meta.xml
│ ├── fflib_MethodReturnValueRecorder.cls
│ ├── fflib_MethodReturnValueRecorder.cls-meta.xml
│ ├── fflib_MethodVerifier.cls
│ ├── fflib_MethodVerifier.cls-meta.xml
│ ├── fflib_QualifiedMethod.cls
│ ├── fflib_QualifiedMethod.cls-meta.xml
│ ├── fflib_QualifiedMethodAndArgValues.cls
│ ├── fflib_QualifiedMethodAndArgValues.cls-meta.xml
│ ├── fflib_System.cls
│ ├── fflib_System.cls-meta.xml
│ ├── fflib_VerificationMode.cls
│ └── fflib_VerificationMode.cls-meta.xml
└── test
└── classes
├── fflib_AnswerTest.cls
├── fflib_AnswerTest.cls-meta.xml
├── fflib_AnyOrderTest.cls
├── fflib_AnyOrderTest.cls-meta.xml
├── fflib_ApexMocksTest.cls
├── fflib_ApexMocksTest.cls-meta.xml
├── fflib_ApexMocksUtilsTest.cls
├── fflib_ApexMocksUtilsTest.cls-meta.xml
├── fflib_ArgumentCaptorTest.cls
├── fflib_ArgumentCaptorTest.cls-meta.xml
├── fflib_IDGeneratorTest.cls
├── fflib_IDGeneratorTest.cls-meta.xml
├── fflib_InOrderTest.cls
├── fflib_InOrderTest.cls-meta.xml
├── fflib_InheritorTest.cls
├── fflib_InheritorTest.cls-meta.xml
├── fflib_MatchTest.cls
├── fflib_MatchTest.cls-meta.xml
├── fflib_MatcherDefinitionsTest.cls
├── fflib_MatcherDefinitionsTest.cls-meta.xml
├── fflib_MethodArgValuesTest.cls
├── fflib_MethodArgValuesTest.cls-meta.xml
├── fflib_MyList.cls
├── fflib_MyList.cls-meta.xml
├── fflib_QualifiedMethodAndArgValuesTest.cls
├── fflib_QualifiedMethodAndArgValuesTest.cls-meta.xml
├── fflib_QualifiedMethodTest.cls
├── fflib_QualifiedMethodTest.cls-meta.xml
├── fflib_SystemTest.cls
└── fflib_SystemTest.cls-meta.xml
/.github/ISSUE_TEMPLATE/bug_report.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Bug report
3 | about: Create a report to help us improve
4 | title: ''
5 | labels: ''
6 | assignees: ''
7 |
8 | ---
9 |
10 | **Describe the bug**
11 | (A clear and concise description of what the bug is.)
12 |
13 | **To Reproduce**
14 |
15 | (Please provide a public github repo with a full SFDX project that demonstrates the problem. If the repro case can be followed with a single example Apex class against a scratch org with just the fflib-apex-mocks project deployed into it, you don't need to provide a github repo)
16 |
17 | Steps to reproduce the behavior:
18 | 1. Create a scratch org as follows....
19 | 2. Run the following Anonymous Apex....
20 | 3. See error
21 |
22 | **Expected behavior**
23 | A clear and concise description of what you expected to happen.
24 |
25 | **Screenshots and text of error observed**
26 | If applicable, add screenshots to help explain your problem. Also, paste the text of the raw error into the issue as well so that it can be found by others via search.
27 |
28 | **Version**
29 | Did you try to reproduce the problem against the latest fflib-apex-mocks code?
30 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/feature_request.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Feature request
3 | about: Suggest an idea for this project
4 | title: ''
5 | labels: ''
6 | assignees: ''
7 |
8 | ---
9 |
10 | **Is your feature request related to a problem? Please describe.**
11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
12 |
13 | **Describe the solution you'd like**
14 | A clear and concise description of what you want to happen.
15 |
16 | **Describe alternatives you've considered**
17 | A clear and concise description of any alternative solutions or features you've considered.
18 |
19 | **Additional context**
20 | Add any other context or screenshots about the feature request here.
21 |
--------------------------------------------------------------------------------
/.github/workflows/deploy.and.test.yml:
--------------------------------------------------------------------------------
1 | name: Create a Scratch Org, Push Source and Run Apex Tests
2 |
3 | on:
4 | push:
5 | pull_request_target:
6 | workflow_dispatch:
7 |
8 | jobs:
9 | build:
10 |
11 | runs-on: ubuntu-latest
12 |
13 | steps:
14 | - uses: actions/checkout@v2 #Check out this repo
15 | with:
16 | ref: ${{github.event.pull_request.head.ref}}
17 | repository: ${{github.event.pull_request.head.repo.full_name}}
18 | - name: Install SF CLI and authorize DevHub
19 | uses: apex-enterprise-patterns/setup-sfdx@v2 #We're using a fork of https://github.com/sfdx-actions/setup-sfdx for safety
20 | with:
21 | sfdx-auth-url: ${{ secrets.DEVHUB_SFDXURL }}
22 | - name: Setup the config parameters needed
23 | run: sf config set target-dev-hub SFDX-ENV --global #Even though the setup-sfdx action uses --setdefaultdevhubusername, it doesn't seem to stick since it uses --setdefaultusername so we brute force it here
24 | - name: Create the scratch org
25 | run: sf org create scratch --definition-file config/project-scratch-def.json --set-default --duration-days 1 --no-track-source
26 | - name: Deploy and compile the codebase
27 | run: sf project deploy start
28 | - name: Run the core framework tests
29 | run: sf apex run test --wait 5
30 | - name: Destroy scratch org
31 | run: sf org delete scratch --no-prompt
32 | if: always()
33 |
--------------------------------------------------------------------------------
/.github/workflows/manage.sf.api.versions.yml:
--------------------------------------------------------------------------------
1 | name: Manage SF API Versions
2 | on:
3 | workflow_dispatch:
4 | inputs:
5 | api-version:
6 | description: 'api version in the format XX e.g 58'
7 | required: true
8 | type: string
9 | jobs:
10 | update:
11 | runs-on: ubuntu-latest
12 | steps:
13 | - uses: actions/checkout@v3
14 | - uses: apex-enterprise-patterns/manage-sf-api-version@v1.0.0
15 | with:
16 | api-version: ${{inputs.api-version}}
17 | - uses: peter-evans/create-pull-request@v5
18 | with:
19 | title: 'Bump API Versions to ${{inputs.api-version}}.0'
20 | body: 'Automatically bumped by GitHub Actions '
21 | branch: 'devops/bump-api-versions-v${{inputs.api-version}}.0'
22 | commit-message: 'chore: bump api to v${{inputs.api-version}}.0'
23 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # General Project related
2 | .DS_Store
3 | target/
4 | temp/
5 | /deploy/*
6 | /debug/
7 | **/dep-dir.txt
8 | *.prefs
9 | build.properties
10 | /sfdx-source/apex-mocks/main/default
11 |
12 | # MavensMate IDE related
13 | *mm.log
14 | *.sublime-build
15 | *.sublime-project
16 | *.sublime-settings
17 | *.sublime-workspace
18 | .sublime-project
19 | .tm_properties
20 |
21 | # Eclipse IDE Related
22 | .project
23 | .settings/
24 | salesforce.schema
25 | Referenced Packages/
26 |
27 | # VS Code IDE Related
28 | .vscode/
29 | .history/
30 |
31 | # Illuminated Cloud Related
32 | .idea/
33 | IlluminatedCloud
34 |
35 | # SFDX Related
36 | .sfdx/
37 | .sf/
38 | sfdx-source/untracked/
39 | .execanon
40 |
41 | # NPM Related
42 | package.json
43 | /node_modules
44 | package-lock.json
45 |
46 |
47 | sfdx-source/group*
48 | research/
49 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c), FinancialForce.com, inc
2 | All rights reserved.
3 |
4 | Redistribution and use in source and binary forms, with or without modification,
5 | are permitted provided that the following conditions are met:
6 |
7 | - Redistributions of source code must retain the above copyright notice,
8 | this list of conditions and the following disclaimer.
9 | - Redistributions in binary form must reproduce the above copyright notice,
10 | this list of conditions and the following disclaimer in the documentation
11 | and/or other materials provided with the distribution.
12 | - Neither the name of the FinancialForce.com, inc nor the names of its contributors
13 | may be used to endorse or promote products derived from this software without
14 | specific prior written permission.
15 |
16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 | OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
19 | THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
20 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 | OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22 | OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
23 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # FFLib ApexMocks Framework
2 |
3 | 
4 |
5 | ApexMocks is a mocking framework for the Salesforce Lightning Apex language.
6 |
7 | It derives its inspiration from the well known Java mocking framework [Mockito](https://site.mockito.org/)
8 |
9 |
10 |
12 |
13 |
14 | ## Using ApexMocks on the Salesforce Lightning Platform
15 |
16 | ApexMocks allows you to write tests to both verify behavior and stub dependencies.
17 |
18 | An assumption is made that you are using some form of [Dependency Injection](http://en.wikipedia.org/wiki/Dependency_injection) - for example passing dependencies via a constructor:
19 | ```Java
20 | public MyClass(ClassA.IClassA dependencyA, ClassB.IClassB dependencyB)
21 | ```
22 | This allows you to pass mock implementations of dependencies A and B when you want to unit test MyClass.
23 |
24 | Lets assume we've written our own list interface fflib_MyList.IList that we want to either verify or stub:
25 | ```Java
26 | public class fflib_MyList implements IList
27 | {
28 | public interface IList
29 | {
30 | void add(String value);
31 | String get(Integer index);
32 | void clear();
33 | Boolean isEmpty();
34 | }
35 | }
36 | ```
37 | ### verify() behaviour verification
38 | ```Java
39 | // Given
40 | fflib_ApexMocks mocks = new fflib_ApexMocks();
41 | fflib_MyList.IList mockList = (fflib_MyList.IList)mocks.mock(fflib_MyList.class);
42 |
43 | // When
44 | mockList.add('bob');
45 |
46 | // Then
47 | ((fflib_MyList.IList) mocks.verify(mockList)).add('bob');
48 | ((fflib_MyList.IList) mocks.verify(mockList, fflib_ApexMocks.NEVER)).clear();
49 | ```
50 |
51 | If the method wasn't called the expected number of times, or with the expected arguments, verify will throw an exception.
52 | The exception message contains details of the expected and actual invocations:
53 |
54 | ```
55 | EXPECTED COUNT: 1
56 | ACTUAL COUNT: 0
57 | METHOD: EmailService__sfdc_ApexStub.sendTo(String)
58 | ---
59 | ACTUAL ARGS: ("user-two@example.com")
60 | ---
61 | EXPECTED ARGS: [[contains "user-one"]]
62 |
63 | ```
64 |
65 | ### when() dependency stubbing
66 | ```Java
67 | fflib_ApexMocks mocks = new fflib_ApexMocks();
68 | fflib_MyList.IList mockList = (fflib_MyList.IList)mocks.mock(fflib_MyList.class);
69 |
70 | mocks.startStubbing();
71 | mocks.when(mockList.get(0)).thenReturn('bob');
72 | mocks.when(mockList.get(1)).thenReturn('fred');
73 | mocks.stopStubbing();
74 | ```
75 |
76 | ## Utilties
77 |
78 | ### Setting a read-only field, such as a formula
79 |
80 | ```Java
81 | Account acc = new Account();
82 | Integer mockFormulaResult = 10;
83 | acc = (Account)fflib_ApexMocksUtils.setReadOnlyFields(
84 | acc,
85 | Account.class,
86 | new Map {Account.Your_Formula_Field__c => mockFormulaResult}
87 | );
88 | System.assertEquals(mockFormulaResult, acc.Your_Formula_Field__c);
89 | ```
90 |
91 | ## Stub API
92 | Using Salesforce's [Stub API](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_testing_stub_api.htm), stub objects are generated dynamically at run time.
93 | ```Java
94 | fflib_ApexMocks mocks = new fflib_ApexMocks();
95 | fflib_MyList mockList = (fflib_MyList)mocks.mock(fflib_MyList.class);
96 | ```
97 |
98 | ## Documentation
99 |
100 | * [ApexMocks Framework Tutorial](http://code4cloud.wordpress.com/2014/05/06/apexmocks-framework-tutorial/)
101 | * [Simple Dependency Injection](http://code4cloud.wordpress.com/2014/05/09/simple-dependency-injection/)
102 | * [ApexMocks Generator](http://code4cloud.wordpress.com/2014/05/15/using-apex-mocks-generator-to-create-mock-class-definitions/)
103 | * [Behaviour Verification](http://code4cloud.wordpress.com/2014/05/15/writing-behaviour-verification-unit-tests/)
104 | * [Stubbing Dependencies](http://code4cloud.wordpress.com/2014/05/15/stubbing-dependencies-in-a-unit-test/)
105 | * [Supported Features](http://code4cloud.wordpress.com/2014/05/15/apexmocks-supported-features/)
106 | * [New Improved apex-mocks-generator](http://code4cloud.wordpress.com/2014/06/27/new-improved-apex-mocks-generator/)
107 | * [ApexMocks Improvements - exception stubbing, base classes and more](http://code4cloud.wordpress.com/2014/11/05/apexmocks-improvements-exception-stubbing-inner-interfaces-and-mock-base-classes/)
108 | * [Matchers](http://superdupercode.blogspot.co.uk/2016/03/apex-mocks-matchers.html)
109 | * [ApexMock blogs from Jesse Altman](http://jessealtman.com/tag/apexmocks/)
110 | * [Order of calls verification](https://xonoxforce.wordpress.com/2017/03/26/inorder-verify/)
111 | * [Answering](https://xonoxforce.wordpress.com/2017/03/31/answering-with-apex-mocks/)
112 | * [Counters](https://xonoxforce.wordpress.com/2017/04/01/counters-in-apex-mocks-verifications/)
113 | * [Troubleshooting](https://salesforce.stackexchange.com/questions/252460/my-apexmocks-arent-working-what-could-be-wrong)
114 |
--------------------------------------------------------------------------------
/config/project-scratch-def.json:
--------------------------------------------------------------------------------
1 | {
2 | "orgName": "apex-mocks",
3 | "edition": "Developer",
4 | "settings": {
5 | "lightningExperienceSettings": {
6 | "enableS1DesktopEnabled": true
7 | }
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/sfdx-project.json:
--------------------------------------------------------------------------------
1 | {
2 | "packageDirectories": [
3 | {
4 | "path": "sfdx-source/apex-mocks",
5 | "default": true
6 | }
7 | ],
8 | "namespace": "",
9 | "sfdcLoginUrl": "https://login.salesforce.com",
10 | "sourceApiVersion": "63.0"
11 | }
--------------------------------------------------------------------------------
/sfdx-source/apex-mocks/main/classes/fflib_Answer.cls:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2017 FinancialForce.com, inc. All rights reserved.
3 | */
4 |
5 | /**
6 | * Interface for the answering framework.
7 | * This interface must be implemented inside the test class and implement the call back method answer.
8 | * @group Core
9 | */
10 | public interface fflib_Answer
11 | {
12 | /**
13 | * Method to be implemented in the test class to implement the call back method.
14 | * @param invocation The invocation on the mock.
15 | * @throws The exception to be thrown.
16 | * @return The value to be returned.
17 | */
18 | Object answer(fflib_InvocationOnMock invocation);
19 | }
--------------------------------------------------------------------------------
/sfdx-source/apex-mocks/main/classes/fflib_Answer.cls-meta.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 63.0
4 | Active
5 |
6 |
--------------------------------------------------------------------------------
/sfdx-source/apex-mocks/main/classes/fflib_AnyOrder.cls:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2017 FinancialForce.com, inc. All rights reserved.
3 | */
4 |
5 | /**
6 | * 'Classic' invocation verifier - checks that a method was called with the given arguments the expected number of times.
7 | * The order of method calls is not important.
8 | * @group Core
9 | */
10 | public class fflib_AnyOrder extends fflib_MethodVerifier
11 | {
12 | /*
13 | * Verifies a method was invoked the expected number of times, with the expected arguments.
14 | * @param qualifiedMethod The method to be verified.
15 | * @param methodArg The arguments of the method that needs to be verified.
16 | * @param verificationMode The verification mode that holds the setting about how the verification should be performed.
17 | */
18 | protected override void verify(
19 | fflib_QualifiedMethod qm,
20 | fflib_MethodArgValues expectedArguments,
21 | fflib_VerificationMode verificationMode)
22 | {
23 | List expectedMatchers = fflib_Match.Matching ? fflib_Match.getAndClearMatchers(expectedArguments.argValues.size()) : null;
24 | List actualArguments = fflib_MethodCountRecorder.getMethodArgumentsByTypeName().get(qm);
25 |
26 | Integer methodCount = getMethodCount(expectedArguments, expectedMatchers, actualArguments);
27 |
28 | String qualifier = '';
29 | Integer expectedCount = null;
30 |
31 | if((verificationMode.VerifyMin == verificationMode.VerifyMax) && methodCount != verificationMode.VerifyMin)
32 | {
33 | expectedCount = verificationMode.VerifyMin;
34 | }
35 | else if (verificationMode.VerifyMin != null && verificationMode.VerifyMin > methodCount)
36 | {
37 | expectedCount = verificationMode.VerifyMin;
38 | qualifier = ' or more times';
39 | }
40 | else if (verificationMode.VerifyMax != null && verificationMode.VerifyMax < methodCount)
41 | {
42 | expectedCount = verificationMode.VerifyMax;
43 | qualifier = ' or fewer times';
44 | }
45 |
46 | if (expectedCount != null)
47 | {
48 | throwException(qm, '', expectedCount, qualifier, methodCount, verificationMode.CustomAssertMessage, expectedArguments, expectedMatchers, actualArguments);
49 | }
50 | }
51 |
52 | private Integer getMethodCount(fflib_MethodArgValues methodArg, List matchers, List methodArgs)
53 | {
54 | Integer retval = 0;
55 |
56 | if (methodArgs != null)
57 | {
58 | if (matchers != null)
59 | {
60 | for (fflib_MethodArgValues args : methodArgs)
61 | {
62 | if (fflib_Match.matchesAllArgs(args, matchers))
63 | {
64 | capture(matchers);
65 | retval ++;
66 | }
67 | }
68 | }
69 | else
70 | {
71 | return countCalls(methodArgs, methodArg);
72 | }
73 | }
74 |
75 | return retval;
76 | }
77 |
78 | private Integer countCalls(List methodArgs, fflib_MethodArgValues methodArg)
79 | {
80 | Integer count = 0;
81 |
82 | for(fflib_MethodArgValues arg: methodArgs)
83 | {
84 | if( arg == methodArg) count++;
85 | }
86 |
87 | return count;
88 | }
89 |
90 | /*
91 | * Method that validate the verification mode used in the verify.
92 | * Not all the methods from the fflib_VerificationMode are implemented for the different classes that extends the fflib_MethodVerifier.
93 | * The error is thrown at run time, so this method is called in the method that actually performs the verify.
94 | * @param verificationMode The verification mode that have to been verified.
95 | * @throws Exception with message for the fflib_VerificationMode not implemented.
96 | */
97 | protected override void validateMode(fflib_VerificationMode verificationMode)
98 | {
99 | if(verificationMode.Method == fflib_VerificationMode.ModeName.CALLS)
100 | {
101 | throw new fflib_ApexMocks.ApexMocksException(
102 | 'The calls() method is available only in the InOrder Verification.');
103 | }
104 | }
105 | }
106 |
--------------------------------------------------------------------------------
/sfdx-source/apex-mocks/main/classes/fflib_AnyOrder.cls-meta.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 63.0
4 | Active
5 |
6 |
--------------------------------------------------------------------------------
/sfdx-source/apex-mocks/main/classes/fflib_ApexMocks.cls:
--------------------------------------------------------------------------------
1 | /*
2 | Copyright (c) 2014-2017 FinancialForce.com, inc. All rights reserved.
3 | */
4 |
5 | /**
6 | * @group Core
7 | */
8 | public with sharing class fflib_ApexMocks implements System.StubProvider
9 | {
10 | public static final Integer NEVER = 0;
11 |
12 | private final fflib_MethodCountRecorder methodCountRecorder;
13 | private final fflib_MethodReturnValueRecorder methodReturnValueRecorder;
14 |
15 | private fflib_MethodVerifier methodVerifier;
16 | private fflib_VerificationMode verificationMode;
17 | private fflib_Answer myAnswer;
18 |
19 | public Boolean verifying { get; set; }
20 |
21 | public Boolean Stubbing
22 | {
23 | get
24 | {
25 | return methodReturnValueRecorder.Stubbing;
26 | }
27 |
28 | private set;
29 | }
30 |
31 | public List DoThrowWhenExceptions
32 | {
33 | get
34 | {
35 | return methodReturnValueRecorder.DoThrowWhenExceptions;
36 | }
37 |
38 | set
39 | {
40 | methodReturnValueRecorder.DoThrowWhenExceptions = value;
41 | }
42 | }
43 |
44 | /**
45 | * Construct an ApexMocks instance.
46 | */
47 | public fflib_ApexMocks()
48 | {
49 | this.verifying = false;
50 |
51 | this.methodCountRecorder = new fflib_MethodCountRecorder();
52 | this.verificationMode = new fflib_VerificationMode();
53 | this.methodVerifier = new fflib_AnyOrder();
54 |
55 | this.methodReturnValueRecorder = new fflib_MethodReturnValueRecorder();
56 |
57 | this.methodReturnValueRecorder.Stubbing = false;
58 | }
59 |
60 | /**
61 | * Creates mock object of given class or interface.
62 | * @param classToMock class or interface to mock.
63 | * @return mock object.
64 | */
65 | public Object mock(Type classToMock)
66 | {
67 | return Test.createStub(classToMock, this);
68 | }
69 |
70 | /**
71 | * Inherited from StubProvider.
72 | * @param stubbedObject The stubbed object.
73 | * @param stubbedMethodName The name of the invoked method.
74 | * @param returnType The return type of the invoked method.
75 | * @param listOfParamTypes A list of the parameter types of the invoked method.
76 | * @param listOfParamNames A list of the parameter names of the invoked method.
77 | * @param listOfArgs The actual argument values passed into this method at runtime.
78 | * @return The stubbed return value. Null by default, unless you prepared one that matches this method and argument values in stubbing.
79 | */
80 | public Object handleMethodCall(Object stubbedObject, String stubbedMethodName, Type returnType,
81 | List listOfParamTypes, List listOfParamNames, List