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
VidhiVidhi 

Test class Error

Hello Friends i have wriiten a wrapper class.It is working correctly but when i am writting the test class for it i am getting error 

Error: Compile Error: Invalid type: CategoryWrapper at line 15 column 36

Class 

public class Cls_OppRelatedList {
List<categoryWrapper> categories {get;set;}
public id  aid{get;set;}
public string surl = '';
public list<opportunity> opportunityList{get;set;}

 public Cls_OppRelatedList(ApexPages.StandardController controller) {
opportunityList=new list<opportunity>();
categories=new List<categoryWrapper>();
if(ApexPages.currentPage().getUrl() != null)
     {
     
     aid= ApexPages.currentPage().getParameters().get('id');
     }
     if(aid!=null){
    opportunityList=[select name,accountid,stagename,closedate,Amount from opportunity where Accountid=:aid ] ;
     system.debug('%%%%%%%%%%%%%%%%'+opportunityList);
         }
    }
public List<categoryWrapper> getCategories() {
    
     integer i = 0;
     for(opportunity a: opportunityList)
            {
           CategoryWrapper lw = new CategoryWrapper(a);
            categories.add(lw);
            i++;
            } 
             return categories;  
                           
                           
               }


public class CategoryWrapper {
   public string oppname { get; set;}
   public date closedate { get; set;}
   public string stagename { get; set;}
   public id opportunityid{get;set;}
   public CategoryWrapper(opportunity c){
       opportunityid=c.id;
        oppname =c.name;
         stagename=c.stagename;
         closedate=c.closedate;
       
    } 
}

}              

+++++++++++++++++++

Test Class :

@isTest(SeeAllData=True)
Public class Test_Cls_OppRelatedList
{
   Public static testMethod void OppRelatedList()
   {
       List<Opportunity> Opp = New List<opportunity>();
       Account a=new Account();
       a.Name='Test';
       insert a;
       Opp = [select name,accountid,stagename,closedate,Amount from opportunity limit 2];
       ApexPages.StandardController controller=new ApexPages.StandardController(a);  
       Cls_OppRelatedList obj = new Cls_OppRelatedList(controller);
       obj.getCategories();
       
       CategoryWrapper obj1 = New CategoryWrapper(new Opportunity(Name ='Test Oppty', CloseDate = System.today(), StageName = 'Closed Lost', AccountId = a.Id));
     
   }
}

 

 Pls let me know where i am wrong and how can we correct this?

 

robdobbyrobdobby

When referencing an inner class from another file, you need to use the top level class like this: 

 

Cls_OppRelatedList.CategoryWrapper

 

So your test class uses this syntax:

 

Cls_OppRelatedList.CategoryWrapper obj1 = New Cls_OppRelatedList.CategoryWrapper(new Opportunity(Name ='Test Oppty', CloseDate = System.today(), StageName = 'Closed Lost', AccountId = a.Id));