• timaa
  • NEWBIE
  • 0 Points
  • Member since 2016

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 0
    Replies
Hi! I have class:
public class DisplayOpportunity{ 
    public PageReference save() {
        return null;
    }


    public List<Opportunity> Elements {get; set;}
	public String oppId {get; set;}
 

public void init() {
		Elements = [SELECT Name, CreatedDate, StageName FROM Opportunity WHERE StageName='Prospecting' or StageName='Closed Won'];   
        
}    
    public void changeStage() {
     Opportunity getElements=[SELECT StageName FROM Opportunity WHERE Id = :oppId]; 
	 
       getElements.StageName;
      if (getElements.StageName == 'Closed Won')
      {
    ApexPages.addmessage(new ApexPages.message(ApexPages.severity.WARNING,'Closed Won is set already')); 
}   
        Else {
		update getElements;
        }
 		
		init();
        
 

    } 
}

and test class:
@isTest 
public class TestOpportunity {
	public static testMethod void insertNewOpportunity() {
        
  
        //create new opportunity
 Opportunity opp = new Opportunity();
	   opp.Name = 'test Oppo';
       opp.CloseDate = System.today();
       opp.StageName = 'Prospecting';
    insert opp;         
        
        
                //inilizate controller
DisplayOpportunity myOpp = new DisplayOpportunity ();  
ApexPages.currentPage().getParameters().put('oppId',opp.Id);        
                       
      //call method for StageChange
myOpp.changeStage();       
    
    }
    
}

Can you help me to understand part when I should call method and verify it in test class?
  • May 13, 2016
  • Like
  • 0