I am really trying to cover this small class for its code coverage but struggling to do that somehow. Can somebody please help me ?
public with sharing class MultiSelectComponentController {
public SelectOption[] leftOptions { get; set; }
public SelectOption[] rightOptions { get; set; }
public void setOptions(SelectOption[] options, String value) {
options.clear();
String[] parts = value.split('&');
for (Integer i=0; i<parts.size()/2; i++) {
options.add(new SelectOption(EncodingUtil.urlDecode(parts[i*2], 'UTF-8'),
EncodingUtil.urlDecode(parts[(i*2)+1], 'UTF-8')));
}
}
public String leftOptionsHidden { get; set {
leftOptionsHidden = value;
setOptions(leftOptions, value);
}
}
public String rightOptionsHidden { get; set {
rightOptionsHidden = value;
setOptions(rightOptions, value);
}
}
}
The test class which I tried is :
@isTest
public class MultiSelectComponentControllerTest {
static testMethod void testMultiSelectComponent(){
Test.startTest();
SelectOption[] options = new SelectOption[2];
options.add(new SelectOption('test', 'test'));
options.add(new SelectOption('value', 'value'));
MultiSelectComponentController controller = new MultiSelectComponentController();
controller.rightOptionsHidden = 'Test';
controller.leftOptionsHidden = 'New Test';
controller.setOptions(options, 'Game&NewGame');
System.assert(controller != null);
Test.stopTest();
}
}
But its failing and giving me the error...
System.NullPointerException: Attempt to de-reference a null object Class.MultiSelectComponentController.setOptions: line 22, column 1 Class.MultiSelectComponentController.__sfdc_rightOptionsHidden: line 42, column 1 Class.MultiSelectComponentControllerTest.testMultiSelectComponent: line 11, column 1