diff --git a/CHANGELOG.org b/CHANGELOG.org index b8ce4a1..5f19b75 100644 --- a/CHANGELOG.org +++ b/CHANGELOG.org @@ -13,12 +13,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ** Changed +- Moved: Node.drawTree to Nodes (#60) +- Pinned pitest-junit5-plugin at 0.9 (#59) - Replace Jenkins with Github Actions (#57) - [checkstyle] suppress npath complexity issues - [coverage] lower requirements - Clean up changelog and readme, and remove external build dependencies (#38) -- Pinned pitest-junit5-plugin at 0.9 (#59) -- Moved: Node.drawTree to Nodes (#60) ** Removed @@ -26,6 +26,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ** Dependencies +- Upgraded JUnit from 4.13 to Junit Jupiter 5.6.1 - Bump kemitix-checkstyle-ruleset from 4.0.1 to 5.4.0 (#59) - Bump kemitix-parent from 5.2.0 to 5.3.0 (#56) - Bump lombok from 1.18.10 to 1.18.12 (#55) diff --git a/pom.xml b/pom.xml index a1cb290..de0d4da 100644 --- a/pom.xml +++ b/pom.xml @@ -17,6 +17,8 @@ 1.8 + ${java.version} + ${java.version} 2.16 2.4.1 0.9 @@ -24,7 +26,7 @@ 1.18.12 3.15.0 2.1.0 - 4.13 + 5.6.1 2.2 97% @@ -52,8 +54,8 @@ provided - junit - junit + org.junit.jupiter + junit-jupiter ${junit.version} test diff --git a/src/test/java/net/kemitix/node/EmptyNodeExceptionTest.java b/src/test/java/net/kemitix/node/EmptyNodeExceptionTest.java index 85b6122..873b695 100644 --- a/src/test/java/net/kemitix/node/EmptyNodeExceptionTest.java +++ b/src/test/java/net/kemitix/node/EmptyNodeExceptionTest.java @@ -1,10 +1,9 @@ package net.kemitix.node; import lombok.val; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests for {@link EmptyNodeException}. @@ -23,7 +22,8 @@ public class EmptyNodeExceptionTest { //when val nodeException = new EmptyNodeException(message); //then - assertThat(nodeException.getMessage(), is(message)); + assertThat(nodeException.getMessage()) + .isEqualTo(message); } } diff --git a/src/test/java/net/kemitix/node/HeadTailTest.java b/src/test/java/net/kemitix/node/HeadTailTest.java index ab32ba0..fc91686 100644 --- a/src/test/java/net/kemitix/node/HeadTailTest.java +++ b/src/test/java/net/kemitix/node/HeadTailTest.java @@ -1,6 +1,6 @@ package net.kemitix.node; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.Arrays; import java.util.Collections; diff --git a/src/test/java/net/kemitix/node/ImmutableNodeItemTest.java b/src/test/java/net/kemitix/node/ImmutableNodeItemTest.java index 63d3b00..64aaa69 100644 --- a/src/test/java/net/kemitix/node/ImmutableNodeItemTest.java +++ b/src/test/java/net/kemitix/node/ImmutableNodeItemTest.java @@ -2,10 +2,9 @@ package net.kemitix.node; import lombok.val; import org.assertj.core.api.SoftAssertions; -import org.junit.Rule; -import org.junit.Test; -import org.junit.experimental.categories.Category; -import org.junit.rules.ExpectedException; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; import java.util.Arrays; import java.util.Collections; @@ -13,7 +12,7 @@ import java.util.Optional; import java.util.stream.Collectors; import java.util.stream.Stream; -import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.*; /** * Test for {@link ImmutableNodeItem}. @@ -22,18 +21,8 @@ import static org.assertj.core.api.Assertions.assertThat; */ public class ImmutableNodeItemTest { - private static final String IMMUTABLE_OBJECT = "Immutable object"; - - @Rule - public ExpectedException exception = ExpectedException.none(); - private Node immutableNode; - private void expectImmutableException() { - exception.expect(UnsupportedOperationException.class); - exception.expectMessage(IMMUTABLE_OBJECT); - } - @Test public void canCreateAnEmptyAndUnnamedNode() { //when @@ -53,9 +42,11 @@ public class ImmutableNodeItemTest { public void shouldThrowExceptionOnSetName() { //given immutableNode = Nodes.asImmutable(Nodes.unnamedRoot(null)); - expectImmutableException(); //when - immutableNode.setName("named"); + assertThatExceptionOfType(UnsupportedOperationException.class) + .isThrownBy(() -> + immutableNode.setName("named")) + .withMessage("Immutable object"); } @Test @@ -104,46 +95,54 @@ public class ImmutableNodeItemTest { public void shouldNotBeAbleToAddChildToImmutableTree() { //given immutableNode = Nodes.asImmutable(Nodes.unnamedRoot("root")); - expectImmutableException(); //when - Nodes.unnamedChild("child", immutableNode); + assertThatExceptionOfType(UnsupportedOperationException.class) + .isThrownBy(() -> + Nodes.unnamedChild("child", immutableNode)) + .withMessage("Immutable object"); } @Test public void shouldThrowExceptionWhenSetParent() { //given immutableNode = Nodes.asImmutable(Nodes.unnamedRoot("subject")); - expectImmutableException(); //when - immutableNode.setParent(Nodes.unnamedRoot("child")); + assertThatExceptionOfType(UnsupportedOperationException.class) + .isThrownBy(() -> + immutableNode.setParent(Nodes.unnamedRoot("child"))) + .withMessage("Immutable object"); } @Test public void shouldThrowExceptionWhenAddingChild() { //given immutableNode = Nodes.asImmutable(Nodes.unnamedRoot("subject")); - expectImmutableException(); //when - immutableNode.addChild(Nodes.unnamedRoot("child")); + assertThatExceptionOfType(UnsupportedOperationException.class) + .isThrownBy(() -> + immutableNode.addChild(Nodes.unnamedRoot("child"))) + .withMessage("Immutable object"); } - /** - * Test that we can walk a tree to the target node. - */ - @Test - @Category(NodeFindInPathTestsCategory.class) - public void shouldWalkTreeToNode() { - //given - val root = Nodes.unnamedRoot("root"); - Nodes.namedChild("child", "child", Nodes.unnamedChild("parent", root)); - immutableNode = Nodes.asImmutable(root); - //when - val result = immutableNode.findInPath(Arrays.asList("parent", "child")); - //then - assertThat(result.isPresent()).isTrue(); - if (result.isPresent()) { - assertThat(result.get() - .getName()).isEqualTo("child"); + @Nested + @DisplayName("findInPath") + public class FindInPathTests { + + /** + * Test that we can walk a tree to the target node. + */ + @Test + public void shouldWalkTreeToNode() { + //given + val root = Nodes.unnamedRoot("root"); + Nodes.namedChild("child", "child", Nodes.unnamedChild("parent", root)); + immutableNode = Nodes.asImmutable(root); + //when + val result = immutableNode.findInPath(Arrays.asList("parent", "child")); + //then + assertThat(result.isPresent()).isTrue(); + result.map(value -> + assertThat(value.getName()).isEqualTo("child")); } } @@ -152,7 +151,6 @@ public class ImmutableNodeItemTest { * doesn't exist. */ @Test - @Category(NodeFindInPathTestsCategory.class) public void shouldNotFindNonExistentChildNode() { //given val root = Nodes.unnamedRoot("root"); @@ -168,14 +166,14 @@ public class ImmutableNodeItemTest { * Test that when we pass null we get an exception. */ @Test - @Category(NodeFindInPathTestsCategory.class) public void shouldThrowNEWhenWalkTreeNull() { //given immutableNode = Nodes.asImmutable(Nodes.unnamedRoot("subject")); - exception.expect(NullPointerException.class); - exception.expectMessage("path"); //when - immutableNode.findInPath(null); + assertThatNullPointerException() + .isThrownBy(() -> + immutableNode.findInPath(null)) + .withMessageContaining("path"); } /** @@ -183,7 +181,6 @@ public class ImmutableNodeItemTest { * a result. */ @Test - @Category(NodeFindInPathTestsCategory.class) public void shouldReturnEmptyForEmptyWalkTreePath() { //given immutableNode = Nodes.asImmutable(Nodes.unnamedRoot("subject")); @@ -218,10 +215,11 @@ public class ImmutableNodeItemTest { public void getChildShouldThrowNPEWhenThereIsNoChild() { //given immutableNode = Nodes.asImmutable(Nodes.unnamedRoot("data")); - exception.expect(NullPointerException.class); - exception.expectMessage("child"); //when - immutableNode.findChild(null); + assertThatNullPointerException() + .isThrownBy(() -> + immutableNode.findChild(null)) + .withMessageContaining("child"); } @Test @@ -258,19 +256,22 @@ public class ImmutableNodeItemTest { public void removingParentThrowsException() { //given immutableNode = Nodes.asImmutable(Nodes.unnamedRoot(null)); - expectImmutableException(); //when - immutableNode.removeParent(); + assertThatExceptionOfType(UnsupportedOperationException.class) + .isThrownBy(() -> + immutableNode.removeParent()) + .withMessage("Immutable object"); } @Test public void findChildNamedShouldThrowNPEWhenNameIsNull() { //given - exception.expect(NullPointerException.class); - exception.expectMessage("name"); immutableNode = Nodes.asImmutable(Nodes.unnamedRoot(null)); //when - immutableNode.findChildByName(null); + assertThatNullPointerException() + .isThrownBy(() -> + immutableNode.findChildByName(null)) + .withMessageContaining("name"); } @Test @@ -301,27 +302,33 @@ public class ImmutableNodeItemTest { public void removeChildThrowsExceptions() { //given immutableNode = Nodes.asImmutable(Nodes.unnamedRoot(null)); - expectImmutableException(); //then - immutableNode.removeChild(null); + assertThatExceptionOfType(UnsupportedOperationException.class) + .isThrownBy(() -> + immutableNode.removeChild(null)) + .withMessage("Immutable object"); } @Test public void setDataShouldThrowException() { //given immutableNode = Nodes.asImmutable(Nodes.unnamedRoot("initial")); - expectImmutableException(); //when - immutableNode.setData("updated"); + assertThatExceptionOfType(UnsupportedOperationException.class) + .isThrownBy(() -> + immutableNode.setData("updated")) + .withMessage("Immutable object"); } @Test public void createChildThrowsException() { //given immutableNode = Nodes.asImmutable(Nodes.unnamedRoot(null)); - expectImmutableException(); //when - immutableNode.createChild("child data", "child name"); + assertThatExceptionOfType(UnsupportedOperationException.class) + .isThrownBy(() -> + immutableNode.createChild("child data", "child name")) + .withMessage("Immutable object"); } @Test @@ -338,36 +345,43 @@ public class ImmutableNodeItemTest { public void createChildShouldThrowException() { //given immutableNode = Nodes.asImmutable(Nodes.unnamedRoot("")); - expectImmutableException(); //when - immutableNode.createChild("child"); + assertThatExceptionOfType(UnsupportedOperationException.class) + .isThrownBy(() -> + immutableNode.createChild("child")) + .withMessage("Immutable object"); } @Test public void createDescendantLineShouldThrowException() { //given immutableNode = Nodes.asImmutable(Nodes.unnamedRoot("")); - expectImmutableException(); //when - immutableNode.createDescendantLine(Arrays.asList("child", "grandchild")); + assertThatExceptionOfType(UnsupportedOperationException.class) + .isThrownBy(() -> + immutableNode.createDescendantLine(Arrays.asList("child", "grandchild"))) + .withMessage("Immutable object"); } @Test public void insertInPathShouldThrowException() { //given immutableNode = Nodes.asImmutable(Nodes.unnamedRoot("")); - expectImmutableException(); //when - immutableNode.insertInPath(null, ""); + assertThatExceptionOfType(UnsupportedOperationException.class) + .isThrownBy(() -> + immutableNode.insertInPath(null, "")) + .withMessage("Immutable object"); } @Test public void AsImmutableShouldThrowIAEWhenNotRoot() { - //given - exception.expect(IllegalArgumentException.class); - exception.expectMessage("source must be the root node"); - //when - Nodes.asImmutable(Nodes.unnamedChild("child", Nodes.unnamedRoot("root"))); + assertThatExceptionOfType(IllegalArgumentException.class) + .isThrownBy(() -> + Nodes.asImmutable( + Nodes.unnamedChild("child", + Nodes.unnamedRoot("root")))) + .withMessage("source must be the root node"); } @Test diff --git a/src/test/java/net/kemitix/node/IsNamedCategory.java b/src/test/java/net/kemitix/node/IsNamedCategory.java deleted file mode 100644 index 13eeacf..0000000 --- a/src/test/java/net/kemitix/node/IsNamedCategory.java +++ /dev/null @@ -1,4 +0,0 @@ -package net.kemitix.node; - -public interface IsNamedCategory { -} diff --git a/src/test/java/net/kemitix/node/NodeExceptionTest.java b/src/test/java/net/kemitix/node/NodeExceptionTest.java index 2d1422b..def83c7 100644 --- a/src/test/java/net/kemitix/node/NodeExceptionTest.java +++ b/src/test/java/net/kemitix/node/NodeExceptionTest.java @@ -1,10 +1,9 @@ package net.kemitix.node; import lombok.val; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests for {@link NodeException}. @@ -23,7 +22,8 @@ public class NodeExceptionTest { //when val nodeException = new NodeException(message); //then - assertThat(nodeException.getMessage(), is(message)); + assertThat(nodeException.getMessage()) + .isEqualTo(message); } } diff --git a/src/test/java/net/kemitix/node/NodeFindInPathTestsCategory.java b/src/test/java/net/kemitix/node/NodeFindInPathTestsCategory.java deleted file mode 100644 index 979190f..0000000 --- a/src/test/java/net/kemitix/node/NodeFindInPathTestsCategory.java +++ /dev/null @@ -1,9 +0,0 @@ -package net.kemitix.node; - -/** - * Category marker for tests relating to implementations of Node.findInPath(...). - * - * @author Paul Campbell - */ -public interface NodeFindInPathTestsCategory { -} diff --git a/src/test/java/net/kemitix/node/NodeItemTest.java b/src/test/java/net/kemitix/node/NodeItemTest.java index 2fd0194..7aa5158 100644 --- a/src/test/java/net/kemitix/node/NodeItemTest.java +++ b/src/test/java/net/kemitix/node/NodeItemTest.java @@ -2,10 +2,9 @@ package net.kemitix.node; import lombok.val; import org.assertj.core.api.SoftAssertions; -import org.junit.Rule; -import org.junit.Test; -import org.junit.experimental.categories.Category; -import org.junit.rules.ExpectedException; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; import java.util.Arrays; import java.util.Collections; @@ -13,7 +12,7 @@ import java.util.Optional; import java.util.Set; import java.util.stream.Collectors; -import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.*; /** * Test for {@link NodeItem}. @@ -22,9 +21,6 @@ import static org.assertj.core.api.Assertions.assertThat; */ public class NodeItemTest { - @Rule - public ExpectedException exception = ExpectedException.none(); - private Node node; @Test @@ -140,10 +136,11 @@ public class NodeItemTest { //given node = Nodes.unnamedRoot("subject"); val child = Nodes.unnamedChild("child", node); - exception.expect(NodeException.class); - exception.expectMessage("Parent is a descendant"); //when - node.setParent(child); + assertThatExceptionOfType(NodeException.class) + .isThrownBy(() -> + node.setParent(child)) + .withMessage("Parent is a descendant"); } /** @@ -185,10 +182,11 @@ public class NodeItemTest { public void shouldThrowNPEWhenSetParentNull() { //given node = Nodes.unnamedRoot("subject"); - exception.expect(NullPointerException.class); - exception.expectMessage("parent"); //when - node.setParent(null); + assertThatNullPointerException() + .isThrownBy(() -> + node.setParent(null)) + .withMessageContaining("parent"); } /** @@ -199,10 +197,11 @@ public class NodeItemTest { public void setParentShouldThrowNodeExceptionWhenParentIsSelf() { //given node = Nodes.unnamedRoot("subject"); - exception.expect(NodeException.class); - exception.expectMessage("Parent is a descendant"); //when - node.setParent(node); + assertThatExceptionOfType(NodeException.class) + .isThrownBy(() -> + node.setParent(node)) + .withMessage("Parent is a descendant"); } /** @@ -256,10 +255,11 @@ public class NodeItemTest { public void shouldThrowNPEWhenAddingNullAsChild() { //given node = Nodes.unnamedRoot("subject"); - exception.expect(NullPointerException.class); - exception.expectMessage("child"); //when - node.addChild(null); + assertThatNullPointerException() + .isThrownBy(() -> + node.addChild(null)) + .withMessageContaining("child"); } /** @@ -285,10 +285,11 @@ public class NodeItemTest { public void addChildShouldThrowNodeExceptionWhenAddingANodeAsOwnChild() { //given node = Nodes.unnamedRoot("subject"); - exception.expect(NodeException.class); - exception.expectMessage("Child is an ancestor"); //then - node.addChild(node); + assertThatExceptionOfType(NodeException.class) + .isThrownBy(() -> + node.addChild(node)) + .withMessage("Child is an ancestor"); } /** @@ -298,10 +299,11 @@ public class NodeItemTest { public void addChildShouldThrowNodeExceptionWhenAddingSelfAsChild() { //given node = Nodes.unnamedRoot("subject"); - exception.expect(NodeException.class); - exception.expectMessage("Child is an ancestor"); //when - node.addChild(node); + assertThatExceptionOfType(NodeException.class) + .isThrownBy(() -> + node.addChild(node)) + .withMessage("Child is an ancestor"); } /** @@ -313,10 +315,11 @@ public class NodeItemTest { //given val parent = Nodes.unnamedRoot("parent"); node = Nodes.unnamedChild("subject", parent); - exception.expect(NodeException.class); - exception.expectMessage("Child is an ancestor"); //when - node.addChild(parent); + assertThatExceptionOfType(NodeException.class) + .isThrownBy(() -> + node.addChild(parent)) + .withMessage("Child is an ancestor"); } /** @@ -329,10 +332,11 @@ public class NodeItemTest { val grandParent = Nodes.unnamedRoot("grandparent"); val parent = Nodes.unnamedChild("parent", grandParent); node = Nodes.unnamedChild("subject", parent); - exception.expect(NodeException.class); - exception.expectMessage("Child is an ancestor"); //when - node.addChild(grandParent); + assertThatExceptionOfType(NodeException.class) + .isThrownBy(() -> + node.addChild(grandParent)) + .withMessage("Child is an ancestor"); } /** @@ -347,82 +351,84 @@ public class NodeItemTest { node.addChild(child); //then assertThat(child.findParent()).as("when a node is added as a child, the child has the node as " + "its parent") - .contains(node); + .contains(node); } - /** - * Test that we can walk a tree to the target node. - */ - @Test - @Category(NodeFindInPathTestsCategory.class) - public void shouldWalkTreeToNode() { - //given - val grandparent = "grandparent"; - val grandParentNode = Nodes.unnamedRoot(grandparent); - val parent = "parent"; - val parentNode = Nodes.unnamedChild(parent, grandParentNode); - val subject = "subject"; - node = Nodes.unnamedChild(subject, parentNode); - //when - val result = grandParentNode.findInPath( - Arrays.asList(parent, subject)); - //then - assertThat(result.isPresent()) - .as("when we walk the tree to a node it is found") - .isTrue(); - result.ifPresent( - stringNode -> - assertThat(stringNode) - .as("when we walk the tree to a node we find the correct node") - .isSameAs(node)); - } + @Nested + @DisplayName("findInPath") + public class FindInPathTests { - /** - * Test that we get an empty {@link Optional} when walking a path that - * doesn't exist. - */ - @Test - @Category(NodeFindInPathTestsCategory.class) - public void shouldNotFindNonExistentChildNode() { - //given - val parent = "parent"; - val parentNode = Nodes.unnamedRoot(parent); - val subject = "subject"; - node = Nodes.unnamedChild(subject, parentNode); - //when - val result = parentNode.findInPath(Arrays.asList(subject, "no child")); - //then - assertThat(result.isPresent()).as("when we walk the tree to a node that doesn't exists, nothing" + " is found") - .isFalse(); - } + /** + * Test that we can walk a tree to the target node. + */ + @Test + public void shouldWalkTreeToNode() { + //given + val grandparent = "grandparent"; + val grandParentNode = Nodes.unnamedRoot(grandparent); + val parent = "parent"; + val parentNode = Nodes.unnamedChild(parent, grandParentNode); + val subject = "subject"; + node = Nodes.unnamedChild(subject, parentNode); + //when + val result = grandParentNode.findInPath( + Arrays.asList(parent, subject)); + //then + assertThat(result.isPresent()) + .as("when we walk the tree to a node it is found") + .isTrue(); + result.ifPresent( + stringNode -> + assertThat(stringNode) + .as("when we walk the tree to a node we find the correct node") + .isSameAs(node)); + } - /** - * Test that when we pass null we get an exception. - */ - @Test - @Category(NodeFindInPathTestsCategory.class) - public void shouldThrowNPEWhenWalkTreeNull() { - //given - node = Nodes.unnamedRoot("subject"); - exception.expect(NullPointerException.class); - exception.expectMessage("path"); - //when - node.findInPath(null); - } + /** + * Test that we get an empty {@link Optional} when walking a path that + * doesn't exist. + */ + @Test + public void shouldNotFindNonExistentChildNode() { + //given + val parent = "parent"; + val parentNode = Nodes.unnamedRoot(parent); + val subject = "subject"; + node = Nodes.unnamedChild(subject, parentNode); + //when + val result = parentNode.findInPath(Arrays.asList(subject, "no child")); + //then + assertThat(result.isPresent()).as("when we walk the tree to a node that doesn't exists, nothing" + " is found") + .isFalse(); + } - /** - * Test that when we pass an empty path we get and empty {@link Optional} as - * a result. - */ - @Test - @Category(NodeFindInPathTestsCategory.class) - public void shouldReturnEmptyForEmptyWalkTreePath() { - //given - node = Nodes.unnamedRoot("subject"); - //when - val result = node.findInPath(Collections.emptyList()); - //then - assertThat(result).isEmpty(); + /** + * Test that when we pass null we get an exception. + */ + @Test + public void shouldThrowNPEWhenWalkTreeNull() { + //given + node = Nodes.unnamedRoot("subject"); + //when + assertThatNullPointerException() + .isThrownBy(() -> + node.findInPath(null)) + .withMessageContaining("path"); + } + + /** + * Test that when we pass an empty path we get and empty {@link Optional} as + * a result. + */ + @Test + public void shouldReturnEmptyForEmptyWalkTreePath() { + //given + node = Nodes.unnamedRoot("subject"); + //when + val result = node.findInPath(Collections.emptyList()); + //then + assertThat(result).isEmpty(); + } } /** @@ -472,10 +478,11 @@ public class NodeItemTest { public void createDescendantLineShouldThrowNPEWhenDescendantsAreNull() { //given node = Nodes.unnamedRoot("subject"); - exception.expect(NullPointerException.class); - exception.expectMessage("descendants"); //when - node.createDescendantLine(null); + assertThatNullPointerException() + .isThrownBy(() -> + node.createDescendantLine(null)) + .withMessageContaining("descendants"); } /** @@ -519,10 +526,11 @@ public class NodeItemTest { public void getChildShouldThrowNPEWhenThereIsNoChild() { //given node = Nodes.unnamedRoot("data"); - exception.expect(NullPointerException.class); - exception.expectMessage("child"); //when - node.findChild(null); + assertThatNullPointerException() + .isThrownBy(() -> + node.findChild(null)) + .withMessageContaining("child"); } /** @@ -554,10 +562,11 @@ public class NodeItemTest { public void createChildShouldThrowNPEWhenChildIsNull() { //given node = Nodes.unnamedRoot("subject"); - exception.expect(NullPointerException.class); - exception.expectMessage("child"); //when - node.createChild(null); + assertThatNullPointerException() + .isThrownBy(() -> + node.createChild(null)) + .withMessageContaining("child"); } @Test @@ -573,10 +582,11 @@ public class NodeItemTest { val alpha = Nodes.namedRoot("alpha data", "alpha"); node.addChild(alpha); val beta = Nodes.namedRoot("beta data", "alpha"); - exception.expect(NodeException.class); - exception.expectMessage("Node with that name already exists here"); //when - node.addChild(beta); + assertThatExceptionOfType(NodeException.class) + .isThrownBy(() -> + node.addChild(beta)) + .withMessage("Node with that name already exists here"); } @Test @@ -681,8 +691,6 @@ public class NodeItemTest { @Test public void placeNodeInTreeWhereNonEmptyNodeWithSameNameExists() { //given - exception.expect(NodeException.class); - exception.expectMessage("A non-empty node named 'grandchild' already exists here"); node = Nodes.unnamedRoot(null); val child = Nodes.namedChild("child data", "child", node); Nodes.namedChild("data", "grandchild", child); @@ -690,7 +698,14 @@ public class NodeItemTest { // only grandchild has data //when // attempt to add another node called 'grandchild' to 'child' - node.insertInPath(Nodes.namedRoot("cuckoo", "grandchild"), "child"); + assertThatExceptionOfType(NodeException.class) + .isThrownBy(() -> + node.insertInPath( + Nodes.namedRoot( + "cuckoo", + "grandchild"), + "child")) + .withMessage("A non-empty node named 'grandchild' already exists here"); } @Test @@ -730,38 +745,41 @@ public class NodeItemTest { @Test public void findChildNamedShouldThrowNPEWhenNameIsNull() { //given - exception.expect(NullPointerException.class); - exception.expectMessage("name"); node = Nodes.unnamedRoot(null); //when - node.findChildByName(null); + assertThatNullPointerException() + .isThrownBy(() -> + node.findChildByName(null)) + .withMessageContaining("name"); } - @Test - @Category(IsNamedCategory.class) - public void isNamedNull() { - //given - node = Nodes.namedRoot(null, null); - //then - assertThat(node.isNamed()).isFalse(); - } + @Nested + @DisplayName("isNamed") + public class IsNamedTests { - @Test - @Category(IsNamedCategory.class) - public void isNamedEmpty() { - //given - node = Nodes.namedRoot(null, ""); - //then - assertThat(node.isNamed()).isFalse(); - } + @Test + public void isNamedNull() { + //given + node = Nodes.namedRoot(null, null); + //then + assertThat(node.isNamed()).isFalse(); + } - @Test - @Category(IsNamedCategory.class) - public void isNamedNamed() { - //given - node = Nodes.namedRoot(null, "named"); - //then - assertThat(node.isNamed()).isTrue(); + @Test + public void isNamedEmpty() { + //given + node = Nodes.namedRoot(null, ""); + //then + assertThat(node.isNamed()).isFalse(); + } + + @Test + public void isNamedNamed() { + //given + node = Nodes.namedRoot(null, "named"); + //then + assertThat(node.isNamed()).isTrue(); + } } @Test diff --git a/src/test/java/net/kemitix/node/NodeTreeDrawTest.java b/src/test/java/net/kemitix/node/NodeTreeDrawTest.java index 33c6c2b..b997b77 100644 --- a/src/test/java/net/kemitix/node/NodeTreeDrawTest.java +++ b/src/test/java/net/kemitix/node/NodeTreeDrawTest.java @@ -1,7 +1,7 @@ package net.kemitix.node; import lombok.val; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; diff --git a/src/test/java/net/kemitix/node/NodesTest.java b/src/test/java/net/kemitix/node/NodesTest.java index 5251587..470c6f2 100644 --- a/src/test/java/net/kemitix/node/NodesTest.java +++ b/src/test/java/net/kemitix/node/NodesTest.java @@ -2,7 +2,7 @@ package net.kemitix.node; import lombok.val; import org.assertj.core.api.SoftAssertions; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static net.trajano.commons.testing.UtilityClassTestUtil .assertUtilityClassWellDefined; diff --git a/src/test/java/net/kemitix/node/OrphanedNodeExceptionTest.java b/src/test/java/net/kemitix/node/OrphanedNodeExceptionTest.java index a942219..f487a37 100644 --- a/src/test/java/net/kemitix/node/OrphanedNodeExceptionTest.java +++ b/src/test/java/net/kemitix/node/OrphanedNodeExceptionTest.java @@ -1,10 +1,9 @@ package net.kemitix.node; import lombok.val; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests for {@link OrphanedNodeException}. @@ -23,7 +22,8 @@ public class OrphanedNodeExceptionTest { //when val nodeException = new OrphanedNodeException(message); //then - assertThat(nodeException.getMessage(), is(message)); + assertThat(nodeException.getMessage()) + .isEqualTo(message); } }