-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Gepardec/mega#753] add tests several services
- Loading branch information
Showing
8 changed files
with
488 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
127 changes: 127 additions & 0 deletions
127
...ardec/mega/service/impl/prematureemployeecheck/PrematureEmployeeCheckServiceImplTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
package com.gepardec.mega.service.impl.prematureemployeecheck; | ||
|
||
import com.gepardec.mega.db.entity.employee.PrematureEmployeeCheckEntity; | ||
import com.gepardec.mega.db.entity.employee.PrematureEmployeeCheckState; | ||
import com.gepardec.mega.db.repository.PrematureEmployeeCheckRepository; | ||
import com.gepardec.mega.domain.mapper.PrematureEmployeeCheckMapper; | ||
import com.gepardec.mega.domain.model.PrematureEmployeeCheck; | ||
import com.gepardec.mega.service.api.PrematureEmployeeCheckService; | ||
import io.quarkus.test.junit.QuarkusTest; | ||
import io.quarkus.test.junit.mockito.InjectMock; | ||
import jakarta.inject.Inject; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.time.LocalDate; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.ArgumentMatchers.anyLong; | ||
import static org.mockito.Mockito.when; | ||
|
||
@QuarkusTest | ||
public class PrematureEmployeeCheckServiceImplTest { | ||
@Inject | ||
PrematureEmployeeCheckService prematureEmployeeCheckService; | ||
|
||
@InjectMock | ||
PrematureEmployeeCheckRepository checkRepository; | ||
|
||
@InjectMock | ||
PrematureEmployeeCheckMapper prematureEmployeeCheckMapper; | ||
|
||
@Test | ||
void findAllForMonth_whenSuccessful_thenReturnTrue() { | ||
List<PrematureEmployeeCheckEntity> entityList = new ArrayList<>(); | ||
entityList.add( | ||
new PrematureEmployeeCheckEntity() | ||
); | ||
|
||
when(checkRepository.findAllForMonth(any(LocalDate.class))) | ||
.thenReturn(entityList); | ||
|
||
when(prematureEmployeeCheckMapper.mapListToDomain(any())) | ||
.thenReturn(List.of(PrematureEmployeeCheck.builder().id(1L).build())); | ||
|
||
List<PrematureEmployeeCheck> actual = prematureEmployeeCheckService.findAllForMonth(any(LocalDate.class)); | ||
|
||
assertThat(actual.size()).isOne(); | ||
} | ||
|
||
@Test | ||
void deleteById_whenSuccessful_thenReturnTrue() { | ||
when(checkRepository.delete(anyLong())) | ||
.thenReturn(true); | ||
|
||
assertThat(prematureEmployeeCheckService.deleteById(anyLong())).isTrue(); | ||
} | ||
|
||
@Test | ||
void deleteAllForMonthWithState_whenSuccessful_thenReturnId() { | ||
when(checkRepository.deleteByMonthAndStates(any(LocalDate.class), any())) | ||
.thenReturn(1L); | ||
|
||
assertThat(prematureEmployeeCheckService.deleteAllForMonthWithState(LocalDate.of(2024,3,1), List.of(PrematureEmployeeCheckState.IN_PROGRESS, PrematureEmployeeCheckState.DONE))).isEqualTo(1L); | ||
} | ||
|
||
@Test | ||
void update_whenSuccessful_thenReturnTrue() { | ||
PrematureEmployeeCheck prematureEmployeeCheck = PrematureEmployeeCheck.builder().id(1L) | ||
.forMonth(LocalDate.of(2024,6,1)) | ||
.reason("Test reason") | ||
.build(); | ||
|
||
when(checkRepository.findById(anyLong())) | ||
.thenReturn(createEntity()); | ||
|
||
when(prematureEmployeeCheckMapper.mapToEntity(any(PrematureEmployeeCheck.class), any(PrematureEmployeeCheckEntity.class))) | ||
.thenReturn(createEntity()); | ||
|
||
when(checkRepository.update(any(PrematureEmployeeCheckEntity.class))) | ||
.thenReturn(createEntity()); | ||
|
||
boolean actual = prematureEmployeeCheckService.update(prematureEmployeeCheck); | ||
|
||
assertThat(actual).isTrue(); | ||
} | ||
|
||
@Test | ||
void update_whenNotSuccessful_thenReturnFalse() { | ||
PrematureEmployeeCheck prematureEmployeeCheck = PrematureEmployeeCheck.builder().id(1L) | ||
.forMonth(LocalDate.of(2024,6,1)) | ||
.reason("Test reason") | ||
.build(); | ||
|
||
when(checkRepository.findById(anyLong())) | ||
.thenReturn(createEntity()); | ||
|
||
when(prematureEmployeeCheckMapper.mapToEntity(any(PrematureEmployeeCheck.class), any(PrematureEmployeeCheckEntity.class))) | ||
.thenReturn(createEntity()); | ||
|
||
when(checkRepository.update(any(PrematureEmployeeCheckEntity.class))) | ||
.thenReturn(createEntityWithIdNull()); | ||
|
||
boolean actual = prematureEmployeeCheckService.update(prematureEmployeeCheck); | ||
|
||
assertThat(actual).isFalse(); | ||
} | ||
|
||
private PrematureEmployeeCheckEntity createEntity() { | ||
PrematureEmployeeCheckEntity entity = new PrematureEmployeeCheckEntity(); | ||
entity.setId(1L); | ||
entity.setForMonth(LocalDate.of(2024,6, 1)); | ||
entity.setReason("Test reason"); | ||
|
||
return entity; | ||
} | ||
|
||
private PrematureEmployeeCheckEntity createEntityWithIdNull() { | ||
PrematureEmployeeCheckEntity entity = new PrematureEmployeeCheckEntity(); | ||
entity.setId(null); | ||
entity.setForMonth(LocalDate.of(2024,6, 1)); | ||
entity.setReason("Test reason"); | ||
|
||
return entity; | ||
} | ||
} |
Oops, something went wrong.