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
GurunathGurunath 

Test Coverage Help

Controller Class Is:

 

public class VoucherContactReport{

public String Voucherid {get; set;}
public Integer NumberEventsBenefiting{get; set;}
public Integer NumberEventsBenefiting3{get; set;}
public Integer NumberEventsBenefiting6{get; set;}
public Integer NumberEventsBenefiting12{get; set;}

public Integer NumberEventsBenefitingAllTime{get; set;}
public Integer CountOfEB{get; set;}
Public String CountOfEB1{get;set;}

public static string TotalCount1{get; set;}
public static string TotalCountUsed1{get; set;}



public Integer TotalRaffles{get; set;}
public Integer TotalRaffles3{get; set;}
public Integer TotalRaffles6{get; set;}
public Integer TotalRaffles12{get; set;}
public Integer TotalRafflesAllTime{get; set;}
public Integer LegacyRaffles{get; set;}

public string TotalOfLegacyRaffles{get;set;}
public static string TotalRafflesAllTime1{get; set;}
public static string LegacyRaffles1{get; set;}

public Integer TotalEvents{get; set;}
public Integer TotalEvents3{get; set;}
public Integer TotalEvents6{get; set;}
public Integer TotalEvents12{get; set;}

public Integer TotalEventsAllTime{get; set;}
public Integer LegacyEvent{get; set;}

public string TotalOfLegacyEvent{get;set;}
public static string TotalEventsAllTime1{get; set;}
public static string LegacyEvent1{get; set;}

public List<Voucher__c> RelatedVoucher;
public List<Voucher__c> RelatedVoucher3;
public List<Voucher__c> RelatedVoucher6;
public List<Voucher__c> RelatedVoucher12;
public List<Voucher__c> RelatedVoucherAllTime;
public List<Treasure_Chest_Application__c> RelatedTreasureChestApplications{get; set;}




public VoucherContactReport(){


}


public List<Voucher__c> getRelatedVoucher() {

NumberEventsBenefiting = 0;
TotalRaffles = 0;
TotalEvents = 0;
RelatedVoucher = new List<Voucher__c>();
RelatedTreasureChestApplications = new List<Treasure_Chest_Application__c>();
// this.Voucherid = 'a1Ac0000000VaCi';
if(Voucherid != null && Voucherid!= ''){


//Added for Count of the Event Benifiting



for(Voucher__c queryvouchers : [select Total_Amount_Raised_for_Events__c,Total_Amount_Raised_for_Vouchers__c,Number_of_Events_Benefiting__c,Term__c,
Name,CreatedDate, (select Amount_Raised_for_Event__c,CreatedDate,Stage__c, Date_Accepted__c,
Amount_Raised_for_Voucher__c, Location_of_event__c,Name_of_the_Event__c,
Date_of_the_Event__c,Temporary_Voucher__r.Account__r.Name
from Treasure_Chest_Applications__r )
from Voucher__c where id=: Voucherid ]){

for(Treasure_Chest_Application__c TCA :queryvouchers.Treasure_Chest_Applications__r){
if(TCA.Date_of_the_Event__c != null ){

if((date.today().month() - TCA.Date_of_the_Event__c.month() <= 1) && (date.today().year() == TCA.Date_of_the_Event__c.year())){

RelatedVoucher.add(queryvouchers);
}
}
}
}
for(Voucher__c CalVouchers : RelatedVoucher ){
TotalRaffles = 0 ;
TotalEvents = 0 ;
NumberEventsBenefiting = 0;

for(Treasure_Chest_Application__c TCA1 :CalVouchers.Treasure_Chest_Applications__r){
if(TCA1.Date_of_the_Event__c != null && TCA1.Amount_Raised_for_Voucher__c != null && TCA1.Amount_Raised_for_Event__c != null ){

if((date.today().month() - TCA1.Date_of_the_Event__c.month() <= 1) && (date.today().year() == TCA1.Date_of_the_Event__c.year())){


// NumberEventsBenefiting += Integer.valueOf(TCA1.get('expr0'));
NumberEventsBenefiting++;
TotalRaffles += Integer.valueOf(TCA1.Amount_Raised_for_Voucher__c);
TotalEvents += Integer.valueOf(TCA1.Amount_Raised_for_Event__c);
system.debug('&&&&&&&&&&&&&&&&&&&&&&&&&&&'+ TotalRaffles);
}
}
}
}
}
return RelatedVoucher;
}




public List<Voucher__c> getRelatedVoucher3() {

NumberEventsBenefiting3 = 0;
TotalRaffles3 = 0;
TotalEvents3 = 0;
RelatedVoucher3 = new List<Voucher__c>();
system.debug('*******************************'+ RelatedVoucher3);


if(Voucherid != null && Voucherid!= ''){


for(Voucher__c queryvouchers : [select Total_Amount_Raised_for_Events__c,Total_Amount_Raised_for_Vouchers__c,Number_of_Events_Benefiting__c,Term__c,
Name,CreatedDate, (select Amount_Raised_for_Event__c,CreatedDate,Stage__c, Date_Accepted__c,
Amount_Raised_for_Voucher__c, Location_of_event__c,Name_of_the_Event__c,
Date_of_the_Event__c,Temporary_Voucher__r.Account__r.Name
from Treasure_Chest_Applications__r )
from Voucher__c where id=: Voucherid ]){

for(Treasure_Chest_Application__c TCA :queryvouchers.Treasure_Chest_Applications__r){
if(TCA.Date_of_the_Event__c != null){


if((date.today().month() - TCA.Date_of_the_Event__c.month() <= 3) && (date.today().year() == TCA.Date_of_the_Event__c.year())){
RelatedVoucher3.add(queryvouchers);
}
}
}
}
for(Voucher__c CalVouchers : RelatedVoucher3 ){
TotalRaffles3 = 0 ;
TotalEvents3 = 0 ;
NumberEventsBenefiting3 = 0;
for(Treasure_Chest_Application__c TCA1 :CalVouchers.Treasure_Chest_Applications__r){

if(TCA1.Date_of_the_Event__c != null && TCA1.Amount_Raised_for_Voucher__c != null && TCA1.Amount_Raised_for_Event__c != null){
if((date.today().month() - TCA1.Date_of_the_Event__c.month() <= 3) && (date.today().year() == TCA1.Date_of_the_Event__c.year())){

// NumberEventsBenefiting3 = Integer.valueOf(CalVouchers.Number_of_Events_Benefiting__c);
NumberEventsBenefiting3 ++;
TotalRaffles3 += Integer.valueOf(TCA1.Amount_Raised_for_Voucher__c);
TotalEvents3 += Integer.valueOf(TCA1.Amount_Raised_for_Event__c);
}

}
}
}
}

return RelatedVoucher3;

}

 


public List<Voucher__c> getRelatedVoucher6() {

NumberEventsBenefiting6 = 0;
TotalRaffles6 = 0;
TotalEvents6 = 0;
RelatedVoucher6 = new List<Voucher__c>();

if(Voucherid != null && Voucherid!= ''){

for(Voucher__c queryvouchers : [select Total_Amount_Raised_for_Events__c,Total_Amount_Raised_for_Vouchers__c,Number_of_Events_Benefiting__c,Term__c,
Name,CreatedDate, (select Amount_Raised_for_Event__c,CreatedDate,Stage__c, Date_Accepted__c,
Amount_Raised_for_Voucher__c, Location_of_event__c,Name_of_the_Event__c,
Date_of_the_Event__c,Temporary_Voucher__r.Account__r.Name
from Treasure_Chest_Applications__r)
from Voucher__c where id=: Voucherid ]){

for(Treasure_Chest_Application__c TCA :queryvouchers.Treasure_Chest_Applications__r){
if(TCA.Date_of_the_Event__c != null){


if((date.today().month() - TCA.Date_of_the_Event__c.month() <= 6) && (date.today().year() == TCA.Date_of_the_Event__c.year())){
RelatedVoucher6.add(queryvouchers);
}
}
}
}
for(Voucher__c CalVouchers : RelatedVoucher6 ){
TotalRaffles6 = 0;
TotalEvents6 = 0;
NumberEventsBenefiting6 = 0;

for(Treasure_Chest_Application__c TCA1 :CalVouchers.Treasure_Chest_Applications__r){
if(TCA1.Date_of_the_Event__c != null && TCA1.Amount_Raised_for_Voucher__c != null && TCA1.Amount_Raised_for_Event__c != null ){

if((date.today().month() - TCA1.Date_of_the_Event__c.month() <= 6) && (date.today().year() == TCA1.Date_of_the_Event__c.year())){

// NumberEventsBenefiting6 = Integer.valueOf(CalVouchers.Number_of_Events_Benefiting__c);
NumberEventsBenefiting6++;
TotalRaffles6 += Integer.valueOf(TCA1.Amount_Raised_for_Voucher__c);
TotalEvents6 += Integer.valueOf(TCA1.Amount_Raised_for_Event__c);
}
}
}
}
}
return RelatedVoucher6;
}

 

public List<Voucher__c> getRelatedVoucher12() {

NumberEventsBenefiting12 = 0;
TotalRaffles12 = 0;
TotalEvents12 = 0;
RelatedVoucher12 = new List<Voucher__c>();

if(Voucherid != null && Voucherid!= ''){

for(Voucher__c queryvouchers : [select Total_Amount_Raised_for_Events__c,Total_Amount_Raised_for_Vouchers__c,Number_of_Events_Benefiting__c,Term__c,
Name,CreatedDate, Legacy_Amount_Raised_for_Events__c,(select Amount_Raised_for_Event__c,CreatedDate,Stage__c, Date_Accepted__c,
Amount_Raised_for_Voucher__c, Location_of_event__c,Name_of_the_Event__c,
Date_of_the_Event__c,Temporary_Voucher__r.Account__r.Name
from Treasure_Chest_Applications__r )
from Voucher__c where id=: Voucherid ]){

for(Treasure_Chest_Application__c TCA :queryvouchers.Treasure_Chest_Applications__r){
if(TCA.Date_of_the_Event__c != null){



if((date.today().month() - TCA.Date_of_the_Event__c.month() <= 12) && (date.today().year() == TCA.Date_of_the_Event__c.year())){
RelatedVoucher12.add(queryvouchers);
}

}
}
}
for(Voucher__c CalVouchers : RelatedVoucher12 ){
TotalRaffles12 = 0;
TotalEvents12 = 0;
NumberEventsBenefiting12 = 0;


for(Treasure_Chest_Application__c TCA1 :CalVouchers.Treasure_Chest_Applications__r){
if(TCA1.Date_of_the_Event__c != null && TCA1.Amount_Raised_for_Voucher__c != null && TCA1.Amount_Raised_for_Event__c != null ){

if((date.today().month() - TCA1.Date_of_the_Event__c.month() <= 12) && (date.today().year() == TCA1.Date_of_the_Event__c.year())){
// NumberEventsBenefiting12 = Integer.valueOf(CalVouchers.Number_of_Events_Benefiting__c);
NumberEventsBenefiting12++;
TotalRaffles12 += Integer.valueOf(TCA1.Amount_Raised_for_Voucher__c);
TotalEvents12 += Integer.valueOf(TCA1.Amount_Raised_for_Event__c);
}
}
}
}
}
return RelatedVoucher12;
}

 


public List<Voucher__c> getRelatedVoucherAllTime() {

NumberEventsBenefitingAllTime = 0;
TotalRafflesAllTime = 0;
TotalEventsAllTime = 0;

RelatedVoucherAllTime = new List<Voucher__c>();

if(Voucherid != null && Voucherid!= ''){
for(Voucher__c queryvouchers : [select Total_Amount_Raised_for_Events__c,Total_Amount_Raised_for_Vouchers__c,Number_of_Events_Benefiting__c,Term__c,
Name,CreatedDate,Legacy_Amount_Raised_for_Vouchers__c,Legacy_Amount_Raised_for_Events__c,Legacy_Used__c, (select Amount_Raised_for_Event__c,CreatedDate,Stage__c, Date_Accepted__c,
Amount_Raised_for_Voucher__c, Location_of_event__c,Name_of_the_Event__c,
Date_of_the_Event__c,Temporary_Voucher__r.Account__r.Name
from Treasure_Chest_Applications__r )
from Voucher__c where id=: Voucherid ]){

for(Treasure_Chest_Application__c TCA :queryvouchers.Treasure_Chest_Applications__r){
if(TCA.Date_of_the_Event__c != null){



if( (TCA.Date_of_the_Event__c <= date.today()) && (date.today().year() >= TCA.Date_of_the_Event__c.year())) {
RelatedVoucherAllTime.add(queryvouchers);
}

}
}
// RelatedVoucherAllTime.add(queryvouchers);
}
for(Voucher__c CalVouchers : RelatedVoucherAllTime ){

TotalRafflesAllTime = 0;
TotalEventsAllTime = 0;
NumberEventsBenefitingAllTime = 0;


for(Treasure_Chest_Application__c TCA1 :CalVouchers.Treasure_Chest_Applications__r){
if(TCA1.Date_of_the_Event__c != null && TCA1.Amount_Raised_for_Voucher__c != null && TCA1.Amount_Raised_for_Event__c != null ){

if (TCA1.Date_of_the_Event__c <= date.today()) {

NumberEventsBenefitingAllTime++;

integer Count1 = NumberEventsBenefitingAllTime;

CountOfEB1 = String.ValueOf(Count1);
CountOfEB = Integer.ValueOf(CalVouchers.Legacy_Used__c );
TotalCount1 = String.ValueOf(CountOfEB);
TotalCountUsed1 = CountOfEB1+' '+'('+'+'+TotalCount1+')';


TotalRafflesAllTime += Integer.valueOf(TCA1.Amount_Raised_for_Voucher__c) ;
TotalRafflesAllTime1 = String.valueOf(TotalRafflesAllTime );


LegacyRaffles = Integer.ValueOf(CalVouchers.Legacy_Amount_Raised_for_Vouchers__c );
LegacyRaffles1 = String.valueOf( LegacyRaffles);
TotalOfLegacyRaffles = TotalRafflesAllTime1+' '+'('+'+'+LegacyRaffles1+')' ;

TotalEventsAllTime += Integer.valueOf(TCA1.Amount_Raised_for_Event__c);
TotalEventsAllTime1 = String.valueOf(TotalEventsAllTime);

LegacyEvent = Integer.ValueOf(CalVouchers.Legacy_Amount_Raised_for_Events__c );
LegacyEvent1 = String.valueOf(LegacyEvent );
TotalOfLegacyEvent = TotalEventsAllTime1+' '+'('+'+'+LegacyEvent1+')';

}
}
}
}

}
return RelatedVoucherAllTime;
}

public List<Treasure_Chest_Application__c> getRTCA() {



RelatedTreasureChestApplications = new List<Treasure_Chest_Application__c>();

if(Voucherid != null && Voucherid!= ''){


for(Treasure_Chest_Application__c TreasureChests : [select Amount_Raised_for_Event__c,CreatedDate,Stage__c, Date_Accepted__c, Amount_Raised_for_Voucher__c, Location_of_event__c,Name_of_the_Event__c,
Date_of_the_Event__c,Temporary_Voucher__r.Account__r.Name from Treasure_Chest_Application__c where Temporary_Voucher__c =: Voucherid AND (Date_Accepted__c = LAST_N_DAYS:30 OR Date_of_the_Event__c = LAST_N_DAYS:30) ]){
// if(date.today().month() - TreasureChests.Date_of_the_Event__c.month() <= 1 && (date.today().year() == TreasureChests.Date_of_the_Event__c.year()) || (date.today().month() - TreasureChests.Date_Accepted__c .month() <= 1 && (date.today().year() == TreasureChests.Date_Accepted__c .year()))){
RelatedTreasureChestApplications.add(TreasureChests);
// }

}
}
return RelatedTreasureChestApplications;
}

}

 

Test Class For this is:

===================

 

@isTest(seeAllData = true)
Public class TestVoucherContactReport{
public Integer TotalRaffles = 0;
public Integer TotalEvents = 0;
public Integer NumberEventsBenefiting =0;
public static testMethod void testVoucherContactReport() {


Account newAcc = new Account();
newAcc.Name = 'Test Account';
newAcc.Post_Code__c = '11111';
newAcc.Address_Line_1__c = 'Test Account';
newAcc.Website = 'Test Account';
newAcc.Address_Line_2__c = 'Test Account';
newAcc.Charity_number__c = 321231 ;
newAcc.City__c = 'Test Account';
newAcc.Phone = '323424' ;
newAcc.County__c = 'Test Account';
newAcc.Where_do_we_post_your_prize_voucher__c = 'Test Account';
insert newAcc;


Voucher__c TemporaryVoucher = new Voucher__c();
TemporaryVoucher.Name = 'Manchester United Tickets';
TemporaryVoucher.Account__c = newAcc.Id;
TemporaryVoucher.Start_Date__c = date.today();
TemporaryVoucher.End_Date__c = date.today();
TemporaryVoucher.Term__c = '1 Month';
TemporaryVoucher.Legacy_Used__c = 2;
//TemporaryVoucher.Number_of_Events_Benefiting__c = 6;
TemporaryVoucher.Legacy_Amount_Raised_for_Events__c = 2;
TemporaryVoucher.Legacy_Amount_Raised_for_Vouchers__c = 8;

insert TemporaryVoucher;

System.assertEquals(TemporaryVoucher.Legacy_Used__c,2);

Contact C = new Contact();
c.LastName = 'Contact';
c.AccountId = newAcc .id;
c.Email = 'rshruthig@moldtekindia.com';
Insert C;
System.assertEquals(c.Email,'rshruthig@moldtekindia.com');

Campaign Camp = new Campaign();
Camp.Name = 'Test Campaign';
insert Camp;
System.assertEquals(Camp.Name,'Test Campaign');
Treasure_Chest_Application__c TCApp = new Treasure_Chest_Application__c();
TCApp.Amount_Raised_for_Event__c = 800.00;
TCApp.Amount_Raised_for_Voucher__c = 900.00;
TCApp.Campaign__c = '701c00000001mCx';
TCApp.Temporary_Voucher__c = 'a1Ac0000000Vb0O';
Insert TCApp;
VoucherContactReport testTreasureChest = new VoucherContactReport();
testTreasureChest.Voucherid = TemporaryVoucher.Id;
testTreasureChest.getRelatedVoucher();
testTreasureChest.getRelatedVoucher12();
testTreasureChest.getRelatedVoucher3();
testTreasureChest.getRelatedVoucher6();
testTreasureChest.getRelatedVoucherAllTime();
testTreasureChest.getRTCA();
}

}

Here I am Getting only 51% code coverage for this, can you please help any one to reach my code coverage  atleast 80%

........its an emergency.....please revert me as early as possible .....

Abhi_TripathiAbhi_Tripathi
Hey,

Take a look at this post , hope this will help you.

http://abhithetechknight.blogspot.in/2013/10/salesforce-test-class-basics.html 

Regards,
Abhi Tripathi
Salesforce Developer