From be380b42c3d3c42b0e4666a78ad25e7ff4d80ce9 Mon Sep 17 00:00:00 2001 From: Nevio Di Gennaro Date: Tue, 14 Jan 2025 11:18:01 +0100 Subject: [PATCH] fix duplicate keyresult tests --- .../service/business/ObjectiveBusinessService.java | 2 +- .../business/ObjectiveBusinessServiceTest.java | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/backend/src/main/java/ch/puzzle/okr/service/business/ObjectiveBusinessService.java b/backend/src/main/java/ch/puzzle/okr/service/business/ObjectiveBusinessService.java index 743eb0cbcb..fe2fead61c 100644 --- a/backend/src/main/java/ch/puzzle/okr/service/business/ObjectiveBusinessService.java +++ b/backend/src/main/java/ch/puzzle/okr/service/business/ObjectiveBusinessService.java @@ -177,7 +177,7 @@ public KeyResult makeCopyOfKeyResultOrdinal(KeyResult keyResult, Objective dupli public List duplicateActionList(KeyResult oldKeyResult, KeyResult newKeyResult) { List actionList = oldKeyResult.getActionList(); - if (!actionList.isEmpty()) { + if (actionList != null) { actionList = actionList .stream() .map(e -> Action.Builder diff --git a/backend/src/test/java/ch/puzzle/okr/service/business/ObjectiveBusinessServiceTest.java b/backend/src/test/java/ch/puzzle/okr/service/business/ObjectiveBusinessServiceTest.java index c0da1c745f..a068eb9932 100644 --- a/backend/src/test/java/ch/puzzle/okr/service/business/ObjectiveBusinessServiceTest.java +++ b/backend/src/test/java/ch/puzzle/okr/service/business/ObjectiveBusinessServiceTest.java @@ -261,8 +261,11 @@ void shouldDuplicateMetricKeyResult() { .build(); KeyResult keyResultMetric = KeyResultMetric.Builder.builder().withTitle("Metric").build(); objectiveBusinessService.duplicateKeyResult(authorizationUser, keyResultMetric, objective); - verify(objectiveBusinessService.makeCopyOfKeyResultMetric(keyResultMetric, objective), times(1)); - verify(keyResultBusinessService.createEntity(keyResultMetric, authorizationUser), times(1)); + verify(objectiveBusinessService, times(1)) + .makeCopyOfKeyResultMetric(keyResultMetric, objective); + + verify(keyResultBusinessService, times(1)) + .createEntity(any(KeyResult.class), any(AuthorizationUser.class)); } @DisplayName("Should duplicate ordinal key result") @@ -275,8 +278,11 @@ void shouldDuplicateOrdinalKeyResult() { .build(); KeyResult keyResultOrdinal = KeyResultOrdinal.Builder.builder().withTitle("Ordinal").build(); objectiveBusinessService.duplicateKeyResult(authorizationUser, keyResultOrdinal, objective); - verify(objectiveBusinessService.makeCopyOfKeyResultMetric(keyResultOrdinal, objective), times(1)); - verify(keyResultBusinessService.createEntity(keyResultOrdinal, authorizationUser), times(1)); + verify(objectiveBusinessService, times(1)) + .makeCopyOfKeyResultOrdinal(keyResultOrdinal, objective); + + verify(keyResultBusinessService, times(1)) + .createEntity(any(KeyResult.class), any(AuthorizationUser.class)); } @DisplayName("Should duplicate ActionList")