Fix bug in formula criteria with only one condition
This commit is contained in:
@@ -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'))
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user