Skip to content
Snippets Groups Projects
Commit 812f4834 authored by OZGCloud's avatar OZGCloud
Browse files

OZG-2966 trim null to empty string

parent b8a80d71
No related branches found
No related tags found
No related merge requests found
...@@ -148,10 +148,18 @@ class PostfachNachrichtPdfService { ...@@ -148,10 +148,18 @@ class PostfachNachrichtPdfService {
} }
private String formatUserName(UserProfile user) { private String formatUserName(UserProfile user) {
return String.format("%s %s", user.getFirstName(), user.getLastName()); return formatForPdf(user.getFirstName(), user.getLastName());
} }
private String formatAntragstellerName(Antragsteller antragsteller) { private String formatAntragstellerName(Antragsteller antragsteller) {
return String.format("%s %s", antragsteller.getVorname(), antragsteller.getNachname()); return formatForPdf(antragsteller.getVorname(), antragsteller.getNachname());
}
private String formatForPdf(String firstName, String lastName) {
return String.format("%s %s", getPdfStringValue(firstName), getPdfStringValue(lastName)).trim();
}
private String getPdfStringValue(String value) {
return Optional.ofNullable(StringUtils.trimToNull(value)).orElseGet(() -> StringUtils.EMPTY);
} }
} }
\ No newline at end of file
...@@ -32,6 +32,7 @@ import java.io.InputStream; ...@@ -32,6 +32,7 @@ import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.util.stream.Stream; import java.util.stream.Stream;
import org.apache.commons.lang3.StringUtils;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Nested;
...@@ -262,9 +263,9 @@ class PostfachNachrichtPdfServiceTest { ...@@ -262,9 +263,9 @@ class PostfachNachrichtPdfServiceTest {
return service.mapPostfachNachricht(PostfachNachrichtPdfDataTestFactory.create(), AntragstellerTestFactory.create()); return service.mapPostfachNachricht(PostfachNachrichtPdfDataTestFactory.create(), AntragstellerTestFactory.create());
} }
@DisplayName("for outgoing nachricht") @DisplayName("for incoming nachricht")
@Nested @Nested
class TestDirectionOut { class TestDirectionIn {
@DisplayName("build absender name") @DisplayName("build absender name")
@Nested @Nested
...@@ -286,12 +287,19 @@ class PostfachNachrichtPdfServiceTest { ...@@ -286,12 +287,19 @@ class PostfachNachrichtPdfServiceTest {
assertThat(name).isEqualTo(PostfachNachrichtPdfService.FALLBACK_ANTRAGSTELLER_NAME); assertThat(name).isEqualTo(PostfachNachrichtPdfService.FALLBACK_ANTRAGSTELLER_NAME);
} }
@Test
void shouldReturnEmptyStringOnNullAntragstellerName() {
var name = service.buildAbsenderName(data, AntragstellerTestFactory.createBuilder().vorname(null).nachname(null).build());
assertThat(name).isEqualTo(StringUtils.EMPTY);
}
} }
} }
@DisplayName("for incoming nachricht") @DisplayName("for outgoing nachricht")
@Nested @Nested
class TestDirectionIn { class TestDirectionOut {
@DisplayName("build absender name") @DisplayName("build absender name")
@Nested @Nested
...@@ -302,9 +310,9 @@ class PostfachNachrichtPdfServiceTest { ...@@ -302,9 +310,9 @@ class PostfachNachrichtPdfServiceTest {
@Test @Test
void shouldReturnUserProfileNameIfExists() { void shouldReturnUserProfileNameIfExists() {
var userName = service.buildAbsenderName(data, AntragstellerTestFactory.create()); var name = service.buildAbsenderName(data, AntragstellerTestFactory.create());
assertThat(userName).isEqualTo(UserProfileTestFactory.FIRSTNAME + " " + UserProfileTestFactory.LASTNAME); assertThat(name).isEqualTo(UserProfileTestFactory.FIRSTNAME + " " + UserProfileTestFactory.LASTNAME);
} }
@Test @Test
...@@ -315,6 +323,16 @@ class PostfachNachrichtPdfServiceTest { ...@@ -315,6 +323,16 @@ class PostfachNachrichtPdfServiceTest {
assertThat(name).isEqualTo(PostfachNachrichtPdfService.FALLBACK_USER_NAME); assertThat(name).isEqualTo(PostfachNachrichtPdfService.FALLBACK_USER_NAME);
} }
@Test
void shouldReturnEmptyStringOnNullName() {
var data = PostfachNachrichtPdfDataTestFactory.createBuilder().direction(Direction.OUT)
.user(UserProfileTestFactory.createBuilder().firstName(null).lastName(null).build()).build();
var name = service.buildAbsenderName(data, AntragstellerTestFactory.create());
assertThat(name).isEmpty();
}
} }
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment