Fix bug in formula criteria with only one condition

This commit is contained in:
Wim Velzeboer
2021-08-12 08:41:33 +01:00
parent d279ab6fc2
commit 7e9c5a7fce
2 changed files with 19 additions and 2 deletions
@@ -248,11 +248,11 @@ public virtual with sharing class fflib_Criteria
for (IFormulaEvaluator evaluator : formulaParts) for (IFormulaEvaluator evaluator : formulaParts)
{ {
Boolean evaluateResult = evaluator.evaluate(record, evaluatedResultByNumber); Boolean evaluateResult = evaluator.evaluate(record, evaluatedResultByNumber);
if (evaluateResult && (this.type == 'OR')) if (evaluateResult && (this.type == 'OR' || this.type == null))
{ {
return true; return true;
} }
else if (!evaluateResult && this.type == 'AND') else if (!evaluateResult && (this.type == 'AND' || this.type == null))
{ {
return false; return false;
} }
@@ -598,4 +598,21 @@ private with sharing class fflib_CriteriaTest
.evaluate(record) .evaluate(record)
); );
} }
@IsTest
static void itShouldEvaluateFormula_WithSingleItem()
{
System.assert(
new fflib_Criteria()
.FormulaCriteria('1')
.equalTo(Contact.LastName, 'Smith')
.evaluate(new Contact(LastName = 'Smith'))
);
System.assertEquals(false,
new fflib_Criteria()
.FormulaCriteria('1')
.equalTo(Contact.LastName, 'Ford')
.evaluate(new Contact(LastName = 'Smith'))
);
}
} }