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
Shruthi GM 4Shruthi GM 4 

test class for the following class:-

Please help me in writing the test class for the below class:-
public class loadingSpinnerCtrl {
    public List<String> dropdown1{get; set;}
    public List<SelectOption> options;
    public void spin() {
        options = new List<SelectOption>();
        for(String s: dropdown1){
            if(s == '1'){
                options.add(new SelectOption('1','Value 1'));
                options.add(new SelectOption('2','Value 2'));
            }else if(s == '2'){
                options.add(new SelectOption('3','Value 3'));
                options.add(new SelectOption('4','Value 4'));
            }else if(s == '3'){
                options.add(new SelectOption('5','Value 5'));
                options.add(new SelectOption('6','Value 6'));
            }else if(s == '4'){
                options.add(new SelectOption('7','Value 7'));
                options.add(new SelectOption('8','Value 8'));
            }else if(s == '5'){
                options.add(new SelectOption('7','Value 9'));
                options.add(new SelectOption('8','Value 10'));
            }            
        }    
        long now = datetime.now().gettime();
        while(datetime.now().gettime()-now<2000); // Busy loop for 2000 ms to simulate delay
    }
    public List<SelectOption> getItems() {
        return options;
    }    
}
Best Answer chosen by Shruthi GM 4
Ravi Dutt SharmaRavi Dutt Sharma
Hi Shruthi,

Let me know if below code helps you:
 
@isTest
private class LoadingSpinnerCtrlTest {

   static testMethod void testSpin(){
   
	   loadingSpinnerCtrl obj = new loadingSpinnerCtrl();
	   obj.dropdown1 = new List<String>();
	   obj.dropdown1.add('1');
	   obj.dropdown1.add('2');
	   obj.dropdown1.add('3');
	   obj.dropdown1.add('4');
	   obj.dropdown1.add('5');
	   obj.spin();
   }
   
   static testMethod void testSpin(){
   
	   loadingSpinnerCtrl obj = new loadingSpinnerCtrl();
	   obj.getItems(); // Add assert statment over here
   }
	
}