function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Jamal ArogundadeJamal Arogundade 

Please Help: System.AssertException: Assertion Failed

Class.testUtility.test_get_membership_amount: line 89, column 1
System.AssertException: Assertion Failed


UtilityTest class

@isTest(SeeAllData=false)
private class testUtility {
    @isTest static void testDateUtility(){
    Date d1 = System.today();
    Date d2 = d1.addDays(10);
    Date d3 = null;
    system.assert(RamblersUtility.maxdate(d1, d2) == d2);
    system.assert(RamblersUtility.maxdate(d1, d3) == d1);
    system.assert(RamblersUtility.maxdate(d3, d2) == d2);
    system.assert(RamblersUtility.maxdate(d3, d3) == NULL);
    system.assert(RamblersUtility.maxdate(d2, d1) == d2);
    }
    
    @isTest static void testDecimalUtility(){
        Decimal dec1 = 1.0;
        Decimal dec2 = 2.0;
        Decimal dec3 = null;
        system.assert(RamblersUtility.maxDecimal(dec1, dec2) == dec2);
        system.assert(RamblersUtility.maxDecimal(dec1, dec3) == dec1);
        system.assert(RamblersUtility.maxDecimal(dec3, dec2) == dec2);
        system.assert(RamblersUtility.maxDecimal(dec3, dec3) == NULL);
        system.assert(RamblersUtility.maxDecimal(dec2, dec1) == dec2);
    }
    
    @istest
    static void test_get_renewal_lookup(){
        // First create a membership_amount__C
        List<npsp__Trigger_Handler__c> triggerHandlers = npsp.TDTM_Config_API.getCachedRecords(); 
        // Add our Trigger Handler to cached Trigger Handlers
        npsp__Trigger_Handler__c th = new npsp__Trigger_Handler__c();
        th.Name = 'Select_Membership_TDTM';
        th.npsp__class__c = 'Select_Membership_TDTM';
        th.npsp__Object__c = 'npe03__Recurring_Donation__c';
        th.npsp__trigger_action__c = 'BeforeInsert,BeforeUpdate';
        th.npsp__Active__c=True;
        th.npsp__load_order__c=0; 
        th.npsp__Asynchronous__c=False;
        triggerHandlers.add(th);
        membership_amount__c mem_amt = new Membership_Amount__c(Name = 'Select Membership', Start_date__c = Date.today().addDays(-45) , End_date__c = Date.today().addDays(50));
        insert mem_amt;
        system.test.startTest();
        system.test.stopTest();
        List<Membership_Amount_Line__c> ma_line_item_no_dates = ramblersutility.get_renewal_lookup(NULL, NULL);
        List<Membership_Amount_Line__c> ma_line_item_with_dates = ramblersutility.get_renewal_lookup(date.today().addDays(-1), date.today().addDays(1));
        system.assert(ma_line_item_no_dates.size()==23);
        system.assert(ma_line_item_with_dates.size()==23);
    }

    @istest
    static void test_get_membership_amount(){
        List<npsp__Trigger_Handler__c> th = npsp.TDTM_Config_API.getCachedRecords(); 
        // Add our Trigger Handler to cached Trigger Handlers
        th.add(new npsp__Trigger_Handler__c(Name='Select_Membership_TDTM', npsp__class__c='Select_Membership_TDTM', npsp__Object__c='npe03__Recurring_Donation__c', npsp__trigger_action__c='BeforeInsert,BeforeUpdate', npsp__Active__c=True, npsp__load_order__c=0, npsp__Asynchronous__c=False));
        Membership_Amount__c mem_amt = new membership_amount__c(name='Select membership', Start_date__c = Date.today().addDays(-45) , End_date__c = Date.today().addDays(50));
        insert mem_amt;
        List<Membership_Amount_Line__c> mas = RamblersUtility.get_renewal_lookup(date.today(), date.today());
        for (Membership_Amount_Line__c ma : mas){
            // We need to update this amount
            switch on string.valueof(ma.Concessionary__c) + ma.Payment_Method__c + ma.Payment_Frequency__c + ma.Membership_Type__c{ // TODO: replace the lookup to a composit key
                when 'trueDirect DebitMonthlyIndividual'{ma.amount__c = 1.0 * 12;}
                when 'trueOtherMonthlyIndividual'{ma.amount__c = 2.0 * 12;}
                when 'trueDirect DebitAnnualIndividual'{ma.amount__c = 3.0;}
                when 'trueOtherAnnualIndividual'{ma.amount__c = 4.0;}
                when 'falseDirect DebitMonthlyIndividual'{ma.amount__c = 5.0 * 12;}
                when 'falseOtherMonthlyIndividual'{ma.amount__c = 6.0 * 12;}
                when 'falseDirect DebitAnnualIndividual'{ma.amount__c = 7.0;}
                when 'falseOtherAnnualIndividual'{ma.amount__c = 8.0;}
                when 'trueDirect DebitMonthlyJoint'{ma.amount__c = 9.0 * 12;} 
                when 'trueOtherMonthlyJoint'{ma.amount__c = 10.0 * 12;}
                when 'trueDirect DebitAnnualJoint'{ma.amount__c = 11.0;}
                when 'trueOtherAnnualJoint'{ma.amount__c = 12.0;}
                when 'falseDirect DebitMonthlyJoint'{ma.amount__c = 13.0 * 12;}
                when 'falseOtherMonthlyJoint'{ma.amount__c = 14.0 * 12;}
                when 'falseDirect DebitAnnualJoint'{ma.amount__c = 15.0;}
                when 'falseOtherAnnualJoint'{ma.amount__c = 16.0;}
                when 'trueOtherAnnualLife'{ma.amount__c = 17.0;}
                when 'falseOtherAnnualLife'{ma.amount__c = 18.0;}
                when 'trueOtherAnnualLife Joint'{ma.amount__c = 19.0;}
                when 'falseOtherAnnualLife Joint'{ma.amount__c = 20.0;}
                when 'falseOtherAnnualArea affiliate'{ma.amount__c = 21.0;}
                when 'falseOtherAnnualNational affiliate'{ma.amount__c = 22.0;}
                when 'falseOtherAnnualCorporate'{ma.amount__c = 23.0;}
                when else {ma.amount__c = 500;}
            }
        }
        system.test.startTest();
        system.test.stoptest();
           system.assert(RamblersUtility.get_membership_amount(mas, date.today(), True, 'Monthly', 'Individual', 'Standard', 'Direct debit', NULL, NULL)==1.0);
        system.assert(RamblersUtility.get_membership_amount(mas, date.today(), True, 'Monthly', 'Individual', 'Standard', 'Other', NULL, NULL)==2.0);
        system.assert(RamblersUtility.get_membership_amount(mas, date.today(), True, 'Annual', 'Individual', 'Standard', 'Direct debit', NULL, NULL)==3.0);
        system.assert(RamblersUtility.get_membership_amount(mas, date.today(), True, 'Annual', 'Individual', 'Standard', 'Other', NULL, NULL)==4.0);
        system.assert(RamblersUtility.get_membership_amount(mas, date.today(), False, 'Monthly', 'Individual', 'Standard', 'Direct debit', NULL, NULL)==5.0);
        system.assert(RamblersUtility.get_membership_amount(mas, date.today(), False, 'Monthly', 'Individual', 'Standard', 'Other', NULL, NULL)==6.0);
        system.assert(RamblersUtility.get_membership_amount(mas, date.today(), False, 'Annual', 'Individual', 'Standard', 'Direct debit', NULL, NULL)==7.0);
        system.assert(RamblersUtility.get_membership_amount(mas, date.today(), False, 'Annual', 'Individual', 'Standard', 'Other', NULL, NULL)==8.0);
        system.assert(RamblersUtility.get_membership_amount(mas, date.today(), True, 'Monthly', 'Joint', 'Standard', 'Direct debit', NULL, NULL)==9.0);
        system.assert(RamblersUtility.get_membership_amount(mas, date.today(), True, 'Monthly', 'Joint', 'Standard', 'Other', NULL, NULL)==10.0);
        system.assert(RamblersUtility.get_membership_amount(mas, date.today(), True, 'Annual', 'Joint', 'Standard', 'Direct debit', NULL, NULL)==11.0);
        system.assert(RamblersUtility.get_membership_amount(mas, date.today(), True, 'Annual', 'Joint', 'Standard', 'Other', NULL, NULL)==12.0);
        system.assert(RamblersUtility.get_membership_amount(mas, date.today(), False, 'Monthly', 'Joint', 'Standard', 'Direct debit', NULL, NULL)==13.0);
        system.assert(RamblersUtility.get_membership_amount(mas, date.today(), False, 'Monthly', 'Joint', 'Standard', 'Other', NULL, NULL)==14.0);
        system.assert(RamblersUtility.get_membership_amount(mas, date.today(), False, 'Annual', 'Joint', 'Standard', 'Direct debit', NULL, NULL)==15.0);
        system.assert(RamblersUtility.get_membership_amount(mas, date.today(), False, 'Annual', 'Joint', 'Standard', 'Other', NULL, NULL)==16.0);
        system.assert(RamblersUtility.get_membership_amount(mas, date.today(), True, 'Annual', 'Individual', 'Life', 'Other', NULL, NULL)==17.0);
        system.assert(RamblersUtility.get_membership_amount(mas, date.today(), False, 'Annual', 'Individual', 'Life', 'Other', NULL, NULL)==18.0);
        system.assert(RamblersUtility.get_membership_amount(mas, date.today(), True, 'Annual', 'Joint', 'Life', 'Other', NULL, NULL)==19.0);
        system.assert(RamblersUtility.get_membership_amount(mas, date.today(), False, 'Annual', 'Joint', 'Life', 'Other', NULL, NULL)==20.0);
        system.assert(RamblersUtility.get_membership_amount(mas, date.today(), False, 'Annual', 'Area affiliate', 'Organisation', 'Other', NULL, NULL)==21.0);
        system.assert(RamblersUtility.get_membership_amount(mas, date.today(), False, 'Annual', 'National affiliate', 'Organisation', 'Other', NULL, NULL)==22.0);
        system.assert(RamblersUtility.get_membership_amount(mas, date.today(), False, 'Annual', 'Corporate', 'Organisation', 'Other', NULL, NULL)==23.0);
        system.assert(RamblersUtility.get_membership_amount(mas, date.today(), True, 'Monthly', 'Joint', 'Standard', 'Other', 100, NULL)==0.0);
        system.assert(RamblersUtility.get_membership_amount(mas, date.today(), True, 'Monthly', 'Joint', 'Standard', 'Other', NULL, 120.0)==0.0);
    }

    @istest
    static void test_installments_per_year(){
        map<string, integer> test_map = new map<string, integer>{'Yearly' => 1, 'Quarterly' => 4, 'Monthly' => 12, 'default' => 1};
        for (string s : test_map.keySet()){
            system.assert(ramblersutility.installments_per_year(s) == test_map.get(s));
        }
    }
}

Renewal Job

 
Abhishek BansalAbhishek Bansal
Hi Jamal,

It is clear that your assertion at the lin no. 89 is failing due to mismatch in the result that you expect and what is returned from the class. Please use the debug statement to identify which value is missing or incorrect that is leading to this mismatch.
Please check the code in your main class and make sure that all the variables are records are properly set in the test class.

Thanks,
Abhishek Bansal.
Jamal ArogundadeJamal Arogundade
Thank you so much, the record type was meant to be Standard (Annual) instead of Standard