@Test
public void viewPerson_ShouldAddAttributeForUser() {
//creating a mock user
final User user = new User();
final ModelMap model = new ModelMap();
final int modelSize = 3;
final String username="Canonical";
user.setUsername(username);
user.setEntityId(USER_ID);
String userProfile = new String(ModelKeys.USER_PROFILE);
Page personProfile = new Page();
PageLayout pageLayout = new PageLayout();
pageLayout.setCode(VALID_PAGE_LAYOUT_CODE);
personProfile.setPageLayout(pageLayout);
expect(userService.getUserByUsername(username)).andReturn(user).once();
expect(pageService.getPersonProfilePage(user.getEntityId())).andReturn(personProfile);
replay(userService, pageService);
String view = profileController.viewProfile(username, model, null);
//assert that the model is not null
assertThat(model, CoreMatchers.notNullValue());
//assert that the model size is three
assertThat(model.size(), CoreMatchers.equalTo(modelSize));
//assert that the model does contain an attribute associated with the authenticated user after setUpForm() is called
assertThat(model.containsAttribute(userProfile), CoreMatchers.equalTo(true));
//assert that the model does not contain authenticated user as null
assertThat(model.get(userProfile), CoreMatchers.notNullValue());
assertThat(view, is(ViewNames.PERSON_PROFILE + "." + VALID_PAGE_LAYOUT_CODE));
verify(userService, pageService);
}