+ Start a Discussion
Veena GopalVeena Gopal 

null object created but not null checked.

In the visualforce workbook the following example is given for constructor testing:
To test the constructor use the below code:-
// test the class constructor
static testMethod void testClassConstructor() {
WarehouseUtils utils = new WarehouseUtils(null);
// We expect that utils is not null
System.assert(utils != null);
Why system assert has been checked for != null when null was actualy passed for the object?
Please let me know if you need more clarification on the question.
Here we are calling the extension class with  the object utils but instead of passing the object of apexpages.standardsetcontroller we are passing a null value , so object will have a value of  WarehouseUtils:[] .So you need to check with !=null otherwise the test class will be failed . Please mark this as solved if this answer your query.
Veena GopalVeena Gopal
What i understand is:
the statement we need to check is 
public WarehouseUtils(ApexPages.StandardSetController controller) {
they have mentioned
// We expect that utils is not null

you have mentioned
"so object will have a value of  WarehouseUtils:[]".

But what is the value WarehouseUtils:[]. what does this mean?
Veena GopalVeena Gopal
what i finally understood was. when you are testing a constructor which is especially empty, you can just pass anything to invoke it. it can be null or a valid object as well. but finally when you are checking system assert you will have to check for !null only because that is what is the expectation of a correctly called constructor.
Veena GopalVeena Gopal
but why constructor expects a non null value is still a question.