Skip to content

Commit

Permalink
Unit tests fix #79
Browse files Browse the repository at this point in the history
  • Loading branch information
tillias committed Nov 1, 2020
1 parent ea86a00 commit 6fc2744
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 23 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<properties>
<!-- Build properties -->
<maven.version>3.3.9</maven.version>
<java.version>10</java.version>
<java.version>1.8</java.version>
<node.version>v12.16.1</node.version>
<npm.version>6.14.5</npm.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -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();
}
}

0 comments on commit 6fc2744

Please sign in to comment.