From 2cb008cccd39c4d13a7a66ed991c382e807bd94e Mon Sep 17 00:00:00 2001 From: Robert Baillie Date: Tue, 15 Feb 2022 15:09:18 +0000 Subject: [PATCH] Started the process of fully wrapping fflib_Criteria Allows for better fluidity in using code and more consistent parameter checking Have wrapped and implemented all inSet and notInSet implementations --- .../classes/criteria/fflib_Criteria.cls | 2 +- .../fflib-extension/ortoo_Criteria.cls | 651 +++++++++++++++++- .../tests/ortoo_CriteriaTest.cls | 620 +++++++++++++++++ 3 files changed, 1256 insertions(+), 17 deletions(-) diff --git a/framework/default/fflib-apex-extensions/default/classes/criteria/fflib_Criteria.cls b/framework/default/fflib-apex-extensions/default/classes/criteria/fflib_Criteria.cls index 153f93a1e44..ff4f1f58b89 100755 --- a/framework/default/fflib-apex-extensions/default/classes/criteria/fflib_Criteria.cls +++ b/framework/default/fflib-apex-extensions/default/classes/criteria/fflib_Criteria.cls @@ -57,7 +57,7 @@ public virtual with sharing class fflib_Criteria /** * Adds the given evalutor onto the formula stack */ - protected void addEvaluator( Evaluator evaluator ) + public void addEvaluator( Evaluator evaluator ) { evaluators.add( evaluator ); } diff --git a/framework/default/ortoo-core/default/classes/fflib-extension/ortoo_Criteria.cls b/framework/default/ortoo-core/default/classes/fflib-extension/ortoo_Criteria.cls index 57de5cfc164..267a518a099 100644 --- a/framework/default/ortoo-core/default/classes/fflib-extension/ortoo_Criteria.cls +++ b/framework/default/ortoo-core/default/classes/fflib-extension/ortoo_Criteria.cls @@ -3,18 +3,295 @@ * * @group fflib Extension */ -public inherited sharing virtual class ortoo_Criteria extends fflib_Criteria implements ISearchCriteria // NOPMD: specified a mini-namespace to differentiate from fflib versions +public inherited sharing virtual class ortoo_Criteria implements ISearchCriteria // NOPMD: specified a mini-namespace to differentiate from fflib versions { + fflib_Criteria criteria; - public virtual ortoo_Criteria likeString( Schema.SObjectField field, Object value ) + public ortoo_Criteria() { - addEvaluator( new FieldEvaluator( field, fflib_Operator.LIKEx, value ) ); + criteria = new fflib_Criteria(); + } + + public String toSOQL() + { + return criteria.toSOQL(); + } + + // TODO: add remaining public methods from fflib_Criteria + // TODO: change SObjects2 to allow ortoo_Criteria - maybe define an interface instead + + /** + * Checks if the given field has a value 'like' that given + * + * @param field The field to check the value of + * @param values The value that resolve to 'true' + * + * @return ortoo_Criteria Itself, providing a fluent interface + * + * @example + * new ortoo_Criteria() + * .likeString( Account.Type, 'Customer%' ) + * + * Evaluates: + * Type LIKE 'Customer%' + */ + public ortoo_Criteria likeString( Schema.SObjectField field, String value ) + { + Contract.requires( field != null, 'likeString called with a null field' ); + if ( ! String.isEmpty( value ) ) + { + criteria.addEvaluator( new fflib_Criteria.FieldEvaluator( field, fflib_Operator.LIKEx, value ) ); + } + return this; + } + + /** + * Checks if the given field has a value 'like' that given + * + * @param relatedField The name of the to check the value of + * @param values The value that resolve to 'true' + * + * @return ortoo_Criteria Itself, providing a fluent interface + * + * @example + * new ortoo_Criteria() + * .likeString( 'Account.Type', 'Customer%' ) + * + * Evaluates: + * Account.Type LIKE 'Customer%' + */ + public ortoo_Criteria likeString( String relatedField, String value ) + { + Contract.requires( relatedField != null, 'likeString called with a null relatedField' ); + if ( ! String.isEmpty( value ) ) + { + criteria.addEvaluator( new fflib_Criteria.RelatedFieldEvaluator( relatedField, fflib_Operator.LIKEx, value ) ); + } + return this; + } + + /** + * Checks if the given field has a value in the given set + * + * @param field The field to check the value of + * @param values The values that resolve to 'true' + * + * @return ortoo_Criteria Itself, providing a fluent interface + * + * @example + * new ortoo_Criteria() + * .inSet( Account.Type, new Set{'Customer', 'Competitor', 'Partner'} ) + * + * Evaluates: + * Type IN ('Customer','Competitor','Partner') + */ + public ortoo_Criteria inSet( Schema.SObjectField field, Set values ) + { + Contract.requires( field != null, 'inSet called with a null field' ); + Contract.requires( values != null, 'inSet called with a null values' ); + Contract.requires( ! values.isEmpty(), 'inSet called with an empty values' ); + + criteria.inSet( field, new fflib_Objects( new List( values ) ) ); + return this; + } + + /** + * Checks if the given field has a DateTime value in the given set + * + * @param field The field to check the value of + * @param values The values that resolve to 'true' + * + * @return ortoo_Criteria Itself, providing a fluent interface + * + * @example + * new ortoo_Criteria() + * .inSet( Account.DateTime_Value__c, new Set{ Date.newInstanceGmt( 2020, 01, 02, 11, 20, 00 ), Date.newInstance( 2021, 01, 02, 11, 00, 20 )} ) + * + * Evaluates: + * DateTime_Value__c IN (2021-01-02T11:20:00Z,2021-01-02T11:00:20Z) + */ + public ortoo_Criteria inSet( Schema.SObjectField field, Set values ) + { + Contract.requires( field != null, 'inSet called with a null field' ); + Contract.requires( values != null, 'inSet called with a null values' ); + Contract.requires( ! values.isEmpty(), 'inSet called with an empty values' ); + + criteria.inSet( field, new fflib_DateTimes( values ) ); + return this; + } + + /** + * Checks if the given field has a Date value in the given set + * + * @param field The field to check the value of + * @param values The values that resolve to 'true' + * + * @return ortoo_Criteria Itself, providing a fluent interface + * + * @example + * new ortoo_Criteria() + * .inSet( Account.Date_Value__c, new Set{ Date.newInstance( 2020, 01, 02 ), Date.newInstance( 2021, 01, 02 )} ) + * + * Evaluates: + * Date_Value__c IN (2021-01-02,2021-01-02) + */ + public ortoo_Criteria inSet( Schema.SObjectField field, Set values ) + { + Contract.requires( field != null, 'inSet called with a null field' ); + Contract.requires( values != null, 'inSet called with a null values' ); + Contract.requires( ! values.isEmpty(), 'inSet called with an empty values' ); + + criteria.inSet( field, new fflib_Dates( values ) ); + return this; + } + + /** + * Checks if the given field has a Decimal value in the given set + * + * @param field The field to check the value of + * @param values The values that resolve to 'true' + * + * @return ortoo_Criteria Itself, providing a fluent interface + * + * @example + * new ortoo_Criteria() + * .inSet( Account.Decimal_Value__c, new Set{1.1,2.2,3.3} ) + * + * Evaluates: + * Decimal_Value__c IN (1.1,2.2,3.3) + */ + public ortoo_Criteria inSet( Schema.SObjectField field, Set values ) + { + Contract.requires( field != null, 'inSet called with a null field' ); + Contract.requires( values != null, 'inSet called with a null values' ); + Contract.requires( ! values.isEmpty(), 'inSet called with an empty values' ); + + criteria.inSet( field, new fflib_Decimals( values ) ); + return this; + } + + /** + * Checks if the given field has a Double value in the given set + * + * @param field The field to check the value of + * @param values The values that resolve to 'true' + * + * @return ortoo_Criteria Itself, providing a fluent interface + * + * @example + * new ortoo_Criteria() + * .inSet( Account.Double_Value__c, new Set{1.1,2.2,3.3} ) + * + * Evaluates: + * Double_Value__c IN (1.1,2.2,3.3) + */ + public ortoo_Criteria inSet( Schema.SObjectField field, Set values ) + { + Contract.requires( field != null, 'inSet called with a null field' ); + Contract.requires( values != null, 'inSet called with a null values' ); + Contract.requires( ! values.isEmpty(), 'inSet called with an empty values' ); + + criteria.inSet( field, new fflib_Doubles( values ) ); return this; } - public virtual ortoo_Criteria likeString( String relatedField, Object value ) + /** + * Checks if the given field has an Id value in the given set + * + * @param field The field to check the value of + * @param values The values that resolve to 'true' + * + * @return ortoo_Criteria Itself, providing a fluent interface + * + * @example + * new ortoo_Criteria() + * .inSet( Account.Id, new Set{'0010t00001bH9q2AAC', '0010t00001bH9q2AAB'} ) + * + * Evaluates: + * Id IN ('0010t00001bH9q2AAC','0010t00001bH9q2AAB') + */ + public ortoo_Criteria inSet( Schema.SObjectField field, Set values ) { - addEvaluator( new RelatedFieldEvaluator( relatedField, fflib_Operator.LIKEx, value ) ); + Contract.requires( field != null, 'inSet called with a null field' ); + Contract.requires( values != null, 'inSet called with a null values' ); + Contract.requires( ! values.isEmpty(), 'inSet called with an empty values' ); + + criteria.inSet( field, new fflib_Ids( values ) ); + return this; + } + + /** + * Checks if the given field has a Integer value in the given set + * + * @param field The field to check the value of + * @param values The values that resolve to 'true' + * + * @return ortoo_Criteria Itself, providing a fluent interface + * + * @example + * new ortoo_Criteria() + * .inSet( Account.Integer_Value__c, new Set{1,2,3} ) + * + * Evaluates: + * Integer_Value__c IN (1,2,3) + */ + public ortoo_Criteria inSet( Schema.SObjectField field, Set values ) + { + Contract.requires( field != null, 'inSet called with a null field' ); + Contract.requires( values != null, 'inSet called with a null values' ); + Contract.requires( ! values.isEmpty(), 'inSet called with an empty values' ); + + criteria.inSet( field, new fflib_Integers( values ) ); + return this; + } + + /** + * Checks if the given field has a Long value in the given set + * + * @param field The field to check the value of + * @param values The values that resolve to 'true' + * + * @return ortoo_Criteria Itself, providing a fluent interface + * + * @example + * new ortoo_Criteria() + * .inSet( Account.Long_Value__c, new Set{1,2,3} ) + * + * Evaluates: + * Long_Value__c IN (1,2,3) + */ + public ortoo_Criteria inSet( Schema.SObjectField field, Set values ) + { + Contract.requires( field != null, 'inSet called with a null field' ); + Contract.requires( values != null, 'inSet called with a null values' ); + Contract.requires( ! values.isEmpty(), 'inSet called with an empty values' ); + + criteria.inSet( field, new fflib_Longs( values ) ); + return this; + } + + /** + * Checks if the given field has a String value in the given set + * + * @param field The field to check the value of + * @param values The values that resolve to 'true' + * + * @return ortoo_Criteria Itself, providing a fluent interface + * + * @example + * new ortoo_Criteria() + * .inSet( Account.String_Value__c, new Set{'one','two'} ) + * + * Evaluates: + * Long_Value__c IN ('one','two') + */ + public ortoo_Criteria inSet( Schema.SObjectField field, Set values ) + { + Contract.requires( field != null, 'inSet called with a null field' ); + Contract.requires( values != null, 'inSet called with a null values' ); + Contract.requires( ! values.isEmpty(), 'inSet called with an empty values' ); + + criteria.inSet( field, new fflib_Strings( values ) ); return this; } @@ -35,6 +312,10 @@ public inherited sharing virtual class ortoo_Criteria extends fflib_Criteria imp */ public ortoo_Criteria inSet( String relatedField, Set values ) { + Contract.requires( relatedField != null, 'inSet called with a null relatedField' ); + Contract.requires( values != null, 'inSet called with a null values' ); + Contract.requires( ! values.isEmpty(), 'inSet called with an empty values' ); + return inSet( relatedField, new fflib_Objects( new List( values ) ) ); } @@ -55,6 +336,10 @@ public inherited sharing virtual class ortoo_Criteria extends fflib_Criteria imp */ public ortoo_Criteria inSet( String relatedField, Set values ) { + Contract.requires( relatedField != null, 'inSet called with a null relatedField' ); + Contract.requires( values != null, 'inSet called with a null values' ); + Contract.requires( ! values.isEmpty(), 'inSet called with an empty values' ); + return inSet( relatedField, new fflib_DateTimes( values ) ); } @@ -75,6 +360,10 @@ public inherited sharing virtual class ortoo_Criteria extends fflib_Criteria imp */ public ortoo_Criteria inSet( String relatedField, Set values ) { + Contract.requires( relatedField != null, 'inSet called with a null relatedField' ); + Contract.requires( values != null, 'inSet called with a null values' ); + Contract.requires( ! values.isEmpty(), 'inSet called with an empty values' ); + return inSet( relatedField, new fflib_Dates( values ) ); } @@ -95,6 +384,10 @@ public inherited sharing virtual class ortoo_Criteria extends fflib_Criteria imp */ public ortoo_Criteria inSet( String relatedField, Set values ) { + Contract.requires( relatedField != null, 'inSet called with a null relatedField' ); + Contract.requires( values != null, 'inSet called with a null values' ); + Contract.requires( ! values.isEmpty(), 'inSet called with an empty values' ); + return inSet( relatedField, new fflib_Decimals( values ) ); } @@ -115,6 +408,10 @@ public inherited sharing virtual class ortoo_Criteria extends fflib_Criteria imp */ public ortoo_Criteria inSet( String relatedField, Set values ) { + Contract.requires( relatedField != null, 'inSet called with a null relatedField' ); + Contract.requires( values != null, 'inSet called with a null values' ); + Contract.requires( ! values.isEmpty(), 'inSet called with an empty values' ); + return inSet( relatedField, new fflib_Doubles( values ) ); } @@ -135,6 +432,10 @@ public inherited sharing virtual class ortoo_Criteria extends fflib_Criteria imp */ public ortoo_Criteria inSet( String relatedField, Set values ) { + Contract.requires( relatedField != null, 'inSet called with a null relatedField' ); + Contract.requires( values != null, 'inSet called with a null values' ); + Contract.requires( ! values.isEmpty(), 'inSet called with an empty values' ); + return inSet( relatedField, new fflib_Ids( values ) ); } @@ -155,6 +456,10 @@ public inherited sharing virtual class ortoo_Criteria extends fflib_Criteria imp */ public ortoo_Criteria inSet( String relatedField, Set values ) { + Contract.requires( relatedField != null, 'inSet called with a null relatedField' ); + Contract.requires( values != null, 'inSet called with a null values' ); + Contract.requires( ! values.isEmpty(), 'inSet called with an empty values' ); + return inSet( relatedField, new fflib_Integers( values ) ); } @@ -175,6 +480,10 @@ public inherited sharing virtual class ortoo_Criteria extends fflib_Criteria imp */ public ortoo_Criteria inSet( String relatedField, Set values ) { + Contract.requires( relatedField != null, 'inSet called with a null relatedField' ); + Contract.requires( values != null, 'inSet called with a null values' ); + Contract.requires( ! values.isEmpty(), 'inSet called with an empty values' ); + return inSet( relatedField, new fflib_Longs( values ) ); } @@ -195,9 +504,40 @@ public inherited sharing virtual class ortoo_Criteria extends fflib_Criteria imp */ public ortoo_Criteria inSet( String relatedField, Set values ) { + Contract.requires( relatedField != null, 'inSet called with a null relatedField' ); + Contract.requires( values != null, 'inSet called with a null values' ); + Contract.requires( ! values.isEmpty(), 'inSet called with an empty values' ); + return inSet( relatedField, new fflib_Strings( values ) ); } + /** + * Checks if the given field has a value that is not in the given set + * + * @param field The field to check the value of + * @param values The values that resolve to 'true' + * + * @return ortoo_Criteria Itself, providing a fluent interface + * + * @example + * new ortoo_Criteria() + * .notInSet( Account.Type, new Set{'Customer', 'Competitor', 'Partner'} ) + * + * Evaluates: + * Type NOT IN ('Customer','Competitor','Partner') + */ + public ortoo_Criteria notInSet( Schema.SobjectField field, Set values ) + { + Contract.requires( field != null, 'notInSet called with a null field' ); + Contract.requires( values != null, 'notInSet called with a null values' ); + + if ( !values.isEmpty() ) + { + criteria.notInSet( field, values ); + } + return this; + } + /** * Checks if the given field has a value that is not in the given set * @@ -215,7 +555,41 @@ public inherited sharing virtual class ortoo_Criteria extends fflib_Criteria imp */ public ortoo_Criteria notInSet( String relatedField, Set values ) { - return notInSet( relatedField, new fflib_Objects( new List( values ) ) ); + Contract.requires( relatedField != null, 'notInSet called with a null relatedField' ); + Contract.requires( values != null, 'notInSet called with a null values' ); + + if ( !values.isEmpty() ) + { + notInSet( relatedField, new fflib_Objects( new List( values ) ) ); + } + return this; + } + + /** + * Checks if the given field has a DateTime value that is not in the given set + * + * @param field The field to check the value of + * @param values The values that resolve to 'true' + * + * @return ortoo_Criteria Itself, providing a fluent interface + * + * @example + * new ortoo_Criteria() + * .notInSet( Account.DateTime_Value__c, new Set{ Date.newInstanceGmt( 2020, 01, 02, 11, 20, 00 ), Date.newInstance( 2021, 01, 02, 11, 00, 20 )} ) + * + * Evaluates: + * DateTime_Value__c NOT IN (2021-01-02T11:20:00Z,2021-01-02T11:00:20Z) + */ + public ortoo_Criteria notInSet( Schema.SobjectField field, Set values ) + { + Contract.requires( field != null, 'notInSet called with a null field' ); + Contract.requires( values != null, 'notInSet called with a null values' ); + + if ( !values.isEmpty() ) + { + criteria.notInSet( field, values ); + } + return this; } /** @@ -235,7 +609,41 @@ public inherited sharing virtual class ortoo_Criteria extends fflib_Criteria imp */ public ortoo_Criteria notInSet( String relatedField, Set values ) { - return notInSet( relatedField, new fflib_DateTimes( values ) ); + Contract.requires( relatedField != null, 'notInSet called with a null relatedField' ); + Contract.requires( values != null, 'notInSet called with a null values' ); + + if ( !values.isEmpty() ) + { + notInSet( relatedField, new fflib_DateTimes( values ) ); + } + return this; + } + + /** + * Checks if the given field has a Date value that is not in the given set + * + * @param field The field to check the value of + * @param values The values that resolve to 'true' + * + * @return ortoo_Criteria Itself, providing a fluent interface + * + * @example + * new ortoo_Criteria() + * .notInSet( Account.Date_Value__c, new Set{ Date.newInstance( 2020, 01, 02 ), Date.newInstance( 2021, 01, 02 )} ) + * + * Evaluates: + * Date_Value__c NOT IN (2021-01-02,2021-01-02) + */ + public ortoo_Criteria notInSet( Schema.SobjectField field, Set values ) + { + Contract.requires( field != null, 'notInSet called with a null field' ); + Contract.requires( values != null, 'notInSet called with a null values' ); + + if ( !values.isEmpty() ) + { + criteria.notInSet( field, values ); + } + return this; } /** @@ -255,7 +663,41 @@ public inherited sharing virtual class ortoo_Criteria extends fflib_Criteria imp */ public ortoo_Criteria notInSet( String relatedField, Set values ) { - return notInSet( relatedField, new fflib_Dates( values ) ); + Contract.requires( relatedField != null, 'notInSet called with a null relatedField' ); + Contract.requires( values != null, 'notInSet called with a null values' ); + + if ( !values.isEmpty() ) + { + notInSet( relatedField, new fflib_Dates( values ) ); + } + return this; + } + + /** + * Checks if the given field has a Decimal value that is not in the given set + * + * @param field The field to check the value of + * @param values The values that resolve to 'true' + * + * @return ortoo_Criteria Itself, providing a fluent interface + * + * @example + * new ortoo_Criteria() + * .notInSet( Account.Decimal_Value__c, new Set{1.1,2.2,3.3} ) + * + * Evaluates: + * Decimal_Value__c NOT IN (1.1,2.2,3.3) + */ + public ortoo_Criteria notInSet( Schema.SobjectField field, Set values ) + { + Contract.requires( field != null, 'notInSet called with a null field' ); + Contract.requires( values != null, 'notInSet called with a null values' ); + + if ( !values.isEmpty() ) + { + criteria.notInSet( field, values ); + } + return this; } /** @@ -275,7 +717,41 @@ public inherited sharing virtual class ortoo_Criteria extends fflib_Criteria imp */ public ortoo_Criteria notInSet( String relatedField, Set values ) { - return notInSet( relatedField, new fflib_Decimals( values ) ); + Contract.requires( relatedField != null, 'notInSet called with a null relatedField' ); + Contract.requires( values != null, 'notInSet called with a null values' ); + + if ( !values.isEmpty() ) + { + notInSet( relatedField, new fflib_Decimals( values ) ); + } + return this; + } + + /** + * Checks if the given field has a Double value that is not in the given set + * + * @param field The field to check the value of + * @param values The values that resolve to 'true' + * + * @return ortoo_Criteria Itself, providing a fluent interface + * + * @example + * new ortoo_Criteria() + * .notInSet( Account.Double_Value__c, new Set{1.1,2.2,3.3} ) + * + * Evaluates: + * Double_Value__c NOT IN (1.1,2.2,3.3) + */ + public ortoo_Criteria notInSet( Schema.SobjectField field, Set values ) + { + Contract.requires( field != null, 'notInSet called with a null field' ); + Contract.requires( values != null, 'notInSet called with a null values' ); + + if ( !values.isEmpty() ) + { + criteria.notInSet( field, values ); + } + return this; } /** @@ -295,7 +771,41 @@ public inherited sharing virtual class ortoo_Criteria extends fflib_Criteria imp */ public ortoo_Criteria notInSet( String relatedField, Set values ) { - return notInSet( relatedField, new fflib_Doubles( values ) ); + Contract.requires( relatedField != null, 'notInSet called with a null relatedField' ); + Contract.requires( values != null, 'notInSet called with a null values' ); + + if ( !values.isEmpty() ) + { + notInSet( relatedField, new fflib_Doubles( values ) ); + } + return this; + } + + /** + * Checks if the given field has an Id value that is not in the given set + * + * @param field The field to check the value of + * @param values The values that resolve to 'true' + * + * @return ortoo_Criteria Itself, providing a fluent interface + * + * @example + * new ortoo_Criteria() + * .notInSet( Account.Id, new Set{'0010t00001bH9q2AAC', '0010t00001bH9q2AAB'} ) + * + * Evaluates: + * Id NOT IN ('0010t00001bH9q2AAC','0010t00001bH9q2AAB') + */ + public ortoo_Criteria notInSet( Schema.SobjectField field, Set values ) + { + Contract.requires( field != null, 'notInSet called with a null field' ); + Contract.requires( values != null, 'notInSet called with a null values' ); + + if ( !values.isEmpty() ) + { + criteria.notInSet( field, values ); + } + return this; } /** @@ -315,7 +825,41 @@ public inherited sharing virtual class ortoo_Criteria extends fflib_Criteria imp */ public ortoo_Criteria notInSet( String relatedField, Set values ) { - return notInSet( relatedField, new fflib_Ids( values ) ); + Contract.requires( relatedField != null, 'notInSet called with a null relatedField' ); + Contract.requires( values != null, 'notInSet called with a null values' ); + + if ( !values.isEmpty() ) + { + notInSet( relatedField, new fflib_Ids( values ) ); + } + return this; + } + + /** + * Checks if the given field has a Integer value that is not in the given set + * + * @param field The field to check the value of + * @param values The values that resolve to 'true' + * + * @return ortoo_Criteria Itself, providing a fluent interface + * + * @example + * new ortoo_Criteria() + * .notInSet( Account.Integer_Value__c, new Set{1,2,3} ) + * + * Evaluates: + * Integer_Value__c NOT IN (1,2,3) + */ + public ortoo_Criteria notInSet( Schema.SobjectField field, Set values ) + { + Contract.requires( field != null, 'notInSet called with a null field' ); + Contract.requires( values != null, 'notInSet called with a null values' ); + + if ( !values.isEmpty() ) + { + criteria.notInSet( field, values ); + } + return this; } /** @@ -335,7 +879,41 @@ public inherited sharing virtual class ortoo_Criteria extends fflib_Criteria imp */ public ortoo_Criteria notInSet( String relatedField, Set values ) { - return notInSet( relatedField, new fflib_Integers( values ) ); + Contract.requires( relatedField != null, 'notInSet called with a null relatedField' ); + Contract.requires( values != null, 'notInSet called with a null values' ); + + if ( !values.isEmpty() ) + { + notInSet( relatedField, new fflib_Integers( values ) ); + } + return this; + } + + /** + * Checks if the given field has a Long value that is not in the given set + * + * @param field The field to check the value of + * @param values The values that resolve to 'true' + * + * @return ortoo_Criteria Itself, providing a fluent interface + * + * @example + * new ortoo_Criteria() + * .notInSet( Account.Long_Value__c, new Set{1,2,3} ) + * + * Evaluates: + * Long_Value__c NOT IN (1,2,3) + */ + public ortoo_Criteria notInSet( Schema.SobjectField field, Set values ) + { + Contract.requires( field != null, 'notInSet called with a null field' ); + Contract.requires( values != null, 'notInSet called with a null values' ); + + if ( !values.isEmpty() ) + { + criteria.notInSet( field, values ); + } + return this; } /** @@ -355,7 +933,41 @@ public inherited sharing virtual class ortoo_Criteria extends fflib_Criteria imp */ public ortoo_Criteria notInSet( String relatedField, Set values ) { - return notInSet( relatedField, new fflib_Longs( values ) ); + Contract.requires( relatedField != null, 'notInSet called with a null relatedField' ); + Contract.requires( values != null, 'notInSet called with a null values' ); + + if ( !values.isEmpty() ) + { + notInSet( relatedField, new fflib_Longs( values ) ); + } + return this; + } + + /** + * Checks if the given field has a String value that is not in the given set + * + * @param field The field to check the value of + * @param values The values that resolve to 'true' + * + * @return ortoo_Criteria Itself, providing a fluent interface + * + * @example + * new ortoo_Criteria() + * .notInSet( Account.String_Value__c, new Set{'one','two'} ) + * + * Evaluates: + * Long_Value__c NOT IN ('one','two') + */ + public ortoo_Criteria notInSet( Schema.SobjectField field, Set values ) + { + Contract.requires( field != null, 'notInSet called with a null field' ); + Contract.requires( values != null, 'notInSet called with a null values' ); + + if ( !values.isEmpty() ) + { + criteria.notInSet( field, values ); + } + return this; } /** @@ -375,17 +987,24 @@ public inherited sharing virtual class ortoo_Criteria extends fflib_Criteria imp */ public ortoo_Criteria notInSet( String relatedField, Set values ) { - return notInSet( relatedField, new fflib_Strings( values ) ); + Contract.requires( relatedField != null, 'notInSet called with a null relatedField' ); + Contract.requires( values != null, 'notInSet called with a null values' ); + + if ( !values.isEmpty() ) + { + notInSet( relatedField, new fflib_Strings( values ) ); + } + return this; } protected ortoo_Criteria inSet( String relatedField, fflib_Objects values ) { - addEvaluator( new RelatedFieldSetEvaluator( relatedField, fflib_Operator.INx, values ) ); + criteria.addEvaluator( new fflib_Criteria.RelatedFieldSetEvaluator( relatedField, fflib_Operator.INx, values ) ); return this; } protected ortoo_Criteria notInSet( String relatedField, fflib_Objects values ) { - addEvaluator( new RelatedFieldSetEvaluator( relatedField, fflib_Operator.NOT_IN, values ) ); + criteria.addEvaluator( new fflib_Criteria.RelatedFieldSetEvaluator( relatedField, fflib_Operator.NOT_IN, values ) ); return this; } } \ No newline at end of file diff --git a/framework/default/ortoo-core/default/classes/fflib-extension/tests/ortoo_CriteriaTest.cls b/framework/default/ortoo-core/default/classes/fflib-extension/tests/ortoo_CriteriaTest.cls index 12882b3555b..b291384ede0 100644 --- a/framework/default/ortoo-core/default/classes/fflib-extension/tests/ortoo_CriteriaTest.cls +++ b/framework/default/ortoo-core/default/classes/fflib-extension/tests/ortoo_CriteriaTest.cls @@ -16,6 +16,21 @@ private without sharing class ortoo_CriteriaTest System.assertEquals( expected, got, 'likeString, when called with a field, will add a LIKE to the generated SOQL' ); } + @isTest + private static void likeString_field_whenCalledWithAnEmptyString_doesNotAddToTheGeneratedSoql() // NOPMD: Test method name format + { + ortoo_Criteria criteria = new ortoo_Criteria(); + + Test.startTest(); + criteria.likeString( Contact.Name, '' ); + Test.stopTest(); + + String expected = ''; + String got = criteria.toSOQL(); + + System.assertEquals( expected, got, 'likeString, when called with a field and an empty string, will not add a LIKE to the generated SOQL' ); + } + @isTest private static void likeString_stringName_whenCalled_addsALikeToTheGeneratedSoql() // NOPMD: Test method name format { @@ -31,6 +46,21 @@ private without sharing class ortoo_CriteriaTest System.assertEquals( expected, got, 'likeString, when called with a string name for a field will add a LIKE to the generated SOQL' ); } + @isTest + private static void likeString_stringName_whenCalledWithAnEmptyString_doesNotAddToTheGeneratedSoql() // NOPMD: Test method name format + { + ortoo_Criteria criteria = new ortoo_Criteria(); + + Test.startTest(); + criteria.likeString( 'Contact.Name', '' ); + Test.stopTest(); + + String expected = ''; + String got = criteria.toSOQL(); + + System.assertEquals( expected, got, 'likeString, when called with a string name and an empty string, will not add a LIKE to the generated SOQL' ); + } + @isTest private static void inSet_field_stringValues_whenCalled_addsAnInToTheGeneratedSoql() // NOPMD: Test method name format { @@ -46,6 +76,25 @@ private without sharing class ortoo_CriteriaTest System.assertEquals( expected, got, 'inSet, when called with a field and a set of Strings, will add an IN to the generated SOQL' ); } + @isTest + private static void isSet_field_stringValues_whenGivenAnEmptySet_throwsAnException() // NOPMD: Test method name format + { + ortoo_Criteria criteria = new ortoo_Criteria(); + Test.startTest(); + String exceptionMessage; + try + { + criteria.inSet( Account.Name, new Set() ); + } + catch ( Contract.RequiresException e ) + { + exceptionMessage = e.getMessage(); + } + Test.stopTest(); + + Amoss_Asserts.assertContains( 'inSet called with an empty values', exceptionMessage, 'isSet, when called with a field and an empty set of Strings, will throw an exception' ); + } + @isTest private static void inSet_stringName_stringValues_whenCalled_addsAnInToTheGeneratedSoql() // NOPMD: Test method name format { @@ -61,6 +110,25 @@ private without sharing class ortoo_CriteriaTest System.assertEquals( expected, got, 'inSet, when called with a string field name and a set of Strings, will add an IN to the generated SOQL' ); } + @isTest + private static void isSet_stringName_stringValues_whenGivenAnEmptySet_throwsAnException() // NOPMD: Test method name format + { + ortoo_Criteria criteria = new ortoo_Criteria(); + Test.startTest(); + String exceptionMessage; + try + { + criteria.inSet( 'Account.Name', new Set() ); + } + catch ( Contract.RequiresException e ) + { + exceptionMessage = e.getMessage(); + } + Test.stopTest(); + + Amoss_Asserts.assertContains( 'inSet called with an empty values', exceptionMessage, 'isSet, when called with a string name and an empty set of Strings, will throw an exception' ); + } + @isTest private static void inSet_field_longValues_whenCalled_addsAnInToTheGeneratedSoql() // NOPMD: Test method name format { @@ -76,6 +144,25 @@ private without sharing class ortoo_CriteriaTest System.assertEquals( expected, got, 'inSet, when called with a field and a set of Longs, will add an IN to the generated SOQL' ); } + @isTest + private static void isSet_field_longValues_whenGivenAnEmptySet_throwsAnException() // NOPMD: Test method name format + { + ortoo_Criteria criteria = new ortoo_Criteria(); + Test.startTest(); + String exceptionMessage; + try + { + criteria.inSet( Account.Name, new Set() ); + } + catch ( Contract.RequiresException e ) + { + exceptionMessage = e.getMessage(); + } + Test.stopTest(); + + Amoss_Asserts.assertContains( 'inSet called with an empty values', exceptionMessage, 'isSet, when called with a field and an empty set of Strings, will throw an exception' ); + } + @isTest private static void inSet_stringName_longValues_whenCalled_addsAnInToTheGeneratedSoql() // NOPMD: Test method name format { @@ -91,6 +178,25 @@ private without sharing class ortoo_CriteriaTest System.assertEquals( expected, got, 'inSet, when called with a string field name and a set of Longs, will add an IN to the generated SOQL' ); } + @isTest + private static void isSet_stringName_longValues_whenGivenAnEmptySet_throwsAnException() // NOPMD: Test method name format + { + ortoo_Criteria criteria = new ortoo_Criteria(); + Test.startTest(); + String exceptionMessage; + try + { + criteria.inSet( 'Account.Name', new Set() ); + } + catch ( Contract.RequiresException e ) + { + exceptionMessage = e.getMessage(); + } + Test.stopTest(); + + Amoss_Asserts.assertContains( 'inSet called with an empty values', exceptionMessage, 'isSet, when called with a string name and an empty set of Longs, will throw an exception' ); + } + @isTest private static void inSet_field_integerValues_whenCalled_addsAnInToTheGeneratedSoql() // NOPMD: Test method name format { @@ -106,6 +212,25 @@ private without sharing class ortoo_CriteriaTest System.assertEquals( expected, got, 'inSet, when called with a field and a set of Integers, will add an IN to the generated SOQL' ); } + @isTest + private static void isSet_field_integerValues_whenGivenAnEmptySet_throwsAnException() // NOPMD: Test method name format + { + ortoo_Criteria criteria = new ortoo_Criteria(); + Test.startTest(); + String exceptionMessage; + try + { + criteria.inSet( Account.Name, new Set() ); + } + catch ( Contract.RequiresException e ) + { + exceptionMessage = e.getMessage(); + } + Test.stopTest(); + + Amoss_Asserts.assertContains( 'inSet called with an empty values', exceptionMessage, 'isSet, when called with a field and an empty set of Integers, will throw an exception' ); + } + @isTest private static void inSet_stringName_integerValues_whenCalled_addsAnInToTheGeneratedSoql() // NOPMD: Test method name format { @@ -121,6 +246,25 @@ private without sharing class ortoo_CriteriaTest System.assertEquals( expected, got, 'inSet, when called with a string field name and a set of Integers, will add an IN to the generated SOQL' ); } + @isTest + private static void isSet_stringName_integerValues_whenGivenAnEmptySet_throwsAnException() // NOPMD: Test method name format + { + ortoo_Criteria criteria = new ortoo_Criteria(); + Test.startTest(); + String exceptionMessage; + try + { + criteria.inSet( 'Account.Name', new Set() ); + } + catch ( Contract.RequiresException e ) + { + exceptionMessage = e.getMessage(); + } + Test.stopTest(); + + Amoss_Asserts.assertContains( 'inSet called with an empty values', exceptionMessage, 'isSet, when called with a string field name and an empty set of Integers, will throw an exception' ); + } + @isTest private static void inSet_field_idValues_whenCalled_addsAnInToTheGeneratedSoql() // NOPMD: Test method name format { @@ -139,6 +283,25 @@ private without sharing class ortoo_CriteriaTest System.assertEquals( expected, got, 'inSet, when called with a field and a set of Ids, will add an IN to the generated SOQL' ); } + @isTest + private static void isSet_field_IdValues_whenGivenAnEmptySet_throwsAnException() // NOPMD: Test method name format + { + ortoo_Criteria criteria = new ortoo_Criteria(); + Test.startTest(); + String exceptionMessage; + try + { + criteria.inSet( Account.Name, new Set() ); + } + catch ( Contract.RequiresException e ) + { + exceptionMessage = e.getMessage(); + } + Test.stopTest(); + + Amoss_Asserts.assertContains( 'inSet called with an empty values', exceptionMessage, 'isSet, when called with a field and an empty set of Ids, will throw an exception' ); + } + @isTest private static void inSet_stringName_idValues_whenCalled_addsAnInToTheGeneratedSoql() // NOPMD: Test method name format { @@ -157,6 +320,25 @@ private without sharing class ortoo_CriteriaTest System.assertEquals( expected, got, 'inSet, when called with a string field name and a set of Ids, will add an IN to the generated SOQL' ); } + @isTest + private static void isSet_stringName_IdValues_whenGivenAnEmptySet_throwsAnException() // NOPMD: Test method name format + { + ortoo_Criteria criteria = new ortoo_Criteria(); + Test.startTest(); + String exceptionMessage; + try + { + criteria.inSet( 'Account.Name', new Set() ); + } + catch ( Contract.RequiresException e ) + { + exceptionMessage = e.getMessage(); + } + Test.stopTest(); + + Amoss_Asserts.assertContains( 'inSet called with an empty values', exceptionMessage, 'isSet, when called with a string name and an empty set of Ids, will throw an exception' ); + } + @isTest private static void inSet_field_doubleValues_whenCalled_addsAnInToTheGeneratedSoql() // NOPMD: Test method name format { @@ -172,6 +354,24 @@ private without sharing class ortoo_CriteriaTest System.assertEquals( expected, got, 'inSet, when called with a field and a set of Doubles, will add an IN to the generated SOQL' ); } + @isTest + private static void isSet_field_doubleValues_whenGivenAnEmptySet_throwsAnException() // NOPMD: Test method name format + { + ortoo_Criteria criteria = new ortoo_Criteria(); + Test.startTest(); + String exceptionMessage; + try + { + criteria.inSet( Account.Name, new Set() ); + } + catch ( Contract.RequiresException e ) + { + exceptionMessage = e.getMessage(); + } + Test.stopTest(); + + Amoss_Asserts.assertContains( 'inSet called with an empty values', exceptionMessage, 'isSet, when called with a field and an empty set of Doubles, will throw an exception' ); + } @isTest private static void inSet_stringName_doubleValues_whenCalled_addsAnInToTheGeneratedSoql() // NOPMD: Test method name format { @@ -187,6 +387,25 @@ private without sharing class ortoo_CriteriaTest System.assertEquals( expected, got, 'inSet, when called with a string field name and a set of Doubles, will add an IN to the generated SOQL' ); } + @isTest + private static void isSet_stringName_doubleValues_whenGivenAnEmptySet_throwsAnException() // NOPMD: Test method name format + { + ortoo_Criteria criteria = new ortoo_Criteria(); + Test.startTest(); + String exceptionMessage; + try + { + criteria.inSet( 'Account.Name', new Set() ); + } + catch ( Contract.RequiresException e ) + { + exceptionMessage = e.getMessage(); + } + Test.stopTest(); + + Amoss_Asserts.assertContains( 'inSet called with an empty values', exceptionMessage, 'isSet, when called with a string field name and an empty set of Doubles, will throw an exception' ); + } + @isTest private static void inSet_field_decimalValues_whenCalled_addsAnInToTheGeneratedSoql() // NOPMD: Test method name format { @@ -202,6 +421,25 @@ private without sharing class ortoo_CriteriaTest System.assertEquals( expected, got, 'inSet, when called with a field and a set of Decimals, will add an IN to the generated SOQL' ); } + @isTest + private static void isSet_field_decimalValues_whenGivenAnEmptySet_throwsAnException() // NOPMD: Test method name format + { + ortoo_Criteria criteria = new ortoo_Criteria(); + Test.startTest(); + String exceptionMessage; + try + { + criteria.inSet( Account.Name, new Set() ); + } + catch ( Contract.RequiresException e ) + { + exceptionMessage = e.getMessage(); + } + Test.stopTest(); + + Amoss_Asserts.assertContains( 'inSet called with an empty values', exceptionMessage, 'isSet, when called with a field and an empty set of Decimal, will throw an exception' ); + } + @isTest private static void inSet_stringName_decimalValues_whenCalled_addsAnInToTheGeneratedSoql() // NOPMD: Test method name format { @@ -217,6 +455,25 @@ private without sharing class ortoo_CriteriaTest System.assertEquals( expected, got, 'inSet, when called with a string field name and a set of Decimals, will add an IN to the generated SOQL' ); } + @isTest + private static void isSet_stringName_decimalValues_whenGivenAnEmptySet_throwsAnException() // NOPMD: Test method name format + { + ortoo_Criteria criteria = new ortoo_Criteria(); + Test.startTest(); + String exceptionMessage; + try + { + criteria.inSet( 'Account.Name', new Set() ); + } + catch ( Contract.RequiresException e ) + { + exceptionMessage = e.getMessage(); + } + Test.stopTest(); + + Amoss_Asserts.assertContains( 'inSet called with an empty values', exceptionMessage, 'isSet, when called with a string field name and an empty set of Decimals, will throw an exception' ); + } + @isTest private static void inSet_field_dateValues_whenCalled_addsAnInToTheGeneratedSoql() // NOPMD: Test method name format { @@ -235,6 +492,25 @@ private without sharing class ortoo_CriteriaTest System.assertEquals( expected, got, 'inSet, when called with a field and a set of Dates, will add an IN to the generated SOQL' ); } + @isTest + private static void isSet_field_dateValues_whenGivenAnEmptySet_throwsAnException() // NOPMD: Test method name format + { + ortoo_Criteria criteria = new ortoo_Criteria(); + Test.startTest(); + String exceptionMessage; + try + { + criteria.inSet( Account.Name, new Set() ); + } + catch ( Contract.RequiresException e ) + { + exceptionMessage = e.getMessage(); + } + Test.stopTest(); + + Amoss_Asserts.assertContains( 'inSet called with an empty values', exceptionMessage, 'isSet, when called with a field and an empty set of Dates, will throw an exception' ); + } + @isTest private static void inSet_stringName_dateValues_whenCalled_addsAnInToTheGeneratedSoql() // NOPMD: Test method name format { @@ -253,6 +529,25 @@ private without sharing class ortoo_CriteriaTest System.assertEquals( expected, got, 'inSet, when called with a string field name and a set of Dates, will add an IN to the generated SOQL' ); } + @isTest + private static void isSet_stringName_dateValues_whenGivenAnEmptySet_throwsAnException() // NOPMD: Test method name format + { + ortoo_Criteria criteria = new ortoo_Criteria(); + Test.startTest(); + String exceptionMessage; + try + { + criteria.inSet( 'Account.Name', new Set() ); + } + catch ( Contract.RequiresException e ) + { + exceptionMessage = e.getMessage(); + } + Test.stopTest(); + + Amoss_Asserts.assertContains( 'inSet called with an empty values', exceptionMessage, 'isSet, when called with a string field name and an empty set of Dates, will throw an exception' ); + } + @isTest private static void inSet_field_dateTimeValues_whenCalled_addsAnInToTheGeneratedSoql() // NOPMD: Test method name format { @@ -271,6 +566,25 @@ private without sharing class ortoo_CriteriaTest System.assertEquals( expected, got, 'inSet, when called with a field and a set of DateTimes, will add an IN to the generated SOQL' ); } + @isTest + private static void isSet_field_dateTimeValues_whenGivenAnEmptySet_throwsAnException() // NOPMD: Test method name format + { + ortoo_Criteria criteria = new ortoo_Criteria(); + Test.startTest(); + String exceptionMessage; + try + { + criteria.inSet( Account.Name, new Set() ); + } + catch ( Contract.RequiresException e ) + { + exceptionMessage = e.getMessage(); + } + Test.stopTest(); + + Amoss_Asserts.assertContains( 'inSet called with an empty values', exceptionMessage, 'isSet, when called with a field and an empty set of DateTime, will throw an exception' ); + } + @isTest private static void inSet_stringName_dateTimeValues_whenCalled_addsAnInToTheGeneratedSoql() // NOPMD: Test method name format { @@ -289,6 +603,25 @@ private without sharing class ortoo_CriteriaTest System.assertEquals( expected, got, 'inSet, when called with a string field name and a set of DateTimes, will add an IN to the generated SOQL' ); } + @isTest + private static void isSet_stringName_dateTimeValues_whenGivenAnEmptySet_throwsAnException() // NOPMD: Test method name format + { + ortoo_Criteria criteria = new ortoo_Criteria(); + Test.startTest(); + String exceptionMessage; + try + { + criteria.inSet( 'Account.Name', new Set() ); + } + catch ( Contract.RequiresException e ) + { + exceptionMessage = e.getMessage(); + } + Test.stopTest(); + + Amoss_Asserts.assertContains( 'inSet called with an empty values', exceptionMessage, 'isSet, when called with a string field name and an empty set of DateTime, will throw an exception' ); + } + @isTest private static void inSet_field_objectValues_whenCalled_addsAnInToTheGeneratedSoql() // NOPMD: Test method name format { @@ -304,6 +637,24 @@ private without sharing class ortoo_CriteriaTest System.assertEquals( expected, got, 'inSet, when called with a field and a set of DateTimes, will add an IN to the generated SOQL' ); } + @isTest + private static void isSet_field_objectValues_whenGivenAnEmptySet_throwsAnException() // NOPMD: Test method name format + { + ortoo_Criteria criteria = new ortoo_Criteria(); + Test.startTest(); + String exceptionMessage; + try + { + criteria.inSet( Account.Name, new Set() ); + } + catch ( Contract.RequiresException e ) + { + exceptionMessage = e.getMessage(); + } + Test.stopTest(); + + Amoss_Asserts.assertContains( 'inSet called with an empty values', exceptionMessage, 'isSet, when called with a field and an empty set of Objects, will throw an exception' ); + } @isTest private static void inSet_stringName_objectValues_whenCalled_addsAnInToTheGeneratedSoql() // NOPMD: Test method name format { @@ -319,6 +670,25 @@ private without sharing class ortoo_CriteriaTest System.assertEquals( expected, got, 'inSet, when called with a string field name and a set of DateTimes, will add an IN to the generated SOQL' ); } + @isTest + private static void isSet_stringName_objectValues_whenGivenAnEmptySet_throwsAnException() // NOPMD: Test method name format + { + ortoo_Criteria criteria = new ortoo_Criteria(); + Test.startTest(); + String exceptionMessage; + try + { + criteria.inSet( 'Account.Name', new Set() ); + } + catch ( Contract.RequiresException e ) + { + exceptionMessage = e.getMessage(); + } + Test.stopTest(); + + Amoss_Asserts.assertContains( 'inSet called with an empty values', exceptionMessage, 'isSet, when called with a string field name and an empty set of Objects, will throw an exception' ); + } + @isTest private static void notInSet_field_stringValues_whenCalled_addsANotInToTheGeneratedSoql() // NOPMD: Test method name format { @@ -334,6 +704,20 @@ private without sharing class ortoo_CriteriaTest System.assertEquals( expected, got, 'notInSet, when called with a field and a set of Strings, will add NOT IN to the generated SOQL' ); } + @isTest + private static void notInSet_field_stringValues_whenGivenAnEmptySet_doesNotAddToTheGeneratedSoql() // NOPMD: Test method name format + { + ortoo_Criteria criteria = new ortoo_Criteria(); + + Test.startTest(); + criteria.notInSet( Account.Name, new Set() ); + Test.stopTest(); + + String got = criteria.toSOQL(); + + System.assertEquals( '', got, 'notInSet, when called with a field and an empty set of Strings, will not add to the generated SOQL' ); + } + @isTest private static void notInSet_stringName_stringValues_whenCalled_addsNotInToTheGeneratedSoql() // NOPMD: Test method name format { @@ -349,6 +733,20 @@ private without sharing class ortoo_CriteriaTest System.assertEquals( expected, got, 'notInSet, when called with a string field name and a set of Strings, will add NOT IN to the generated SOQL' ); } + @isTest + private static void notInSet_stringName_stringValues_whenGivenAnEmptySet_doesNotAddToTheGeneratedSoql() // NOPMD: Test method name format + { + ortoo_Criteria criteria = new ortoo_Criteria(); + + Test.startTest(); + criteria.notInSet( 'Account.Name', new Set() ); + Test.stopTest(); + + String got = criteria.toSOQL(); + + System.assertEquals( '', got, 'notInSet, when called with a string name and an empty set of Strings, will not add to the generated SOQL' ); + } + @isTest private static void notInSet_field_longValues_whenCalled_addsNotInToTheGeneratedSoql() // NOPMD: Test method name format { @@ -364,6 +762,20 @@ private without sharing class ortoo_CriteriaTest System.assertEquals( expected, got, 'notInSet, when called with a field and a set of Longs, will add NOT IN to the generated SOQL' ); } + @isTest + private static void notInSet_field_longValues_whenGivenAnEmptySet_doesNotAddToTheGeneratedSoql() // NOPMD: Test method name format + { + ortoo_Criteria criteria = new ortoo_Criteria(); + + Test.startTest(); + criteria.notInSet( Account.Name, new Set() ); + Test.stopTest(); + + String got = criteria.toSOQL(); + + System.assertEquals( '', got, 'notInSet, when called with a field and an empty set of Longs, will not add to the generated SOQL' ); + } + @isTest private static void notInSet_stringName_longValues_whenCalled_addsNotInToTheGeneratedSoql() // NOPMD: Test method name format { @@ -379,6 +791,20 @@ private without sharing class ortoo_CriteriaTest System.assertEquals( expected, got, 'notInSet, when called with a string field name and a set of Longs, will add NOT IN to the generated SOQL' ); } + @isTest + private static void notInSet_stringName_longValues_whenGivenAnEmptySet_doesNotAddToTheGeneratedSoql() // NOPMD: Test method name format + { + ortoo_Criteria criteria = new ortoo_Criteria(); + + Test.startTest(); + criteria.notInSet( Account.Name, new Set() ); + Test.stopTest(); + + String got = criteria.toSOQL(); + + System.assertEquals( '', got, 'notInSet, when called with a string name and an empty set of Longs, will not add to the generated SOQL' ); + } + @isTest private static void notInSet_field_integerValues_whenCalled_addsNotInToTheGeneratedSoql() // NOPMD: Test method name format { @@ -394,6 +820,20 @@ private without sharing class ortoo_CriteriaTest System.assertEquals( expected, got, 'notInSet, when called with a field and a set of Integers, will add NOT IN to the generated SOQL' ); } + @isTest + private static void notInSet_field_integerValues_whenGivenAnEmptySet_doesNotAddToTheGeneratedSoql() // NOPMD: Test method name format + { + ortoo_Criteria criteria = new ortoo_Criteria(); + + Test.startTest(); + criteria.notInSet( Account.Name, new Set() ); + Test.stopTest(); + + String got = criteria.toSOQL(); + + System.assertEquals( '', got, 'notInSet, when called with a field and an empty set of Integers, will not add to the generated SOQL' ); + } + @isTest private static void notInSet_stringName_integerValues_whenCalled_addsNotInToTheGeneratedSoql() // NOPMD: Test method name format { @@ -409,6 +849,19 @@ private without sharing class ortoo_CriteriaTest System.assertEquals( expected, got, 'notInSet, when called with a string field name and a set of Integers, will add NOT IN to the generated SOQL' ); } + @isTest + private static void notInSet_stringName_IntegerValues_whenGivenAnEmptySet_doesNotAddToTheGeneratedSoql() // NOPMD: Test method name format + { + ortoo_Criteria criteria = new ortoo_Criteria(); + + Test.startTest(); + criteria.notInSet( Account.Name, new Set() ); + Test.stopTest(); + + String got = criteria.toSOQL(); + + System.assertEquals( '', got, 'notInSet, when called with a string name and an empty set of Integer, will not add to the generated SOQL' ); + } @isTest private static void notInSet_field_idValues_whenCalled_addsNotInToTheGeneratedSoql() // NOPMD: Test method name format { @@ -427,6 +880,20 @@ private without sharing class ortoo_CriteriaTest System.assertEquals( expected, got, 'notInSet, when called with a field and a set of Ids, will add NOT IN to the generated SOQL' ); } + @isTest + private static void notInSet_field_idValues_whenGivenAnEmptySet_doesNotAddToTheGeneratedSoql() // NOPMD: Test method name format + { + ortoo_Criteria criteria = new ortoo_Criteria(); + + Test.startTest(); + criteria.notInSet( Account.Name, new Set() ); + Test.stopTest(); + + String got = criteria.toSOQL(); + + System.assertEquals( '', got, 'notInSet, when called with a field and an empty set of Ids, will not add to the generated SOQL' ); + } + @isTest private static void notInSet_stringName_idValues_whenCalled_addsNotInToTheGeneratedSoql() // NOPMD: Test method name format { @@ -445,6 +912,20 @@ private without sharing class ortoo_CriteriaTest System.assertEquals( expected, got, 'notInSet, when called with a string field name and a set of Ids, will add NOT IN to the generated SOQL' ); } + @isTest + private static void notInSet_stringName_idValues_whenGivenAnEmptySet_doesNotAddToTheGeneratedSoql() // NOPMD: Test method name format + { + ortoo_Criteria criteria = new ortoo_Criteria(); + + Test.startTest(); + criteria.notInSet( 'Account.Name', new Set() ); + Test.stopTest(); + + String got = criteria.toSOQL(); + + System.assertEquals( '', got, 'notInSet, when called with a string name and an empty set of Ids, will not add to the generated SOQL' ); + } + @isTest private static void notInSet_field_doubleValues_whenCalled_addsNotInToTheGeneratedSoql() // NOPMD: Test method name format { @@ -460,6 +941,20 @@ private without sharing class ortoo_CriteriaTest System.assertEquals( expected, got, 'notInSet, when called with a field and a set of Doubles, will add NOT IN to the generated SOQL' ); } + @isTest + private static void notInSet_field_doubleValues_whenGivenAnEmptySet_doesNotAddToTheGeneratedSoql() // NOPMD: Test method name format + { + ortoo_Criteria criteria = new ortoo_Criteria(); + + Test.startTest(); + criteria.notInSet( Account.Name, new Set() ); + Test.stopTest(); + + String got = criteria.toSOQL(); + + System.assertEquals( '', got, 'notInSet, when called with a field and an empty set of Doubles, will not add to the generated SOQL' ); + } + @isTest private static void notInSet_stringName_doubleValues_whenCalled_addsNotInToTheGeneratedSoql() // NOPMD: Test method name format { @@ -475,6 +970,20 @@ private without sharing class ortoo_CriteriaTest System.assertEquals( expected, got, 'notInSet, when called with a string field name and a set of Doubles, will add NOT IN to the generated SOQL' ); } + @isTest + private static void notInSet_stringName_doubleValues_whenGivenAnEmptySet_doesNotAddToTheGeneratedSoql() // NOPMD: Test method name format + { + ortoo_Criteria criteria = new ortoo_Criteria(); + + Test.startTest(); + criteria.notInSet( 'Account.Name', new Set() ); + Test.stopTest(); + + String got = criteria.toSOQL(); + + System.assertEquals( '', got, 'notInSet, when called with a string name and an empty set of Doubles, will not add to the generated SOQL' ); + } + @isTest private static void notInSet_field_decimalValues_whenCalled_addsNotInToTheGeneratedSoql() // NOPMD: Test method name format { @@ -490,6 +999,20 @@ private without sharing class ortoo_CriteriaTest System.assertEquals( expected, got, 'notInSet, when called with a field and a set of Decimals, will add NOT IN to the generated SOQL' ); } + @isTest + private static void notInSet_field_decimalValues_whenGivenAnEmptySet_doesNotAddToTheGeneratedSoql() // NOPMD: Test method name format + { + ortoo_Criteria criteria = new ortoo_Criteria(); + + Test.startTest(); + criteria.notInSet( Account.Name, new Set() ); + Test.stopTest(); + + String got = criteria.toSOQL(); + + System.assertEquals( '', got, 'notInSet, when called with a field and an empty set of Decimals, will not add to the generated SOQL' ); + } + @isTest private static void notInSet_stringName_decimalValues_whenCalled_addsNotInToTheGeneratedSoql() // NOPMD: Test method name format { @@ -505,6 +1028,20 @@ private without sharing class ortoo_CriteriaTest System.assertEquals( expected, got, 'notInSet, when called with a string field name and a set of Decimals, will add NOT IN to the generated SOQL' ); } + @isTest + private static void notInSet_stringName_decimalValues_whenGivenAnEmptySet_doesNotAddToTheGeneratedSoql() // NOPMD: Test method name format + { + ortoo_Criteria criteria = new ortoo_Criteria(); + + Test.startTest(); + criteria.notInSet( Account.Name, new Set() ); + Test.stopTest(); + + String got = criteria.toSOQL(); + + System.assertEquals( '', got, 'notInSet, when called with a string name and an empty set of Decimals, will not add to the generated SOQL' ); + } + @isTest private static void notInSet_field_dateValues_whenCalled_addsNotInToTheGeneratedSoql() // NOPMD: Test method name format { @@ -523,6 +1060,20 @@ private without sharing class ortoo_CriteriaTest System.assertEquals( expected, got, 'notInSet, when called with a field and a set of Dates, will add NOT IN to the generated SOQL' ); } + @isTest + private static void notInSet_field_dateValues_whenGivenAnEmptySet_doesNotAddToTheGeneratedSoql() // NOPMD: Test method name format + { + ortoo_Criteria criteria = new ortoo_Criteria(); + + Test.startTest(); + criteria.notInSet( Account.Name, new Set() ); + Test.stopTest(); + + String got = criteria.toSOQL(); + + System.assertEquals( '', got, 'notInSet, when called with a field and an empty set of Dates, will not add to the generated SOQL' ); + } + @isTest private static void notInSet_stringName_dateValues_whenCalled_addsNotInToTheGeneratedSoql() // NOPMD: Test method name format { @@ -541,6 +1092,20 @@ private without sharing class ortoo_CriteriaTest System.assertEquals( expected, got, 'notInSet, when called with a string field name and a set of Dates, will add NOT IN to the generated SOQL' ); } + @isTest + private static void notInSet_stringName_dateValues_whenGivenAnEmptySet_doesNotAddToTheGeneratedSoql() // NOPMD: Test method name format + { + ortoo_Criteria criteria = new ortoo_Criteria(); + + Test.startTest(); + criteria.notInSet( 'Account.Name', new Set() ); + Test.stopTest(); + + String got = criteria.toSOQL(); + + System.assertEquals( '', got, 'notInSet, when called with a string name and an empty set of Dates, will not add to the generated SOQL' ); + } + @isTest private static void notInSet_field_dateTimeValues_whenCalled_addsNotInToTheGeneratedSoql() // NOPMD: Test method name format { @@ -559,6 +1124,20 @@ private without sharing class ortoo_CriteriaTest System.assertEquals( expected, got, 'notInSet, when called with a field and a set of DateTimes, will add NOT IN to the generated SOQL' ); } + @isTest + private static void notInSet_field_dateTimeValues_whenGivenAnEmptySet_doesNotAddToTheGeneratedSoql() // NOPMD: Test method name format + { + ortoo_Criteria criteria = new ortoo_Criteria(); + + Test.startTest(); + criteria.notInSet( Account.Name, new Set() ); + Test.stopTest(); + + String got = criteria.toSOQL(); + + System.assertEquals( '', got, 'notInSet, when called with a field and an empty set of DateTime, will not add to the generated SOQL' ); + } + @isTest private static void notInSet_stringName_dateTimeValues_whenCalled_addsNotInToTheGeneratedSoql() // NOPMD: Test method name format { @@ -577,6 +1156,20 @@ private without sharing class ortoo_CriteriaTest System.assertEquals( expected, got, 'notInSet, when called with a string field name and a set of DateTimes, will add NOT IN to the generated SOQL' ); } + @isTest + private static void notInSet_stringName_dateTimeValues_whenGivenAnEmptySet_doesNotAddToTheGeneratedSoql() // NOPMD: Test method name format + { + ortoo_Criteria criteria = new ortoo_Criteria(); + + Test.startTest(); + criteria.notInSet( 'Account.Name', new Set() ); + Test.stopTest(); + + String got = criteria.toSOQL(); + + System.assertEquals( '', got, 'notInSet, when called with a string name and an empty set of DateTime, will not add to the generated SOQL' ); + } + @isTest private static void notInSet_field_objectValues_whenCalled_addsNotInToTheGeneratedSoql() // NOPMD: Test method name format { @@ -592,6 +1185,20 @@ private without sharing class ortoo_CriteriaTest System.assertEquals( expected, got, 'notInSet, when called with a field and a set of DateTimes, will add NOT IN to the generated SOQL' ); } + @isTest + private static void notInSet_field_objectValues_whenGivenAnEmptySet_doesNotAddToTheGeneratedSoql() // NOPMD: Test method name format + { + ortoo_Criteria criteria = new ortoo_Criteria(); + + Test.startTest(); + criteria.notInSet( Account.Name, new Set() ); + Test.stopTest(); + + String got = criteria.toSOQL(); + + System.assertEquals( '', got, 'notInSet, when called with a field and an empty set of Objects, will not add to the generated SOQL' ); + } + @isTest private static void notInSet_stringName_objectValues_whenCalled_addsNotInToTheGeneratedSoql() // NOPMD: Test method name format { @@ -607,4 +1214,17 @@ private without sharing class ortoo_CriteriaTest System.assertEquals( expected, got, 'notInSet, when called with a string field name and a set of DateTimes, will add NOT IN to the generated SOQL' ); } + @isTest + private static void notInSet_stringName_objectValues_whenGivenAnEmptySet_doesNotAddToTheGeneratedSoql() // NOPMD: Test method name format + { + ortoo_Criteria criteria = new ortoo_Criteria(); + + Test.startTest(); + criteria.notInSet( 'Account.Name', new Set() ); + Test.stopTest(); + + String got = criteria.toSOQL(); + + System.assertEquals( '', got, 'notInSet, when called with a string name and an empty set of Object, will not add to the generated SOQL' ); + } } \ No newline at end of file