Upgrade JUnit from 4.13 to Junit Jupiter 5.6.1 (#61)

* Upgrade JUnit from 4.13 to Junit Jupiter 5.6.1

* Update CHANGELOG
This commit is contained in:
Paul Campbell 2020-03-22 21:49:05 +00:00 committed by GitHub
parent 82f0c25b1d
commit 3cb432a3ab
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 270 additions and 248 deletions

View file

@ -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)

View file

@ -17,6 +17,8 @@
<properties>
<java.version>1.8</java.version>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
<tiles-maven-plugin.version>2.16</tiles-maven-plugin.version>
<kemitix-maven-tiles.version>2.4.1</kemitix-maven-tiles.version>
<pitest-junit5-plugin.version>0.9</pitest-junit5-plugin.version>
@ -24,7 +26,7 @@
<lombok.version>1.18.12</lombok.version>
<assertj.version>3.15.0</assertj.version>
<trajano-commons-testing.version>2.1.0</trajano-commons-testing.version>
<junit.version>4.13</junit.version>
<junit.version>5.6.1</junit.version>
<hamcrest.version>2.2</hamcrest.version>
<jacoco-class-instruction-covered-ratio>97%</jacoco-class-instruction-covered-ratio>
</properties>
@ -52,8 +54,8 @@
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>

View file

@ -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);
}
}

View file

@ -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;

View file

@ -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<String> 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

View file

@ -1,4 +0,0 @@
package net.kemitix.node;
public interface IsNamedCategory {
}

View file

@ -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);
}
}

View file

@ -1,9 +0,0 @@
package net.kemitix.node;
/**
* Category marker for tests relating to implementations of Node.findInPath(...).
*
* @author Paul Campbell
*/
public interface NodeFindInPathTestsCategory {
}

View file

@ -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<String> 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

View file

@ -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;

View file

@ -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;

View file

@ -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);
}
}