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

OZG-5010,OZG-5397 trim empty strings to null

parent 0addd624
No related branches found
No related tags found
No related merge requests found
......@@ -86,8 +86,14 @@ public class BescheidItemMapper {
if (attachmentsObject instanceof Collection<?> attachments) {
return (Collection<String>) attachments;
}
return nonNull(attachmentsObject)
? List.of(String.valueOf(attachmentsObject))
: null;
if (attachmentsObject instanceof String attachment) {
attachment = StringUtils.trimToNull(attachment);
if (nonNull(attachment)) {
return List.of(attachment);
}
} else if (nonNull(attachmentsObject)) {
return List.of(String.valueOf(attachmentsObject));
}
return null; //NOSONAR
}
}
......@@ -29,8 +29,11 @@ import static org.mockito.Mockito.*;
import java.util.List;
import java.util.Map;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.NullAndEmptySource;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Spy;
......@@ -242,9 +245,11 @@ class BescheidItemMapperTest {
assertThat(result).containsExactly(BescheidItemTestFactory.ATTACHMENT);
}
@Test
void shouldReturnNull() {
var result = mapper.toAttachments(null);
@DisplayName("should return null")
@ParameterizedTest(name = "when attachmentsObject is \"{0}\"")
@NullAndEmptySource
void shouldReturnNull(String attachmentsObject) {
var result = mapper.toAttachments(attachmentsObject);
assertThat(result).isNull();
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment