diff --git a/goofy-server/src/main/java/de/itvsh/goofy/postfach/PostfachMailModelAssembler.java b/goofy-server/src/main/java/de/itvsh/goofy/postfach/PostfachMailModelAssembler.java index 74734a95188d2896e2a6bd3f4dcc013f77f17278..0b49bcbc606db14e5096b9dea6af58360053a0b6 100644 --- a/goofy-server/src/main/java/de/itvsh/goofy/postfach/PostfachMailModelAssembler.java +++ b/goofy-server/src/main/java/de/itvsh/goofy/postfach/PostfachMailModelAssembler.java @@ -31,8 +31,8 @@ class PostfachMailModelAssembler implements RepresentationModelAssembler<Postfac private static final Predicate<PostfachMail> HAS_ATTACHMENTS = nachricht -> !nachricht.getAttachments().isEmpty(); static final String SYSTEM_USER_IDENTIFIER = "system"; - private static final Predicate<PostfachMail> SENT_BY_CLIENT_USER = postfachNachricht -> !postfachNachricht.getCreatedBy().toString() - .startsWith(SYSTEM_USER_IDENTIFIER); + private static final Predicate<PostfachMail> SENT_BY_CLIENT_USER = postfachNachricht -> Optional.ofNullable(postfachNachricht.getCreatedBy()) + .map(createdBy -> !createdBy.toString().startsWith(SYSTEM_USER_IDENTIFIER)).orElse(false); public CollectionModel<EntityModel<PostfachMail>> toCollectionModel(Stream<PostfachMail> entities, String vorgangId, long vorgangVersion, Optional<String> postfachId) { diff --git a/goofy-server/src/test/java/de/itvsh/goofy/postfach/PostfachMailModelAssemblerTest.java b/goofy-server/src/test/java/de/itvsh/goofy/postfach/PostfachMailModelAssemblerTest.java index 8faa7b4cf65a9aebc068bcd67922978c6a53056e..100b7a73b6827e90dfd9af06f9aca36d7102f202 100644 --- a/goofy-server/src/test/java/de/itvsh/goofy/postfach/PostfachMailModelAssemblerTest.java +++ b/goofy-server/src/test/java/de/itvsh/goofy/postfach/PostfachMailModelAssemblerTest.java @@ -102,8 +102,15 @@ class PostfachMailModelAssemblerTest { assertThat(link).isNotPresent(); } - } + @Test + void shouldNotBePresentOnNull() { + var link = modelAssembler.toModel(PostfachMailTestFactory.createBuilder().createdBy(null).build()) + .getLink(PostfachMailModelAssembler.REL_CREATED_BY); + + assertThat(link).isNotPresent(); + } + } } @Nested