0

I am writing a test class.But i am getting error saying "expecting a right parentheses, found ':' " at line 23.

Apex class :

@isTest
public class Pagination_Test {
    static testMethod void testUnitTestOne(){
        Test.startTest();
        Account acc = new Account();
        acc.Name='wbstest21';
        insert acc;
        List<Opportunity> opps = new List<Opportunity>();
        System.debug('value of account id ::::: '+acc.id);
        Opportunity o1 = new Opportunity(AccountId=acc.id, Name='ABC', stageName='Prospecting', CloseDate=Date.today());
        Opportunity o2 = new Opportunity(AccountId=acc.id, Name='XYZ', stageName='Prospecting', CloseDate=Date.today());
        opps.add(o1);
        opps.add(o2);
        insert opps;

        Pagination page = new Pagination();
        page.getOpplist();

        System.debug('Value of getopp :::: '+page.getOpplist());
        List<Pagination.wrapOpportunity> Actual = page.getOpplist();

        System.debug('value of Actual :::: '+Actual);
        List<Pagination.wrapOpportunity> Expected = (wrapOpportunity:[Oppo=Opportunity:{Name=ABC, Id=00628000005HT5hAAG, StageName=Prospecting, AccountId=001280000090BhQAAU, CloseDate=2015-11-01 00:00:00, OwnerId=00528000001AxRXAA0}, isSelected=false], wrapOpportunity:[Oppo=Opportunity:{Name=XYZ, Id=00628000005HT5iAAG, StageName=Prospecting, AccountId=001280000090BhQAAU, CloseDate=2015-11-01 00:00:00, OwnerId=00528000001AxRXAA0}, isSelected=false]);
        //System.assertEquals(abc, Expected);
        Test.stopTest();
    }

}

Pagination Class :

public class Pagination
{
    public list<wrapOpportunity> wrapOpportunityList { get; set; }
    public list<Opportunity> selectedOpportunities{get;set;} 



    public Pagination(ApexPages.StandardController controller) {

    }

    private integer totalRecs = 0;
    private integer OffsetSize = 0;
    private integer LimitSize= 5;

    ID accid=ApexPages.currentPage().getParameters().get('Id');

    public Pagination()
    {
        totalRecs = [select count() from Opportunity where stageName NOT IN ('Closed Won','Closed Lost') ];
        //totalRecs = [select count() from Opportunity where Accountid=:accid and stageName NOT IN ('Closed Won','Closed Lost')];
    }

    public List<wrapOpportunity> getOpplist() 
    {
        wrapOpportunityList =new list<wrapOpportunity>();

        List<Opportunity> OppLists= Database.Query('SELECT Name, id,stageName,accountid,account.name,CloseDate,Amount,ownerid FROM Opportunity where stageName NOT IN (\'Closed Won\',\'Closed Lost\') ORDER BY Name ASC LIMIT :LimitSize OFFSET :OffsetSize ');         
        //List<Opportunity> OppLists= Database.Query('SELECT Name, id,stageName,accountid,account.name,CloseDate,Amount FROM Opportunity where Accountid=:accid and stageName NOT IN (\'Closed Won\',\'Closed Lost\') LIMIT :LimitSize OFFSET :OffsetSize');
        //List<Opportunity> OppLists= Database.Query('SELECT Name, id,stageName,accountid,account.name,CloseDate,Amount,ownerid,(Select Id, PriceBookEntry.Product2Id, PriceBookEntry.Product2.Name from OpportunityLineItems) FROM Opportunity where stageName NOT IN (\'Closed Won\',\'Closed Lost\') AND Id IN (SELECT OpportunityId from OpportunityLineItem WHERE OpportunityId != '') ORDER BY Name ASC');
        System.debug('Values are ' + OppLists);

        for(Opportunity a:OppLists){
            wrapOpportunitylist.add(new wrapOpportunity(a));  
        }
        return wrapOpportunityList;
    }


    public class wrapOpportunity{

        public Opportunity Oppo{get;set;}
        public boolean isSelected{get;set;}

        public wrapOpportunity(Opportunity a){

            Oppo=a;
            isselected=false;
        }
    }

    public void firstPage()
    {
        OffsetSize=0;
    }
    public void previous()
    {
        OffsetSize = OffsetSize-LimitSize;
    }public void next()
    {
        OffsetSize = OffsetSize+LimitSize;
    }public void lastPage()
    {
        OffsetSize = totalrecs-math.mod(totalRecs,LimitSize);
    }
    public boolean getprev()
    {
        if(OffsetSize ==0)
            return true;
        else
            return false;
    }
    public boolean getnxt()
    {
        if((OffsetSize+LimitSize)>totalRecs)
            return true;
        else
            return false;
    }

    public void ProcessSelected(){
        selectedOpportunities=new list<Opportunity>();

        for(wrapOpportunity wrapobj:wrapOpportunitylist){
            if(wrapobj.isSelected==true){
                selectedOpportunities.add(wrapobj.Oppo);
            }          
        }
    }

    public PageReference SendEmail() {
        ProcessSelected();
        list<id> ownerids=new list<id>();
        for(Opportunity ops: selectedOpportunities){
            ownerids.add(ops.ownerid);
        }
        Messaging.MassEmailMessage mail = new Messaging.MassEmailMessage();
        mail.setTargetObjectIds(ownerids);
        mail.setTemplateId('00X28000000INpREAW');
        mail.setSaveasactivity(False);
        Messaging.sendEmail(new Messaging.MassEmailMessage[] { mail }); 
        ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.INFO, 'Please enter some text to search for Account'));
        return null;
    }


    public PageReference CancelRecords() {
        PageReference pageref=new PageReference('/'+accid); 
        //pageref=ApexPages.currentPage().getURL();
        // pageref.setRedirect(False);
        return pageref;
    }


    public PageReference DeleteRecords() {
        ProcessSelected();
        List<Opportunity> oo1=new List<Opportunity>();
        For(Opportunity oo2:selectedOpportunities){
            Opportunity oo3 = new Opportunity();
            oo3.id=oo2.id;
            //oo3.accountid=accid;
            oo1.add(oo3);
        }
        delete oo1;
        return null;
    }


    public PageReference saveRecords() {
        ProcessSelected();
        List<Opportunity> oo1=new List<Opportunity>();
        For(Opportunity oo2:selectedOpportunities){
            Opportunity oo3 = new Opportunity();
            oo3.id=oo2.id;
            oo3.accountid=accid;
            oo1.add(oo3);
        }
        update oo1;
        return null;
    }


}
3
  • Pagination.wrapOpportunity is inner class?Can you share how wrapOpportunity look like?
    – unidha
    Nov 2, 2015 at 7:59
  • Yes Its a inner class.I have added my pagination class.
    – Jack vardy
    Nov 2, 2015 at 8:05
  • Basically I need to add an assertequals statement for test class.I am getting error in the same.
    – Jack vardy
    Nov 2, 2015 at 8:20

1 Answer 1

2

This is my assumption, based on the code below you want to define the List of inner class.

 List<Pagination.wrapOpportunity> Expected = (wrapOpportunity:[Oppo=Opportunity:{Name=ABC, Id=00628000005HT5hAAG, StageName=Prospecting, AccountId=001280000090BhQAAU, CloseDate=2015-11-01 00:00:00, OwnerId=00528000001AxRXAA0}, isSelected=false], wrapOpportunity:[Oppo=Opportunity:{Name=XYZ, Id=00628000005HT5iAAG, StageName=Prospecting, AccountId=001280000090BhQAAU, CloseDate=2015-11-01 00:00:00, OwnerId=00528000001AxRXAA0}, isSelected=false]);

It should be written to something like this.

List<Pagination.wrapOpportunity> Expected = new List<Pagination.wrapOpportunity>{new Pagination.wrapOpportunity(o1),new Pagination.wrapOpportunity(o2)};

Or you can instantiate many Pagination.wrapOpportunity objects, then add to the List

Something like this also can be done

//Define opportunity object

    Opportunity o1 = new Opportunity(AccountId=acc.id, Name='ABC', stageName='Prospecting', CloseDate=Date.today());
            Opportunity o2 = new Opportunity(AccountId=acc.id, Name='XYZ', stageName='Prospecting', CloseDate=Date.today());

//Create Pagination.wrapOpportunity 

Pagination.wrapOpportunity w1 = new Pagination.wrapOpportunity(o1);
Pagination.wrapOpportunity w1= new  Pagination.wrapOpportunity(o2);

List<Pagination.wrapOpportunity> lst =new List<Pagination.wrapOpportunity>();

lst.add(w1);
lst.add(w2);

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .