From 34ff49fc4016d9954e1a489e341647015bbe644d Mon Sep 17 00:00:00 2001 From: Gunnar Velle Date: Wed, 13 Sep 2023 13:24:40 +0200 Subject: [PATCH] Test to throw exception if no parent --- .../ndla/taxonomy/service/DomainEntityHelperServiceImpl.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/no/ndla/taxonomy/service/DomainEntityHelperServiceImpl.java b/src/main/java/no/ndla/taxonomy/service/DomainEntityHelperServiceImpl.java index 86d0d0e8..5c636028 100644 --- a/src/main/java/no/ndla/taxonomy/service/DomainEntityHelperServiceImpl.java +++ b/src/main/java/no/ndla/taxonomy/service/DomainEntityHelperServiceImpl.java @@ -231,6 +231,9 @@ private Optional updateNodeConnection(NodeConnection nodeConnectio nodeConnection.getParent().get().getPublicId()); Node child = nodeRepository.findByPublicId( nodeConnection.getChild().get().getPublicId()); + if (parent == null || child == null) { + throw new RuntimeException("Failed to find parent or child."); + } existing = nodeConnectionRepository.findByParentIdAndChildId(parent.getId(), child.getId()); if (existing != null) { existing.setPublicId(nodeConnection.getPublicId());