2011-09-08 31 views
0

我試圖寫一個測試類的控制器擴展。這個控制器擴展中有另一個類。這個類有幾個方法。如何調用一類是在控制器擴展類中的方法?

public class Extension_Account 
{ 
    public Extension_Account(ApexPages.StandardController controller) 
    { 
     public class Class1 
     { 
     public Class1() 
     { 
     /* code here*/ 
     } 
     public String getMethod() 
     { 
     /* code here */ 
      } 
     } 
    } 
} 

如何訪問我的測試類中的getMethod方法?

在我的測試類,我能夠訪問構造器用於Class1的,但不知道怎麼去其他方法

public with sharing class TestExtension_Account 

{ 
    static testMethod void TestPrint() 
    { 
     Account a = new Account(); 
     //a.Name='Test Account'; 
     a.FirstName='TestFirst Name'; 
     a.LastName='Test Last Name'; 
     a.BillingStreet='Test billing Street'; 
     a.BillingCity='Test Billing City'; 
     a.BillingState='Test Billing State'; 
     a.BillingCountry='Test Billing country'; 
     a.BillingPostalCode='Test PostCode'; 
     insert a; 



     PageReference pageRef = Page.printaddressaccount; 
     pageRef .getParameters().put('id',a.id); 
     Test.setCurrentPageReference(pageRef); 
     ApexPages.StandardController controller = new ApexPages.StandardController(a); 
     Extension_Account ae = new Extension_Account(controller); 
     ae.getClass1(); 
     ae.getMethod()// gives a compiler error Method does not exist or incorrect signature 
} 
} 

回答

0

如果您的擴展類有一個返回的Class1實例的getClass1()方法,那麼你可以訪問該實例的方法,例如ae.getClass1().getMethod();

+0

謝謝superfell,我的工作就像魅力 – Prady