Skip to content

Commit 1b3ba7b

Browse files
Put apex-mocks and apex-extensions into the fflib directory
1 parent e33b28e commit 1b3ba7b

File tree

120 files changed

+19283
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

120 files changed

+19283
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
3+
<apiVersion>52.0</apiVersion>
4+
<status>Active</status>
5+
</ApexClass>
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
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<fflib_IMatcher> expectedMatchers = fflib_Match.Matching ? fflib_Match.getAndClearMatchers(expectedArguments.argValues.size()) : null;
24+
List<fflib_MethodArgValues> 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<fflib_IMatcher> matchers, List<fflib_MethodArgValues> 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<fflib_MethodArgValues> 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+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ApexClass xmlns="http://soap.sforce.com/2006/04/metadata">
3+
<apiVersion>52.0</apiVersion>
4+
<status>Active</status>
5+
</ApexClass>

0 commit comments

Comments
 (0)