Skip to content
Snippets Groups Projects
Commit 910f87f5 authored by OZGCloud's avatar OZGCloud
Browse files

OZG-7239 OZG-7286 Handle case when postfach setting has no body

parent e12ac2e6
Branches
Tags
No related merge requests found
......@@ -64,8 +64,10 @@ class SettingService {
}
PostfachSettingBody getSettingWithPostfachFromDb() {
var postfach = repository.findOneByName(POSTFACH_SETTING_ITEM_NAME);
return postfach.isPresent() ? (PostfachSettingBody) postfach.get().getSettingBody() : PostfachSettingBody.builder().build();
return repository.findOneByName(POSTFACH_SETTING_ITEM_NAME)
.map(Setting::getSettingBody)
.map(PostfachSettingBody.class::cast)
.orElse(PostfachSettingBody.builder().build());
}
Map<String, OrganisationsEinheitSettings> getOrganisationsEinheitSettings() {
......
......@@ -62,9 +62,6 @@ class SettingServiceTest {
private final PostfachSettingBody postfach = PostfachSettingBodyTestFactory.create();
private static final String POSTFACH = "Postfach";
private final Setting settingWithPostfach = SettingTestFactory.createBuilder().name(POSTFACH).settingBody(postfach).build();
@Nested
class TestGetAlfaSettingDTO {
......@@ -147,9 +144,15 @@ class SettingServiceTest {
@Nested
class TestGetSettingWithPostfachFromDb {
private static final String POSTFACH = "Postfach";
private final Setting emptyPostfachSetting = SettingTestFactory.createBuilder().name(POSTFACH).build();
private final Setting postfachSettingWithBody = SettingTestFactory.createBuilder().name(POSTFACH).settingBody(postfach).build();
@Test
void shouldCallRepository() {
when(repository.findOneByName(POSTFACH)).thenReturn(Optional.of(settingWithPostfach));
when(repository.findOneByName(POSTFACH)).thenReturn(Optional.of(postfachSettingWithBody));
service.getSettingWithPostfachFromDb();
......@@ -158,7 +161,7 @@ class SettingServiceTest {
@Test
void shouldReturnPostfachSettingBody() {
when(repository.findOneByName(POSTFACH)).thenReturn(Optional.of(settingWithPostfach));
when(repository.findOneByName(POSTFACH)).thenReturn(Optional.of(postfachSettingWithBody));
var returnedBody = service.getSettingWithPostfachFromDb();
......@@ -166,13 +169,22 @@ class SettingServiceTest {
}
@Test
void shouldReturnEmptyPostfachSettingBodyForEmptySetting() {
void shouldReturnEmptyPostfachSettingBodyWhenSettingNotFound() {
when(repository.findOneByName(POSTFACH)).thenReturn(Optional.empty());
var returnedBody = service.getSettingWithPostfachFromDb();
assertThat(returnedBody).usingRecursiveComparison().isEqualTo(PostfachSettingBody.builder().build());
}
@Test
void shouldReturnEmptyPostfachSettingBodyForSettingWithoutBody() {
when(repository.findOneByName(POSTFACH)).thenReturn(Optional.of(emptyPostfachSetting));
var returnedBody = service.getSettingWithPostfachFromDb();
assertThat(returnedBody).usingRecursiveComparison().isEqualTo(PostfachSettingBody.builder().build());
}
}
@Nested
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment