Skip to content

Commit

Permalink
[Gepardec/mega#753] add tests for several mappers and rm unused imports
Browse files Browse the repository at this point in the history
  • Loading branch information
gattrCh committed Jun 25, 2024
1 parent fd5106e commit 663b546
Show file tree
Hide file tree
Showing 20 changed files with 286 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
import java.time.LocalDate;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;

@ApplicationScoped
public class AbsenceTimeMapper {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import java.util.Comparator;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

import static com.gepardec.mega.domain.utils.DateUtils.parseDateTime;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,8 @@
import de.provantis.zep.ProjektzeitType;
import jakarta.enterprise.context.ApplicationScoped;

import java.time.LocalDate;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;

@ApplicationScoped
public class ProjectTimeMapper {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public AbsenceTime map(ZepAbsence zepAbsence) {
logger.debug("Mapped ZepAbsence to AbsenceTime -- some values have been hardcoded and not fetched from the ZEP rest client");
return absenceTime;

}catch (Exception e){
} catch (Exception e){
throw new ZepServiceException("While trying to map ZepAbsence to AbsenceTime, an error occurred", e);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@
import com.gepardec.mega.zep.rest.dto.ZepAttendanceDirectionOfTravel;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;

import java.time.LocalDateTime;
import java.util.Comparator;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

@ApplicationScoped
public class ProjectEntryMapper implements Mapper<com.gepardec.mega.domain.model.monthlyreport.ProjectEntry, ZepAttendance> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

@ApplicationScoped
public class ProjectMapper implements Mapper<Project.Builder, ZepProject> {

@Inject
Logger logger;

public Project.Builder map(ZepProject zepProject) {
if (zepProject == null) {
logger.info("ZEP REST implementation -- While trying to map ZepProject to Project, ZepProject was null");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

import java.time.LocalDate;
import java.util.List;
import java.util.stream.Collectors;

@ApplicationScoped
public class AbsenceService {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import de.provantis.zep.BeschaeftigungszeitListeType;
import de.provantis.zep.BeschaeftigungszeitType;
import de.provantis.zep.MitarbeiterType;
import io.quarkus.test.junit.QuarkusTest;
import org.apache.commons.lang3.Range;
import org.apache.commons.lang3.tuple.Pair;
import org.junit.jupiter.api.BeforeEach;
Expand All @@ -17,10 +18,10 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

import static org.assertj.core.api.Assertions.assertThat;

@QuarkusTest
class EmployeeMapperTest {

private EmployeeMapper mapper;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ void whenNull_thenReturnsNull() {
assertThat(AbsenceTimeMapper.map(null)).isNull();
}

@Test
void mapList_whenNull_thenReturnsNull() {
assertThat(AbsenceTimeMapper.mapList(null)).isNull();
}


@Test
void withFullSettings_thenReturnsAbsenceTimeObject() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,9 @@ void whenAttributes_thenReturnsAttributesMap() {
assertThat(attributesMap.get(attribute2.getName())).isEqualTo(attribute2.getValue());

}

@Test
void whenNoAttributes_thenReturnsEmptyMap() {
assertThat(MapperUtil.convertAttributesToMap(null)).isEmpty();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ void whenNull_thenReturnsNull() {
assertThat(mapper.map(null)).isNull();
}

@Test
void mapList_whenNull_thenReturnsNull() {
assertThat(mapper.mapList(null)).isNull();
}

@Test
void withTaetigkeitIsNotATask_thenThrowsIllegalArgumentException() {
ProjektzeitType projektzeitType = projektzeitTypeFor("testen", WorkingLocation.MAIN.zepOrt, JourneyDirection.TO.getDirection(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ void withFullSettings_thenReturnsAbsenceTimeObject() {
void whenEmptyList_thenReturnsEmptyList() {
assertThat(ProjectTimeMapper.mapList(List.of())).isEmpty();
}

@Test
void whenListIsNull_thenReturnNull() {
assertThat(ProjectTimeMapper.mapList(null)).isNull();
}

@Test
void whenList_thenReturnList() {
ProjektzeitType pzt = new ProjektzeitType();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,29 @@
import com.gepardec.mega.zep.rest.dto.ZepAbsence;
import com.gepardec.mega.zep.rest.dto.ZepAbsenceReason;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.mockito.InjectMock;
import jakarta.inject.Inject;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;

import java.time.LocalDate;
import java.util.Iterator;
import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.verify;

@QuarkusTest
class AbsenceMapperTest {

@Inject
AbsenceMapper absenceMapper;

@InjectMock
Logger logger;

@Test
public void mapZepAbsenceToAbsenceTime() {
void mapZepAbsenceToAbsenceTime() {
ZepAbsenceReason zepAbsenceReason = ZepAbsenceReason.builder().name("KR").build();
ZepAbsence zepAbsence = ZepAbsence.builder()
.id(1)
Expand All @@ -41,7 +47,37 @@ public void mapZepAbsenceToAbsenceTime() {
}

@Test
public void mapZepAbsencesToAbsenceTimes() {
void mapZepAbsenceToAbsenceTime_whenReasonIsNull_thenReturnAbsenceTimeWithoutReason() {
ZepAbsence zepAbsence = ZepAbsence.builder()
.id(1)
.employeeId("001")
.startDate(LocalDate.of(2019, 1, 2))
.endDate(LocalDate.of(2019, 1, 5))
.absenceReason(null)
.approved(true)
.build();

AbsenceTime absence = absenceMapper.map(zepAbsence);

assertThat(absence.userId()).isEqualTo(zepAbsence.employeeId());
assertThat(absence.fromDate()).isEqualTo(zepAbsence.startDate());
assertThat(absence.toDate()).isEqualTo(zepAbsence.endDate());
assertThat(absence.reason()).isEqualTo("");
assertThat(absence.accepted()).isEqualTo(zepAbsence.approved());
}

@Test
void mapZepAbsenceToAbsenceTime_whenZepAbsenceIsNull_thenReturnNullAndLogMessage() {
ZepAbsence zepAbsence = null;

AbsenceTime absence = absenceMapper.map(zepAbsence);

assertThat(absence).isNull();
verify(logger).info("ZEP REST implementation -- While trying to map ZepAbsence to AbsenceTime, ZepAbsence was null");
}

@Test
void mapZepAbsencesToAbsenceTimes() {
ZepAbsence[] zepAbsencesArr = {
ZepAbsence.builder()
.id(1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class ActiveMapperTest {
ActiveMapper activeMapper;

@Test
public void map_whenPastStartDateFutureEndDate_isActive() {
void map_whenPastStartDateFutureEndDate_isActive() {
var employmentPeriods = createEmploymentPeriodListFromTodayOffset(
new DateOffset(-10, 2)
);
Expand All @@ -28,7 +28,7 @@ public void map_whenPastStartDateFutureEndDate_isActive() {
assertThat(active).isTrue();
}
@Test
public void map_whenTodayStartEndDate_isActive() {
void map_whenTodayStartEndDate_isActive() {
var employmentPeriods = createEmploymentPeriodListFromTodayOffset(
new DateOffset(0, 0)
);
Expand All @@ -39,7 +39,7 @@ public void map_whenTodayStartEndDate_isActive() {
}

@Test
public void map_whenPastStartDateTodayEndDate_isActive() {
void map_whenPastStartDateTodayEndDate_isActive() {
var employmentPeriods = createEmploymentPeriodListFromTodayOffset(
new DateOffset(-2, 0)
);
Expand All @@ -50,7 +50,7 @@ public void map_whenPastStartDateTodayEndDate_isActive() {
}

@Test
public void map_whenTodayStartDateFutureEndDate_isActive() {
void map_whenTodayStartDateFutureEndDate_isActive() {
var employmentPeriods = createEmploymentPeriodListFromTodayOffset(
new DateOffset(0, 1)
);
Expand All @@ -61,7 +61,7 @@ public void map_whenTodayStartDateFutureEndDate_isActive() {
}

@Test
public void map_whenNullEndDate_isActive() {
void map_whenNullEndDate_isActive() {
var employmentPeriods = List.of(
createEmploymentPeriodWithNullEndDate(-2)
);
Expand All @@ -72,7 +72,7 @@ public void map_whenNullEndDate_isActive() {
}

@Test
public void map_whenMultipleInactiveDatesWithOneNullEndDate_isActive() {
void map_whenMultipleInactiveDatesWithOneNullEndDate_isActive() {
var employmentPeriods = createEmploymentPeriodListFromTodayOffset(
new DateOffset(-100, -50),
new DateOffset(-50, -25),
Expand All @@ -87,7 +87,7 @@ public void map_whenMultipleInactiveDatesWithOneNullEndDate_isActive() {
}

@Test
public void map_whenMultipleInactiveDatesWithFutureEndDate_isActive() {
void map_whenMultipleInactiveDatesWithFutureEndDate_isActive() {
var employmentPeriods = createEmploymentPeriodListFromTodayOffset(
new DateOffset(-100, -50),
new DateOffset(-50, -25),
Expand All @@ -101,7 +101,7 @@ public void map_whenMultipleInactiveDatesWithFutureEndDate_isActive() {
}

@Test
public void map_whenActiveDatePlusNullDate_isActive() {
void map_whenActiveDatePlusNullDate_isActive() {
var employmentPeriods = createEmploymentPeriodListFromTodayOffset(
new DateOffset(-100, 2)
);
Expand All @@ -113,7 +113,7 @@ public void map_whenActiveDatePlusNullDate_isActive() {
}

@Test
public void map_whenMultipleActiveDates_isActive() {
void map_whenMultipleActiveDates_isActive() {
var employmentPeriods = createEmploymentPeriodListFromTodayOffset(
new DateOffset(-2, 10),
new DateOffset(-2, 10)
Expand All @@ -125,7 +125,7 @@ public void map_whenMultipleActiveDates_isActive() {
}

@Test
public void map_whenPastStartEndDate_isInactive() {
void map_whenPastStartEndDate_isInactive() {
var employmentPeriods = createEmploymentPeriodListFromTodayOffset(
new DateOffset(-10, -2)
);
Expand All @@ -136,7 +136,7 @@ public void map_whenPastStartEndDate_isInactive() {
}

@Test
public void map_whenFutureStartEndDate_isInactive() {
void map_whenFutureStartEndDate_isInactive() {
var employmentPeriods = createEmploymentPeriodListFromTodayOffset(
new DateOffset(2, 2)
);
Expand All @@ -147,7 +147,7 @@ public void map_whenFutureStartEndDate_isInactive() {
}

@Test
public void map_whenEmptyList_isInactive() {
void map_whenEmptyList_isInactive() {
List<ZepEmploymentPeriod> employmentPeriods = List.of();

boolean active = activeMapper.map(employmentPeriods);
Expand All @@ -156,7 +156,7 @@ public void map_whenEmptyList_isInactive() {
}

@Test
public void map_whenNullStartDate_isInactive() {
void map_whenNullStartDate_isInactive() {
var employmentPeriods = List.of(
createEmploymentPeriodWithNullStartDate(2)
);
Expand All @@ -166,7 +166,7 @@ public void map_whenNullStartDate_isInactive() {
}

@Test
public void map_whenNullPeriod_isInactive() {
void map_whenNullPeriod_isInactive() {
var employmentPeriods = List.of(
createEmploymentPeriodWithNullDates()
);
Expand All @@ -175,6 +175,11 @@ public void map_whenNullPeriod_isInactive() {
assertThat(active).isFalse();
}

@Test
void map_whenEmploymentPeriodListIsEmpty_thenReturnFalse() {
assertThat(activeMapper.map(null)).isFalse();
}

private ZepEmploymentPeriod createEmploymentPeriodWithNullEndDate(int offsetStart) {
LocalDateTime now = LocalDateTime.now();
return ZepEmploymentPeriod.builder()
Expand Down
Loading

0 comments on commit 663b546

Please sign in to comment.