Skip to content
Snippets Groups Projects
Commit 1aaaa040 authored by OZGCloud's avatar OZGCloud
Browse files

OZG-5666 handle empty sentAt

parent 1cd8f4b1
No related branches found
No related tags found
No related merge requests found
......@@ -24,6 +24,9 @@
package de.ozgcloud.nachrichten.antragraum;
import java.time.ZonedDateTime;
import org.apache.commons.lang3.StringUtils;
import org.mapstruct.CollectionMappingStrategy;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
......@@ -71,8 +74,16 @@ interface AntragraumNachrichtMapper {
@Mapping(target = "sentSuccessful", constant = "true")
@Mapping(target = "subject", constant = "Antwort") // TODO klären
@Mapping(target = "vorgangId", ignore = true)
@Mapping(target = "sentAt", expression = "java(mapZonedDateTime(answer.getSentAt()))")
PostfachNachricht fromRueckfrageAnswer(GrpcRueckfrageAnswer answer);
default ZonedDateTime mapZonedDateTime(String sentAt) {
if (StringUtils.isBlank(sentAt)) {
return null;
}
return ZonedDateTime.parse(sentAt);
}
@Mapping(target = "mergeFrom", ignore = true)
@Mapping(target = "clearField", ignore = true)
@Mapping(target = "clearOneof", ignore = true)
......
......@@ -26,6 +26,7 @@ import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import org.apache.commons.lang3.StringUtils;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.mapstruct.factory.Mappers;
......@@ -148,6 +149,15 @@ class AntragraumNachrichtMapperTest {
assertThat(result.getSentAt()).isCloseTo(PostfachNachrichtTestFactory.SENT_AT, within(2, ChronoUnit.SECONDS));
}
@Test
void shouldHandleEmptySentAt() {
var rueckfrage = GrpcRueckfrageAnswerTestFactory.createBuilder().setSentAt(StringUtils.EMPTY).build();
var result = mapper.fromRueckfrageAnswer(rueckfrage);
assertThat(result.getSentAt()).isNull();
}
private PostfachNachricht map() {
return mapper.fromRueckfrageAnswer(GrpcRueckfrageAnswerTestFactory.create());
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment