-
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.
* add unit tests for new class TopicEnrichmentService
- Loading branch information
1 parent
210dc42
commit aeba3ee
Showing
2 changed files
with
101 additions
and
1 deletion.
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
87 changes: 87 additions & 0 deletions
87
src/test/java/de/caritas/cob/agencyservice/api/service/TopicEnrichmentServiceTest.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,87 @@ | ||
package de.caritas.cob.agencyservice.api.service; | ||
|
||
import static com.google.common.collect.Lists.newArrayList; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.mockito.Mockito.when; | ||
|
||
import de.caritas.cob.agencyservice.api.model.AgencyTopicsDTO; | ||
import java.util.List; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
import de.caritas.cob.agencyservice.topicservice.generated.web.model.TopicDTO; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class TopicEnrichmentServiceTest { | ||
|
||
@InjectMocks | ||
TopicEnrichmentService topicEnrichmentService; | ||
|
||
@Mock | ||
TopicService topicService; | ||
|
||
@Test | ||
void enrichTopicIdsWithTopicData_Should_EnrichAgencyWithTopicDataFromTopicService() { | ||
// given | ||
when(topicService.getAllTopics()).thenReturn( | ||
newArrayList(new TopicDTO().id(1L).name("first topic").description("desc"), | ||
new TopicDTO().id(2L).name("second topic").description("desc"))); | ||
List<Integer> topicIds = newArrayList(1, 2); | ||
|
||
// when | ||
var result = topicEnrichmentService.enrichTopicIdsWithTopicData(topicIds); | ||
|
||
// then | ||
assertThat(result).isNotEmpty(); | ||
assertThat(result) | ||
.extracting(AgencyTopicsDTO::getName) | ||
.contains("first topic", "second topic"); | ||
} | ||
|
||
|
||
@Test | ||
void enrichTopicIdsWithTopicData_Should_ReturnEmptyListIfNoTopicsAreDefined() { | ||
// given | ||
when(topicService.getAllTopics()).thenReturn( | ||
newArrayList()); | ||
List<Integer> topicIds = newArrayList(1, 2); | ||
|
||
// when | ||
var result = topicEnrichmentService.enrichTopicIdsWithTopicData(topicIds); | ||
|
||
// then | ||
assertThat(result).isEmpty(); | ||
} | ||
|
||
|
||
@Test | ||
void enrichTopicIdsWithTopicData_Should_ReturnEmptyListIfTopicsListIsNull() { | ||
// given | ||
when(topicService.getAllTopics()).thenReturn( | ||
null); | ||
List<Integer> topicIds = newArrayList(1, 2); | ||
|
||
// when | ||
var result = topicEnrichmentService.enrichTopicIdsWithTopicData(topicIds); | ||
|
||
// then | ||
assertThat(result).isEmpty(); | ||
} | ||
|
||
@Test | ||
void enrichTopicIdsWithTopicData_Should_ReturnEmptyListIfTopicIdDoNotMatch() { | ||
// given | ||
when(topicService.getAllTopics()).thenReturn( | ||
newArrayList(new TopicDTO().id(3L).name("third topic").description("desc"), | ||
new TopicDTO().id(4L).name("fourth topic").description("desc"))); | ||
List<Integer> topicIds = newArrayList(1, 2); | ||
|
||
// when | ||
var result = topicEnrichmentService.enrichTopicIdsWithTopicData(topicIds); | ||
|
||
// then | ||
assertThat(result).isEmpty(); | ||
} | ||
} |