• Smiley Bindu
  • NEWBIE
  • 0 Points
  • Member since 2012

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 3
    Replies

Hi,

 

We are struggling with the code coverage for the Trigger below.  The Test Class code is below as well.  Any assistance and/or guidance would be greatly appreciated!!

 

Cheers,

Bindu & Jason

 

 

TRIGGER

trigger UpdateQuote on QuoteLineItem(before insert,before update)

{

        for(QuoteLineItem qout : trigger.New )

        {          

if(qout.Product_Name__c == 'Testing Product')

            {                                                 

if(qout.Annual_Vol__c <> NULL )

                {                                       

if(qout.Annual_Vol__c >=  0 && qout.Annual_Vol__c <= 100000)

                   {                       

                      qout.UnitPrice = 350 ;           

                   }

               }

              qout.Quantity = 1 ;    

           }

     }

 }   

 

 

 

 

TEST CLASS:

@isTest
   public class UpdateQuoteTest{
    //private static testmethod void testGetters()
    
    static testMethod void UpdateQuoteTest()
    {
       // Pricebook2 standardPB = [select id from Pricebook2 limit 1];
       
        Pricebook2 pb = new Pricebook2(Name = 'Standard Price Book 2009', Description = 'Price Book 2009 Products', IsActive = true );
        insert pb;
        Product2 prod = new Product2(Name = 'Testing Product', Family = 'Best Practices', IsActive = true);
        insert prod;
         List<Pricebook2> standardPbList = [select id, name, isActive from Pricebook2 where IsStandard = true ];
     //   PricebookEntry standardPrice = new PricebookEntry(Pricebook2Id = pb.Id, Product2Id = prod.Id, UnitPrice = 10000, IsActive = true, UseStandardPrice = false);
    //    insert standardPrice;
    List<PricebookEntry> listPriceBook = new List<PricebookEntry>();
     for(Pricebook2 p : standardPbList ){
      PricebookEntry pbe = New PricebookEntry ();
      pbe = new PricebookEntry(Pricebook2Id = p.Id, Product2Id = prod.Id, UnitPrice = 10000, IsActive = true, UseStandardPrice = false);
       listPriceBook.add(pbe);
     }
        insert listPriceBook;
        Opportunity opp = new Opportunity(Name = 'Test Syndicated 2010', Type = 'Syndicated - New', StageName = 'Planning', CloseDate = system.today());
        insert opp;
        List<OpportunityLineItem> opplineList = new List<OpportunityLineItem>();
       for(PricebookEntry pricebook : listPriceBook){
            OpportunityLineItem oli = new OpportunityLineItem ();
            oli  = new OpportunityLineItem(opportunityId = opp.Id, pricebookentryId = pricebook.Id, Quantity = 1, UnitPrice = 7500, Description = '2007 CMR #4 - Anti-Infectives');
            opplineList.add(oli);
       }
       insert opplineList;
     //   List<OpportunityLineItem> olis = [Select Id From OpportunityLineItem Where OpportunityId =: opp.Id];
     //   update olis[0];
        Quote quttest = new Quote (Name = 'qoutetest' , OpportunityId = opp.id , Pricebook2Id = pb.id );
        insert quttest ;
        List<QuoteLineItem> listval = new   List<QuoteLineItem>();
        Integer Annualvalue = 1000 ;
        for(PricebookEntry pricebook : listPriceBook){
            QuoteLineItem qutlineitemtest = new QuoteLineItem ();
            qutlineitemtest = new QuoteLineItem(QuoteId = quttest .id , Quantity = 3.00 ,Annual_Vol__c = Annualvalue ,UnitPrice = 12 , PricebookEntryId = pricebook.id);
            
            listval.add(qutlineitemtest);
            Annualvalue = Annualvalue + 1000;
         }
       insert listval;
    }
}

 

I need some help wrapping my head around testing this trigger - I seem to have prepared and inserted my dataset correct, but I'm not sure why it's giving me an error of "Expected:Null".

 

My Trigger (working in sandbox, manually inserting records)

 

trigger AddCountyId on Contact (before insert, before update) {
	
    Set<String> CountyIds = new Set<String>();
    
    for(Contact c : Trigger.new) {       
       CountyIds.add(c.fdicCountyID__c);       
    }       
    
    Map<String, Id> countyMap = new Map<String,Id>();

	//Add both sets of IDS to above Map
	for(County__c cty : [SELECT cty.Id, cty.fdicCountyID__c
		FROM County__c cty
		WHERE cty.fdicCountyID__c != null AND cty.fdicCountyID__c IN :CountyIds]) {
    		countyMap.put(cty.fdicCountyID__c, cty.Id);
		}    
  
  	//Update Primary County on the Contact with County ID
    for(Contact updateC : Trigger.new) {
	    try {    
	          if(updateC.fdicCountyID__c != null) {
	  			  //Update Primary County with County Id from Map
	              updateC.Primary_County__c = countyMap.get(updateC.fdicCountyID__c);
	          }
	    }  
	    catch (Exception e) {
	   	}
	}

}

 

Stripped down test method in my test class

 

	static testMethod void verifyCountyId() {
		
		//Create Test County
  		County__c cty = new County__c(Name='Test County', Latitude__c = 1, Longitude__c = 1, fdicCountyId__c ='abcd1234');
  		insert cty;
		
		//Create Test Vendor
		Account vAcct = new Account(Name = 'Test Vendor Account');
		insert vAcct;
		Contact v = new Contact(LastName = 'Vendor Demo', last_engaged_date__c = Date.today(), AccountId = vAcct.Id, fdicCountyId__c = 'abcd1234');
		insert v;
		
		System.assertEquals (v.Primary_County_ID__c, cty.Id);
	}

 I get a System.AssertException: Assertion Failed: Expected:null Actual: a0hJ000000FymvMac 

 

Does anyone have any insight as to what i'm doing wrong?

  • February 27, 2012
  • Like
  • 0