So I have the following controller:
List<User> users {get; set;}
public reshapeUserDivisions()
{
users = new List<User>();
users = [SELECT Id, Division, FROM User WHERE isActive=true];
}
public void changedivisions()
{
boolean isChanged = true;
for(User c: users)
{
if(c.Division.equals('LA'))
{
c.Division = 'Los Angeles';
update c;
isChanged = true;
}
else if(c.Division.equals('NYC'))
{
c.Division = 'New York';
update c;
isChanged = true;
}
else
{
isChanged = false;
}
}
}
public static testMethod void reshapedivisiontest()
{
Pagereference pageref = new Pagereference('/apex/objecteditor');
Test.setCurrentPage(pageref);
reshapeUserDivisions control = new reshapeUserDivisions();
Profile p = [select id from profile where name='Saatchi - Standard User'];
User testUser = new User(alias = 'u1', email='[email protected]',
emailencodingkey='UTF-8', lastname='Testing', languagelocalekey='en_US',
localesidkey='en_US', profileid = p.Id, country='United States',
timezonesidkey='America/Los_Angeles', username='[email protected]', division = 'NYC');
insert testUser;
control.changedivisions();
List<User> users = [SELECT name, division FROM User WHERE alias = 'u1'];
System.assertEquals(users[0].Division, 'New York');
}
Called by the following VisualForce page:
<apex:page controller="reshapeUserDivisions">
<apex:form >
<apex:pageBlock title="Object Editor" id="objeditor" mode="edit">
<apex:commandButton action="{!changedivisions}" value="Standardize User Divisions" />
<apex:actionFunction name="reshapeusers" action="{!changedivisions}" rerender="results,debug,errors">
</apex:actionFunction>
</apex:pageBlock>
</apex:form>
</apex:page>
And keep getting a Null Pointer Exception at the unit test [specificially, at control.changedivisions()], no idea why. Any insights?