From 6fc2744f31ecb3e33777086650725fb7dd2435a5 Mon Sep 17 00:00:00 2001 From: tillias Date: Sun, 1 Nov 2020 21:07:30 +0100 Subject: [PATCH] Unit tests fix #79 --- pom.xml | 2 +- .../custom/ImpactAnalysisServiceTest.java | 26 ++++++++++--------- .../custom/ReleasePathCustomServiceTest.java | 21 ++++++++------- 3 files changed, 26 insertions(+), 23 deletions(-) diff --git a/pom.xml b/pom.xml index 664f3dc..8d7b588 100644 --- a/pom.xml +++ b/pom.xml @@ -22,7 +22,7 @@ 3.3.9 - 10 + 1.8 v12.16.1 6.14.5 UTF-8 diff --git a/src/test/java/com/github/microcatalog/service/custom/ImpactAnalysisServiceTest.java b/src/test/java/com/github/microcatalog/service/custom/ImpactAnalysisServiceTest.java index 9ca02d8..3eccf4a 100644 --- a/src/test/java/com/github/microcatalog/service/custom/ImpactAnalysisServiceTest.java +++ b/src/test/java/com/github/microcatalog/service/custom/ImpactAnalysisServiceTest.java @@ -15,6 +15,7 @@ import org.springframework.boot.test.mock.mockito.MockBean; import java.util.List; +import java.util.NoSuchElementException; import java.util.Optional; import static org.assertj.core.api.Assertions.*; @@ -91,36 +92,36 @@ void calculate_NoCycles_Success() { Group group = groups.get(0); assertThat(group.getItems()).isNotEmpty().hasSize(1); - Item item = group.findByTargetId(5L).orElseThrow(); + Item item = group.findByTargetId(5L).orElseThrow(NoSuchElementException::new); assertThatItemHasSiblings(item, 4L, 7L); group = groups.get(1); assertThat(group.getItems()).isNotEmpty().hasSize(1); - item = group.findByTargetId(7L).orElseThrow(); + item = group.findByTargetId(7L).orElseThrow(NoSuchElementException::new); assertThatItemHasSiblings(item, 4L); group = groups.get(2); assertThat(group.getItems()).isNotEmpty().hasSize(1); - item = group.findByTargetId(4L).orElseThrow(); + item = group.findByTargetId(4L).orElseThrow(NoSuchElementException::new); assertThatItemHasSiblings(item, 2L, 6L); group = groups.get(3); assertThat(group.getItems()).isNotEmpty().hasSize(2); - item = group.findByTargetId(6L).orElseThrow(); + item = group.findByTargetId(6L).orElseThrow(NoSuchElementException::new); assertThatItemHasNoSiblings(item); - item = group.findByTargetId(2L).orElseThrow(); + item = group.findByTargetId(2L).orElseThrow(NoSuchElementException::new); assertThatItemHasSiblings(item, 1L); group = groups.get(4); assertThat(group.getItems()).isNotEmpty().hasSize(1); - item = group.findByTargetId(1L).orElseThrow(); + item = group.findByTargetId(1L).orElseThrow(NoSuchElementException::new); assertThatItemHasSiblings(item, 10L, 12L); group = groups.get(5); assertThat(group.getItems()).isNotEmpty().hasSize(2); - item = group.findByTargetId(10L).orElseThrow(); + item = group.findByTargetId(10L).orElseThrow(NoSuchElementException::new); assertThatItemHasNoSiblings(item); - item = group.findByTargetId(12L).orElseThrow(); + item = group.findByTargetId(12L).orElseThrow(NoSuchElementException::new); assertThatItemHasNoSiblings(item); } @@ -176,26 +177,27 @@ void calculate_ContainsCyclesInOtherComponent_Success() { Group group = groups.get(0); assertThat(group.getItems()).isNotEmpty().hasSize(1); - Item item = group.findByTargetId(4L).orElseThrow(); + Item item = group.findByTargetId(4L).orElseThrow(NoSuchElementException::new); assertThatItemHasSiblings(item, 2L); group = groups.get(1); assertThat(group.getItems()).isNotEmpty().hasSize(1); - item = group.findByTargetId(2L).orElseThrow(); + item = group.findByTargetId(2L).orElseThrow(NoSuchElementException::new); assertThatItemHasSiblings(item, 1L); group = groups.get(2); assertThat(group.getItems()).isNotEmpty().hasSize(1); - item = group.findByTargetId(1L).orElseThrow(); + item = group.findByTargetId(1L).orElseThrow(NoSuchElementException::new); assertThatItemHasNoSiblings(item); } private void assertThatItemHasNoSiblings(Item item) { - assertThat(item.getSiblings()).isEmpty(); + assertThat(item.getSiblings()).isNotNull().isEmpty(); } private void assertThatItemHasSiblings(Item item, Long... siblingsIds) { assertThat(item.getSiblings()) + .isNotNull() .extracting(Microservice::getId) .containsExactlyInAnyOrder(siblingsIds); } diff --git a/src/test/java/com/github/microcatalog/service/custom/ReleasePathCustomServiceTest.java b/src/test/java/com/github/microcatalog/service/custom/ReleasePathCustomServiceTest.java index 3d3396a..c54411d 100644 --- a/src/test/java/com/github/microcatalog/service/custom/ReleasePathCustomServiceTest.java +++ b/src/test/java/com/github/microcatalog/service/custom/ReleasePathCustomServiceTest.java @@ -15,6 +15,7 @@ import org.springframework.boot.test.mock.mockito.MockBean; import java.util.List; +import java.util.NoSuchElementException; import java.util.Optional; import static org.assertj.core.api.Assertions.*; @@ -92,29 +93,29 @@ void getReleasePath_NoCycles_Success() { ReleaseGroup group = groups.get(0); assertThat(group.getSteps()).isNotEmpty().hasSize(2); - ReleaseStep step = group.findByTargetId(5L).orElseThrow(); + ReleaseStep step = group.findByTargetId(5L).orElseThrow(NoSuchElementException::new); assertThat(step.getParentWorkItems()).extracting(Microservice::getId).containsExactlyInAnyOrder(4L, 7L); - step = group.findByTargetId(8L).orElseThrow(); + step = group.findByTargetId(8L).orElseThrow(NoSuchElementException::new); assertThat(step.getParentWorkItems()).extracting(Microservice::getId).containsExactlyInAnyOrder(4L); group = groups.get(1); assertThat(group.getSteps()).isNotEmpty().hasSize(1); - step = group.findByTargetId(7L).orElseThrow(); + step = group.findByTargetId(7L).orElseThrow(NoSuchElementException::new); assertThat(step.getParentWorkItems()).extracting(Microservice::getId).containsExactlyInAnyOrder(4L); group = groups.get(2); assertThat(group.getSteps()).isNotEmpty().hasSize(1); - step = group.findByTargetId(4L).orElseThrow(); + step = group.findByTargetId(4L).orElseThrow(NoSuchElementException::new); assertThat(step.getParentWorkItems()).extracting(Microservice::getId).containsExactlyInAnyOrder(2L); group = groups.get(3); assertThat(group.getSteps()).isNotEmpty().hasSize(1); - step = group.findByTargetId(2L).orElseThrow(); + step = group.findByTargetId(2L).orElseThrow(NoSuchElementException::new); assertThat(step.getParentWorkItems()).extracting(Microservice::getId).containsExactlyInAnyOrder(1L); group = groups.get(4); assertThat(group.getSteps()).isNotEmpty().hasSize(1); - step = group.findByTargetId(1L).orElseThrow(); + step = group.findByTargetId(1L).orElseThrow(NoSuchElementException::new); assertThat(step.getParentWorkItems()).isEmpty(); } @@ -169,19 +170,19 @@ void getReleasePath_ContainsCyclesInOtherComponent_Success() { ReleaseGroup group = groups.get(0); assertThat(group.getSteps()).isNotEmpty().hasSize(2); - ReleaseStep step = group.findByTargetId(3L).orElseThrow(); + ReleaseStep step = group.findByTargetId(3L).orElseThrow(NoSuchElementException::new); assertThat(step.getParentWorkItems()).extracting(Microservice::getId).containsExactlyInAnyOrder(2L); - step = group.findByTargetId(4L).orElseThrow(); + step = group.findByTargetId(4L).orElseThrow(NoSuchElementException::new); assertThat(step.getParentWorkItems()).extracting(Microservice::getId).containsExactlyInAnyOrder(2L); group = groups.get(1); assertThat(group.getSteps()).isNotEmpty().hasSize(1); - step = group.findByTargetId(2L).orElseThrow(); + step = group.findByTargetId(2L).orElseThrow(NoSuchElementException::new); assertThat(step.getParentWorkItems()).extracting(Microservice::getId).containsExactlyInAnyOrder(1L); group = groups.get(2); assertThat(group.getSteps()).isNotEmpty().hasSize(1); - step = group.findByTargetId(1L).orElseThrow(); + step = group.findByTargetId(1L).orElseThrow(NoSuchElementException::new); assertThat(step.getParentWorkItems()).isEmpty(); } }