@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());
  }
  @Test
  public void ensurePersonCanBeCreatedWithOnlyLoginName() {

    Person person = TestDataCreator.createPerson();

    Mockito.when(
            personService.create(
                Mockito.anyString(),
                Mockito.anyString(),
                Mockito.anyString(),
                Mockito.anyString(),
                Mockito.anyListOf(MailNotification.class),
                Mockito.anyListOf(Role.class)))
        .thenReturn(person);

    ldapSyncService.createPerson("murygina", Optional.empty(), Optional.empty(), Optional.empty());

    Mockito.verify(personService)
        .create(
            "murygina",
            null,
            null,
            null,
            Collections.singletonList(MailNotification.NOTIFICATION_USER),
            Collections.singletonList(Role.USER));
  }
  @Test
  public void ensurePersonIsCreatedWithCorrectAttributes() {

    Person person = TestDataCreator.createPerson();

    Mockito.when(
            personService.create(
                Mockito.anyString(),
                Mockito.anyString(),
                Mockito.anyString(),
                Mockito.anyString(),
                Mockito.anyListOf(MailNotification.class),
                Mockito.anyListOf(Role.class)))
        .thenReturn(person);

    ldapSyncService.createPerson(
        "murygina",
        Optional.of("Aljona"),
        Optional.of("Murygina"),
        Optional.of("*****@*****.**"));

    Mockito.verify(personService)
        .create(
            "murygina",
            "Murygina",
            "Aljona",
            "*****@*****.**",
            Collections.singletonList(MailNotification.NOTIFICATION_USER),
            Collections.singletonList(Role.USER));
  }
  @Before
  public void setUp() throws Exception {

    calendarService = Mockito.mock(WorkDaysService.class);
    sickNoteDAO = Mockito.mock(SickNoteDAO.class);
    sickNotes = new ArrayList<>();

    Person person = TestDataCreator.createPerson();

    SickNote sickNote1 =
        TestDataCreator.createSickNote(
            person,
            new DateMidnight(2013, DateTimeConstants.OCTOBER, 7),
            new DateMidnight(2013, DateTimeConstants.OCTOBER, 11),
            DayLength.FULL);

    SickNote sickNote2 =
        TestDataCreator.createSickNote(
            person,
            new DateMidnight(2013, DateTimeConstants.DECEMBER, 18),
            new DateMidnight(2014, DateTimeConstants.JANUARY, 3),
            DayLength.FULL);

    sickNotes.add(sickNote1);
    sickNotes.add(sickNote2);

    Mockito.when(sickNoteDAO.findNumberOfPersonsWithMinimumOneSickNote(2013)).thenReturn(7L);
    Mockito.when(sickNoteDAO.findAllActiveByYear(2013)).thenReturn(sickNotes);

    Mockito.when(
            calendarService.getWorkDays(
                DayLength.FULL,
                new DateMidnight(2013, DateTimeConstants.OCTOBER, 7),
                new DateMidnight(2013, DateTimeConstants.OCTOBER, 11),
                person))
        .thenReturn(new BigDecimal("5"));

    Mockito.when(
            calendarService.getWorkDays(
                DayLength.FULL,
                new DateMidnight(2013, DateTimeConstants.DECEMBER, 18),
                new DateMidnight(2013, DateTimeConstants.DECEMBER, 31),
                person))
        .thenReturn(new BigDecimal("9"));

    statistics = new SickNoteStatistics(2013, sickNoteDAO, calendarService);
  }
  @Before
  public void setUp() {

    person = TestDataCreator.createPerson();

    CalendarSettings calendarSettings = new CalendarSettings();
    calendarSettings.setWorkDayBeginHour(8);
    calendarSettings.setWorkDayEndHour(16);

    timeConfiguration = new AbsenceTimeConfiguration(calendarSettings);
  }
  @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));
  }