You need to sign in to do that
Don't have an account?
Nishant Shrivastava 30
I am not able to get code coverage for my sql query, i shall be grateful to you for any help
Public class Invoice_details {
Public List<VoiceWrapper> InvoiceList {get;set;}
Public kognoz1__Invoice2__c InvoiceInfo { get;set;}
Public static Date StartDate {get;set;}
Public static Date EndDate {get;set;}
Public static string querystr;
Public integer counter = 0;
Public integer list_size=100;
Static set<Id> ids = New set<Id>();
Public Invoice_details() {
InvoiceInfo = new kognoz1__Invoice2__c();
InvoiceList = New List<VoiceWrapper>();
for(kognoz1__Invoice2__c k : [SELECT id, kognoz1__Invoice_Date__c, kognoz1__Account__c, Downloaded__c, kognoz1__Opportunity__r.rechnung_per_email__c , kognoz1__Opportunity__c, (select id, name from Attachments) FROM kognoz1__Invoice2__c ORDER BY kognoz1__Invoice_Date__c DESC limit: List_size ])
{
InvoiceList.add(new VoiceWrapper(K));
}
}
Public void display() {
InvoiceList.clear();
Date startDate = InvoiceInfo.kognoz1__Invoice_Date__c;
Date endDate = InvoiceInfo.kognoz1__Invoice_Due_Date__c;
if(InvoiceInfo.kognoz1__Invoice_Date__c != null ) {
//string Query = 'SELECT kognoz1__Invoice_Date__c, kognoz1__Account__c, kognoz1__Opportunity__c,(select id, name from Attachments) FROM kognoz1__Invoice2__c WHERE kognoz1__Invoice_Date__c = '+startDate+' AND kognoz1__Invoice_Date__c= '+EndDate+' ';
InvoiceList = New List<VoiceWrapper>();
for(kognoz1__Invoice2__c k : [SELECT Id, kognoz1__Invoice_Date__c, kognoz1__Account__c, Downloaded__c, kognoz1__Opportunity__r.rechnung_per_email__c, kognoz1__Opportunity__c, (select id, name from Attachments) FROM kognoz1__Invoice2__c WHERE kognoz1__Invoice_Date__c >=: startDate AND kognoz1__Invoice_Date__c <=: EndDate ORDER BY kognoz1__Invoice_Date__c DESC limit: list_size offset: counter ])
{
InvoiceList.add(new VoiceWrapper(K));
}
}
}
Public class VoiceWrapper {
Public kognoz1__Invoice2__c KI {get;set;}
Public boolean selected {get;set;}
Public VoiceWrapper (kognoz1__Invoice2__c K) {
KI = k;
selected = false;
system.debug(KI);
}
}
Public Pagereference Previous() {
counter = counter-list_size;
display();
return null;
}
Public pagereference Next() {
counter = counter + list_size;
display();
system.debug( InvoiceList);
return null;
}
Public boolean getDisablePrevious() {
if (counter<=0) {
return True;
}
else return false;
}
Public Boolean getDisableNext() {
if (counter > = InvoiceList.size()-list_size) {
return true;
}
else return false;
}
}
My test class---------------------
@isTest(seeAllData=true)
public class Invoice_detailsTestClass {
public List<VoiceWrapper> InvoiceList {get;set;}
public kognoz1__Invoice2__c InvoiceInfo { get;set;}
public static Date StartDate {get;set;}
public static Date EndDate {get;set;}
public boolean selected{get;set;}
public static integer counter = 0;
Public static integer list_size=20;
Public integer total_size ;
static testMethod void Invoice_details() {
list<kognoz1__Invoice2__c> InvoiceList = [SELECT id, kognoz1__Invoice_Date__c, kognoz1__Account__c, kognoz1__Opportunity__r.rechnung_per_email__c, kognoz1__Opportunity__c, (select id, name from Attachments) FROM kognoz1__Invoice2__c];
Account testAcco = TestData.createAccounts(1, 'Publisher', 'Horst')[0];
insert testAcco;
Opportunity opp = TestData.createOpportunity();
opp.AccountId = testAcco.Id;
opp.StageName = 'New';
insert opp;
Test.StartTest();
ApexPages.currentPage().getParameters().put('id', String.valueOf(TestAcco.Id));
Invoice_details testAccPlan = new Invoice_details();
testAccplan.display();
testAccplan.Previous();
testAccplan.Next();
testAccplan.getDisablePrevious();
testAccplan.getDisableNext();
kognoz1__Invoice2__c K = new kognoz1__Invoice2__c();
Invoice_details.VoiceWrapper TV = new Invoice_details.VoiceWrapper( k);
Test.StopTest();
}
static testMethod void testdisplay() {
DAte StartDate = Date.newInstance(2016, 12, 9);
Date endDate = Date.newInstance(2016, 12, 9);
//list<kognoz1__Invoice2__c> InvoiceList = [SELECT id, kognoz1__Invoice_Date__c, kognoz1__Account__c, kognoz1__Opportunity__r.rechnung_per_email__c, kognoz1__Opportunity__c, (select id, name from Attachments) FROM kognoz1__Invoice2__c WHERE kognoz1__Invoice_Date__c >=: startDate AND kognoz1__Invoice_Date__c <=: EndDate ORDER BY kognoz1__Invoice_Date__c DESC limit: list_size offset: counter];
Account testAcco = TestData.createAccounts(1, 'Publisher', 'Horst')[0];
insert testAcco;
Opportunity opp = TestData.createOpportunity();
opp.AccountId = testAcco.Id;
opp.StageName = 'New';
opp.rechnung_per_email__c = 'abv@gmail.com';
insert opp;
kognoz1__Invoice2__c KI = [SELECT id, kognoz1__Invoice_Date__c, kognoz1__Account__c, kognoz1__Opportunity__r.rechnung_per_email__c, kognoz1__Opportunity__c, (select id, name from Attachments) FROM kognoz1__Invoice2__c WHERE kognoz1__Invoice_Date__c >=: startDate AND kognoz1__Invoice_Date__c <=: EndDate ORDER BY kognoz1__Invoice_Date__c DESC limit: list_size offset: counter];
KI.kognoz1__Opportunity__c = opp.Id;
KI.kognoz1__Account__c = testAcco.Id;
KI.kognoz1__Opportunity__r.rechnung_per_email__c = 'post';
KI.kognoz1__Invoice_Date__c = StartDate;
KI.kognoz1__Invoice_Due_Date__c = EndDate;
insert KI;
system.debug(KI);
KI.kognoz1__Invoice_Date__c = StartDate+15;
update KI;
Test.StartTest();
user u = [select id from user where username = 'finance@softgarden.de' limit 1];
System.runAs(u) {
Invoice_details Id = New Invoice_details();
id.display();
Invoice_details.VoiceWrapper IV = new Invoice_details.VoiceWrapper(KI);
}
Test.StopTest();
}
I shall be grateful to you for your kind consideration and input
Public List<VoiceWrapper> InvoiceList {get;set;}
Public kognoz1__Invoice2__c InvoiceInfo { get;set;}
Public static Date StartDate {get;set;}
Public static Date EndDate {get;set;}
Public static string querystr;
Public integer counter = 0;
Public integer list_size=100;
Static set<Id> ids = New set<Id>();
Public Invoice_details() {
InvoiceInfo = new kognoz1__Invoice2__c();
InvoiceList = New List<VoiceWrapper>();
for(kognoz1__Invoice2__c k : [SELECT id, kognoz1__Invoice_Date__c, kognoz1__Account__c, Downloaded__c, kognoz1__Opportunity__r.rechnung_per_email__c , kognoz1__Opportunity__c, (select id, name from Attachments) FROM kognoz1__Invoice2__c ORDER BY kognoz1__Invoice_Date__c DESC limit: List_size ])
{
InvoiceList.add(new VoiceWrapper(K));
}
}
Public void display() {
InvoiceList.clear();
Date startDate = InvoiceInfo.kognoz1__Invoice_Date__c;
Date endDate = InvoiceInfo.kognoz1__Invoice_Due_Date__c;
if(InvoiceInfo.kognoz1__Invoice_Date__c != null ) {
//string Query = 'SELECT kognoz1__Invoice_Date__c, kognoz1__Account__c, kognoz1__Opportunity__c,(select id, name from Attachments) FROM kognoz1__Invoice2__c WHERE kognoz1__Invoice_Date__c = '+startDate+' AND kognoz1__Invoice_Date__c= '+EndDate+' ';
InvoiceList = New List<VoiceWrapper>();
for(kognoz1__Invoice2__c k : [SELECT Id, kognoz1__Invoice_Date__c, kognoz1__Account__c, Downloaded__c, kognoz1__Opportunity__r.rechnung_per_email__c, kognoz1__Opportunity__c, (select id, name from Attachments) FROM kognoz1__Invoice2__c WHERE kognoz1__Invoice_Date__c >=: startDate AND kognoz1__Invoice_Date__c <=: EndDate ORDER BY kognoz1__Invoice_Date__c DESC limit: list_size offset: counter ])
{
InvoiceList.add(new VoiceWrapper(K));
}
}
}
Public class VoiceWrapper {
Public kognoz1__Invoice2__c KI {get;set;}
Public boolean selected {get;set;}
Public VoiceWrapper (kognoz1__Invoice2__c K) {
KI = k;
selected = false;
system.debug(KI);
}
}
Public Pagereference Previous() {
counter = counter-list_size;
display();
return null;
}
Public pagereference Next() {
counter = counter + list_size;
display();
system.debug( InvoiceList);
return null;
}
Public boolean getDisablePrevious() {
if (counter<=0) {
return True;
}
else return false;
}
Public Boolean getDisableNext() {
if (counter > = InvoiceList.size()-list_size) {
return true;
}
else return false;
}
}
My test class---------------------
@isTest(seeAllData=true)
public class Invoice_detailsTestClass {
public List<VoiceWrapper> InvoiceList {get;set;}
public kognoz1__Invoice2__c InvoiceInfo { get;set;}
public static Date StartDate {get;set;}
public static Date EndDate {get;set;}
public boolean selected{get;set;}
public static integer counter = 0;
Public static integer list_size=20;
Public integer total_size ;
static testMethod void Invoice_details() {
list<kognoz1__Invoice2__c> InvoiceList = [SELECT id, kognoz1__Invoice_Date__c, kognoz1__Account__c, kognoz1__Opportunity__r.rechnung_per_email__c, kognoz1__Opportunity__c, (select id, name from Attachments) FROM kognoz1__Invoice2__c];
Account testAcco = TestData.createAccounts(1, 'Publisher', 'Horst')[0];
insert testAcco;
Opportunity opp = TestData.createOpportunity();
opp.AccountId = testAcco.Id;
opp.StageName = 'New';
insert opp;
Test.StartTest();
ApexPages.currentPage().getParameters().put('id', String.valueOf(TestAcco.Id));
Invoice_details testAccPlan = new Invoice_details();
testAccplan.display();
testAccplan.Previous();
testAccplan.Next();
testAccplan.getDisablePrevious();
testAccplan.getDisableNext();
kognoz1__Invoice2__c K = new kognoz1__Invoice2__c();
Invoice_details.VoiceWrapper TV = new Invoice_details.VoiceWrapper( k);
Test.StopTest();
}
static testMethod void testdisplay() {
DAte StartDate = Date.newInstance(2016, 12, 9);
Date endDate = Date.newInstance(2016, 12, 9);
//list<kognoz1__Invoice2__c> InvoiceList = [SELECT id, kognoz1__Invoice_Date__c, kognoz1__Account__c, kognoz1__Opportunity__r.rechnung_per_email__c, kognoz1__Opportunity__c, (select id, name from Attachments) FROM kognoz1__Invoice2__c WHERE kognoz1__Invoice_Date__c >=: startDate AND kognoz1__Invoice_Date__c <=: EndDate ORDER BY kognoz1__Invoice_Date__c DESC limit: list_size offset: counter];
Account testAcco = TestData.createAccounts(1, 'Publisher', 'Horst')[0];
insert testAcco;
Opportunity opp = TestData.createOpportunity();
opp.AccountId = testAcco.Id;
opp.StageName = 'New';
opp.rechnung_per_email__c = 'abv@gmail.com';
insert opp;
kognoz1__Invoice2__c KI = [SELECT id, kognoz1__Invoice_Date__c, kognoz1__Account__c, kognoz1__Opportunity__r.rechnung_per_email__c, kognoz1__Opportunity__c, (select id, name from Attachments) FROM kognoz1__Invoice2__c WHERE kognoz1__Invoice_Date__c >=: startDate AND kognoz1__Invoice_Date__c <=: EndDate ORDER BY kognoz1__Invoice_Date__c DESC limit: list_size offset: counter];
KI.kognoz1__Opportunity__c = opp.Id;
KI.kognoz1__Account__c = testAcco.Id;
KI.kognoz1__Opportunity__r.rechnung_per_email__c = 'post';
KI.kognoz1__Invoice_Date__c = StartDate;
KI.kognoz1__Invoice_Due_Date__c = EndDate;
insert KI;
system.debug(KI);
KI.kognoz1__Invoice_Date__c = StartDate+15;
update KI;
Test.StartTest();
user u = [select id from user where username = 'finance@softgarden.de' limit 1];
System.runAs(u) {
Invoice_details Id = New Invoice_details();
id.display();
Invoice_details.VoiceWrapper IV = new Invoice_details.VoiceWrapper(KI);
}
Test.StopTest();
}
I shall be grateful to you for your kind consideration and input