Skip to content

Commit

Permalink
Added test
Browse files Browse the repository at this point in the history
  • Loading branch information
szymonpoltorak committed Apr 8, 2024
1 parent 68e2e72 commit 3280ba9
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import dev.corn.cornbackend.test.sprint.SprintTestDataBuilder;
import dev.corn.cornbackend.test.sprint.data.AddNewSprintData;
import dev.corn.cornbackend.utils.exceptions.project.ProjectDoesNotExistException;
import dev.corn.cornbackend.utils.exceptions.sprint.InvalidSprintDateException;
import dev.corn.cornbackend.utils.exceptions.sprint.SprintDoesNotExistException;
import dev.corn.cornbackend.utils.exceptions.sprint.SprintEndDateMustBeAfterStartDate;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -71,11 +72,11 @@ final void test_addNewSprint_shouldAddNewSprint() {
assertEquals(expected, actual, SPRINT_RESPONSE_SHOULD_BE_EQUAL_TO_EXPECTED);
verify(sprintRepository).save(ADD_SPRINT_DATA.asSprint());
}

@Test
final void test_addNewSprint_shouldThrowWhenProjectNotFound() {
// given
SprintResponse expected = MAPPER.toSprintResponse(ADD_SPRINT_DATA.asSprint());
SprintRequest sprintRequest = ADD_SPRINT_DATA.asSprintRequest();
User owner = ADD_SPRINT_DATA.project().getOwner();

// when
Expand Down Expand Up @@ -395,7 +396,7 @@ final void test_getCurrentAndFutureSprints_shouldReturnSprintResponseList() {
when(projectRepository.findByIdWithProjectMember(projectId, user))
.thenReturn(Optional.of(ADD_SPRINT_DATA.project()));
when(sprintRepository.findAllByProjectAndEndDateAfter(
any(),any(), any()))
any(), any(), any()))
.thenReturn(new PageImpl<>(List.of(ADD_SPRINT_DATA.asSprint())));
when(MAPPER.toSprintResponse(ADD_SPRINT_DATA.asSprint()))
.thenReturn(ADD_SPRINT_DATA.asSprintResponse());
Expand All @@ -419,4 +420,38 @@ final void test_getCurrentAndFutureSprints_shouldThrowProjectDoesNotExistExcepti
assertThrows(ProjectDoesNotExistException.class, () ->
sprintService.getCurrentAndFutureSprints(projectId, user));
}
}

@Test
final void test_addNewSprint_shouldThrowInvalidSprintDateException() {
// given
SprintRequest expected = ADD_SPRINT_DATA.asSprintRequest();
User owner = ADD_SPRINT_DATA.project().getOwner();

// when
when(sprintRepository.existsBetweenStartDateAndEndDate(ADD_SPRINT_DATA.asSprint().getStartDate(),
ADD_SPRINT_DATA.asSprint().getEndDate(), ADD_SPRINT_DATA.project().getProjectId()))
.thenReturn(true);

// then
assertThrows(InvalidSprintDateException.class, () -> {
sprintService.addNewSprint(expected, owner);
});
}

@Test
final void test_updateSprintsStartDate_shouldThrowInvalidSprintDateException() {
// given
LocalDate newStartDate = LocalDate.now();
final long sprintId = 1L;
User owner = ADD_SPRINT_DATA.project().getOwner();

// when
when(sprintRepository.existsEndDateBeforeDate(newStartDate))
.thenReturn(true);

// then
assertThrows(InvalidSprintDateException.class, () -> {
sprintService.updateSprintsStartDate(newStartDate, sprintId, owner);
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ public static BacklogItemDetailsTestData backlogItemDetailsTestData() {
.projectId(sprint.getProject().getProjectId())
.sprintName(sprint.getSprintName())
.sprintDescription(sprint.getSprintDescription())
.sprintStartDate(sprint.getStartDate())
.sprintEndDate(sprint.getEndDate())
.startDate(sprint.getStartDate())
.endDate(sprint.getEndDate())
.build();

ProjectResponse projectResponse = ProjectResponse.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ public SprintResponse asSprintResponse() {
.sprintName(name)
.projectId(project.getProjectId())
.sprintDescription(description)
.sprintStartDate(startDate)
.sprintEndDate(endDate)
.startDate(startDate)
.endDate(endDate)
.build();
}

Expand Down

0 comments on commit 3280ba9

Please sign in to comment.