+ Start a Discussion
rajesh k 10rajesh k 10 

Hoto test below code(only covered 68% )?

Hi Vatsal,
                  I completed this please help me below code only covered 68 % below i mensioned not covered code

public with sharing class MyCls {

      public ApexPages.StandardSetController con{get; set;}

  
        public List<Myobject__c> objectList{ get{
                                                   if(con != null)
                                                        return ( List<Myobject__c)con.getRecords();
                                                    else
                                                        return null ;
                                                }
                                                set;}
   

    public MyCls() {
  
    Database.QueryLocator qLoc;
   
      qLoc = Database.getQueryLocator([SELECT contact__c,Number__C,DropboxPDFSave__c,date_time__c FROM Myobject__c ORDER BY  date_time__c DESC ]);
  
        con = new ApexPages.StandardSetController(qLoc);
 
    }
     

public Boolean hasNext
    {
        get
        {
            return con.getHasNext();
        }
        set;
    }

    public Boolean hasPrevious
    {
        get
        {
            return con.getHasPrevious();
        }
        set;
    }

    public Integer pageNumber
    {
        get
        {
            return con.getPageNumber();
        }
        set;
    }

    public void previous()
    {
        con.previous();
    }

    public void next()
    {
        con.next();
    }
}

please help me.........

Not covered code:

public ApexPages.StandardSetController con{get; set;}

 
        public List<Myobject__c> objectList{ get{
                                                   if(con != null)
                                                        return ( List<My_object__c>)con.getRecords();
                                                    else
                                                        return null ;
                                                }
                                                set;}


return con.getHasNext();
return con.getHasPrevious();
return con.getPageNumber();

please help me.........
Best Answer chosen by rajesh k 10
Vatsal KothariVatsal Kothari
Hi,

Refer below code:
@isTest
public class MyClsTest {
	
    public static testmethod void myClsMethodTest(){
        
		Account acc = new Account();
		acc.Name = 'test account';
		insert acc;
		
		Contact con = new Contact();
		con.Username__c = 'testuser';
		con.Password__c = 'testpwd';
		con.AccountId = acc.Id;
		con.Lastname = 'test';
		insert con;
		
		MyObject__c obj = new MyObject__c();
		obj.Name = 'test Name';
		obj.Number__c = 132;
		obj.Contact__c = con.Id;
		obj.DropboxPDFSave__c = ''+obj.Id;
		insert obj;
        
        MyCls my = new MyCls();
        Boolean b = my.hasNext;
        Boolean b1 = my.hasPrevious;
        List<MyObject__c> objList = my.objectList;
        my.previous();
        my.next();
    }
}
If this solves your problem, kindly mark it as the best answer.

Thanks,
Vatsal