@Test
  public void ensureSyncedPersonHasCorrectAttributes() {

    Person person =
        TestDataCreator.createPerson("muster", "Marlene", "Muster", "*****@*****.**");

    Person syncedPerson =
        ldapSyncService.syncPerson(
            person,
            Optional.of("Aljona"),
            Optional.of("Murygina"),
            Optional.of("*****@*****.**"));

    Mockito.verify(personService).save(Mockito.eq(person));

    Assert.assertNotNull("Missing login name", syncedPerson.getLoginName());
    Assert.assertNotNull("Missing first name", syncedPerson.getFirstName());
    Assert.assertNotNull("Missing last name", syncedPerson.getLastName());
    Assert.assertNotNull("Missing mail address", syncedPerson.getEmail());

    Assert.assertEquals("Wrong login name", "muster", syncedPerson.getLoginName());
    Assert.assertEquals("Wrong first name", "Aljona", syncedPerson.getFirstName());
    Assert.assertEquals("Wrong last name", "Murygina", syncedPerson.getLastName());
    Assert.assertEquals("Wrong mail address", "*****@*****.**", syncedPerson.getEmail());
  }
  @RequestMapping(value = "/overview", method = RequestMethod.GET)
  public String showOverview(
      @RequestParam(value = ControllerConstants.YEAR_ATTRIBUTE, required = false) String year) {

    Person user = sessionService.getSignedInUser();

    if (StringUtils.hasText(year)) {
      return "redirect:/web/staff/" + user.getId() + "/overview?year=" + year;
    }

    return "redirect:/web/staff/" + user.getId() + "/overview";
  }
  @Test
  public void ensureSyncDoesNotEmptyAttributes() {

    Person person =
        TestDataCreator.createPerson("muster", "Marlene", "Muster", "*****@*****.**");

    Person syncedPerson =
        ldapSyncService.syncPerson(person, Optional.empty(), Optional.empty(), Optional.empty());

    Mockito.verify(personService).save(Mockito.eq(person));

    Assert.assertEquals("Wrong login name", "muster", syncedPerson.getLoginName());
    Assert.assertEquals("Wrong first name", "Marlene", syncedPerson.getFirstName());
    Assert.assertEquals("Wrong last name", "Muster", syncedPerson.getLastName());
    Assert.assertEquals("Wrong mail address", "*****@*****.**", syncedPerson.getEmail());
  }
  @Test
  public void ensureCanAppointPersonAsOfficeUser() {

    Person person = TestDataCreator.createPerson();
    person.setPermissions(Collections.singletonList(Role.USER));

    Assert.assertEquals("Wrong initial permissions", 1, person.getPermissions().size());

    ArgumentCaptor<Person> personCaptor = ArgumentCaptor.forClass(Person.class);

    ldapSyncService.appointPersonAsOfficeUser(person);

    Mockito.verify(personService).save(personCaptor.capture());

    Collection<Role> permissions = personCaptor.getValue().getPermissions();

    Assert.assertEquals("Wrong number of permissions", 2, permissions.size());
    Assert.assertTrue("Should have user role", permissions.contains(Role.USER));
    Assert.assertTrue("Should have office role", permissions.contains(Role.OFFICE));
  }
  @RequestMapping(value = "/staff/{personId}/overview", method = RequestMethod.GET)
  public String showOverview(
      @PathVariable("personId") Integer personId,
      @RequestParam(value = ControllerConstants.YEAR_ATTRIBUTE, required = false) String year,
      Model model) {

    java.util.Optional<Person> optionalPerson = personService.getPersonByID(personId);

    if (!optionalPerson.isPresent()) {
      return ControllerConstants.ERROR_JSP;
    }

    Person person = optionalPerson.get();
    Person signedInUser = sessionService.getSignedInUser();

    boolean isOwnOverviewPage = person.getId().equals(signedInUser.getId());
    boolean isOffice = signedInUser.hasRole(Role.OFFICE);
    boolean isBoss = signedInUser.hasRole(Role.BOSS);
    boolean isDepartmentHead = departmentService.isDepartmentHeadOfPerson(signedInUser, person);

    if (!isOwnOverviewPage && !isOffice && !isBoss && !isDepartmentHead) {
      return ControllerConstants.ERROR_JSP;
    }

    model.addAttribute(PersonConstants.PERSON_ATTRIBUTE, person);

    Integer yearToShow = parseYearParameter(year);
    prepareApplications(person, yearToShow, model);
    prepareHolidayAccounts(person, yearToShow, model);
    prepareSickNoteList(person, yearToShow, model);

    model.addAttribute(ControllerConstants.YEAR_ATTRIBUTE, DateMidnight.now().getYear());

    return "person/overview";
  }