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:
parent
82f0c25b1d
commit
3cb432a3ab
12 changed files with 270 additions and 248 deletions
|
@ -13,12 +13,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
|
|
||||||
** Changed
|
** Changed
|
||||||
|
|
||||||
|
- Moved: Node.drawTree to Nodes (#60)
|
||||||
|
- Pinned pitest-junit5-plugin at 0.9 (#59)
|
||||||
- Replace Jenkins with Github Actions (#57)
|
- Replace Jenkins with Github Actions (#57)
|
||||||
- [checkstyle] suppress npath complexity issues
|
- [checkstyle] suppress npath complexity issues
|
||||||
- [coverage] lower requirements
|
- [coverage] lower requirements
|
||||||
- Clean up changelog and readme, and remove external build dependencies (#38)
|
- 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
|
** Removed
|
||||||
|
|
||||||
|
@ -26,6 +26,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
|
|
||||||
** Dependencies
|
** 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-checkstyle-ruleset from 4.0.1 to 5.4.0 (#59)
|
||||||
- Bump kemitix-parent from 5.2.0 to 5.3.0 (#56)
|
- Bump kemitix-parent from 5.2.0 to 5.3.0 (#56)
|
||||||
- Bump lombok from 1.18.10 to 1.18.12 (#55)
|
- Bump lombok from 1.18.10 to 1.18.12 (#55)
|
||||||
|
|
8
pom.xml
8
pom.xml
|
@ -17,6 +17,8 @@
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<java.version>1.8</java.version>
|
<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>
|
<tiles-maven-plugin.version>2.16</tiles-maven-plugin.version>
|
||||||
<kemitix-maven-tiles.version>2.4.1</kemitix-maven-tiles.version>
|
<kemitix-maven-tiles.version>2.4.1</kemitix-maven-tiles.version>
|
||||||
<pitest-junit5-plugin.version>0.9</pitest-junit5-plugin.version>
|
<pitest-junit5-plugin.version>0.9</pitest-junit5-plugin.version>
|
||||||
|
@ -24,7 +26,7 @@
|
||||||
<lombok.version>1.18.12</lombok.version>
|
<lombok.version>1.18.12</lombok.version>
|
||||||
<assertj.version>3.15.0</assertj.version>
|
<assertj.version>3.15.0</assertj.version>
|
||||||
<trajano-commons-testing.version>2.1.0</trajano-commons-testing.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>
|
<hamcrest.version>2.2</hamcrest.version>
|
||||||
<jacoco-class-instruction-covered-ratio>97%</jacoco-class-instruction-covered-ratio>
|
<jacoco-class-instruction-covered-ratio>97%</jacoco-class-instruction-covered-ratio>
|
||||||
</properties>
|
</properties>
|
||||||
|
@ -52,8 +54,8 @@
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>org.junit.jupiter</groupId>
|
||||||
<artifactId>junit</artifactId>
|
<artifactId>junit-jupiter</artifactId>
|
||||||
<version>${junit.version}</version>
|
<version>${junit.version}</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
package net.kemitix.node;
|
package net.kemitix.node;
|
||||||
|
|
||||||
import lombok.val;
|
import lombok.val;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.hamcrest.CoreMatchers.is;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.junit.Assert.assertThat;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for {@link EmptyNodeException}.
|
* Tests for {@link EmptyNodeException}.
|
||||||
|
@ -23,7 +22,8 @@ public class EmptyNodeExceptionTest {
|
||||||
//when
|
//when
|
||||||
val nodeException = new EmptyNodeException(message);
|
val nodeException = new EmptyNodeException(message);
|
||||||
//then
|
//then
|
||||||
assertThat(nodeException.getMessage(), is(message));
|
assertThat(nodeException.getMessage())
|
||||||
|
.isEqualTo(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package net.kemitix.node;
|
package net.kemitix.node;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
|
@ -2,10 +2,9 @@ package net.kemitix.node;
|
||||||
|
|
||||||
import lombok.val;
|
import lombok.val;
|
||||||
import org.assertj.core.api.SoftAssertions;
|
import org.assertj.core.api.SoftAssertions;
|
||||||
import org.junit.Rule;
|
import org.junit.jupiter.api.DisplayName;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Nested;
|
||||||
import org.junit.experimental.categories.Category;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
@ -13,7 +12,7 @@ import java.util.Optional;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test for {@link ImmutableNodeItem}.
|
* Test for {@link ImmutableNodeItem}.
|
||||||
|
@ -22,18 +21,8 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
*/
|
*/
|
||||||
public class ImmutableNodeItemTest {
|
public class ImmutableNodeItemTest {
|
||||||
|
|
||||||
private static final String IMMUTABLE_OBJECT = "Immutable object";
|
|
||||||
|
|
||||||
@Rule
|
|
||||||
public ExpectedException exception = ExpectedException.none();
|
|
||||||
|
|
||||||
private Node<String> immutableNode;
|
private Node<String> immutableNode;
|
||||||
|
|
||||||
private void expectImmutableException() {
|
|
||||||
exception.expect(UnsupportedOperationException.class);
|
|
||||||
exception.expectMessage(IMMUTABLE_OBJECT);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void canCreateAnEmptyAndUnnamedNode() {
|
public void canCreateAnEmptyAndUnnamedNode() {
|
||||||
//when
|
//when
|
||||||
|
@ -53,9 +42,11 @@ public class ImmutableNodeItemTest {
|
||||||
public void shouldThrowExceptionOnSetName() {
|
public void shouldThrowExceptionOnSetName() {
|
||||||
//given
|
//given
|
||||||
immutableNode = Nodes.asImmutable(Nodes.unnamedRoot(null));
|
immutableNode = Nodes.asImmutable(Nodes.unnamedRoot(null));
|
||||||
expectImmutableException();
|
|
||||||
//when
|
//when
|
||||||
immutableNode.setName("named");
|
assertThatExceptionOfType(UnsupportedOperationException.class)
|
||||||
|
.isThrownBy(() ->
|
||||||
|
immutableNode.setName("named"))
|
||||||
|
.withMessage("Immutable object");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -104,34 +95,43 @@ public class ImmutableNodeItemTest {
|
||||||
public void shouldNotBeAbleToAddChildToImmutableTree() {
|
public void shouldNotBeAbleToAddChildToImmutableTree() {
|
||||||
//given
|
//given
|
||||||
immutableNode = Nodes.asImmutable(Nodes.unnamedRoot("root"));
|
immutableNode = Nodes.asImmutable(Nodes.unnamedRoot("root"));
|
||||||
expectImmutableException();
|
|
||||||
//when
|
//when
|
||||||
Nodes.unnamedChild("child", immutableNode);
|
assertThatExceptionOfType(UnsupportedOperationException.class)
|
||||||
|
.isThrownBy(() ->
|
||||||
|
Nodes.unnamedChild("child", immutableNode))
|
||||||
|
.withMessage("Immutable object");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldThrowExceptionWhenSetParent() {
|
public void shouldThrowExceptionWhenSetParent() {
|
||||||
//given
|
//given
|
||||||
immutableNode = Nodes.asImmutable(Nodes.unnamedRoot("subject"));
|
immutableNode = Nodes.asImmutable(Nodes.unnamedRoot("subject"));
|
||||||
expectImmutableException();
|
|
||||||
//when
|
//when
|
||||||
immutableNode.setParent(Nodes.unnamedRoot("child"));
|
assertThatExceptionOfType(UnsupportedOperationException.class)
|
||||||
|
.isThrownBy(() ->
|
||||||
|
immutableNode.setParent(Nodes.unnamedRoot("child")))
|
||||||
|
.withMessage("Immutable object");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldThrowExceptionWhenAddingChild() {
|
public void shouldThrowExceptionWhenAddingChild() {
|
||||||
//given
|
//given
|
||||||
immutableNode = Nodes.asImmutable(Nodes.unnamedRoot("subject"));
|
immutableNode = Nodes.asImmutable(Nodes.unnamedRoot("subject"));
|
||||||
expectImmutableException();
|
|
||||||
//when
|
//when
|
||||||
immutableNode.addChild(Nodes.unnamedRoot("child"));
|
assertThatExceptionOfType(UnsupportedOperationException.class)
|
||||||
|
.isThrownBy(() ->
|
||||||
|
immutableNode.addChild(Nodes.unnamedRoot("child")))
|
||||||
|
.withMessage("Immutable object");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nested
|
||||||
|
@DisplayName("findInPath")
|
||||||
|
public class FindInPathTests {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test that we can walk a tree to the target node.
|
* Test that we can walk a tree to the target node.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
@Category(NodeFindInPathTestsCategory.class)
|
|
||||||
public void shouldWalkTreeToNode() {
|
public void shouldWalkTreeToNode() {
|
||||||
//given
|
//given
|
||||||
val root = Nodes.unnamedRoot("root");
|
val root = Nodes.unnamedRoot("root");
|
||||||
|
@ -141,9 +141,8 @@ public class ImmutableNodeItemTest {
|
||||||
val result = immutableNode.findInPath(Arrays.asList("parent", "child"));
|
val result = immutableNode.findInPath(Arrays.asList("parent", "child"));
|
||||||
//then
|
//then
|
||||||
assertThat(result.isPresent()).isTrue();
|
assertThat(result.isPresent()).isTrue();
|
||||||
if (result.isPresent()) {
|
result.map(value ->
|
||||||
assertThat(result.get()
|
assertThat(value.getName()).isEqualTo("child"));
|
||||||
.getName()).isEqualTo("child");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -152,7 +151,6 @@ public class ImmutableNodeItemTest {
|
||||||
* doesn't exist.
|
* doesn't exist.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
@Category(NodeFindInPathTestsCategory.class)
|
|
||||||
public void shouldNotFindNonExistentChildNode() {
|
public void shouldNotFindNonExistentChildNode() {
|
||||||
//given
|
//given
|
||||||
val root = Nodes.unnamedRoot("root");
|
val root = Nodes.unnamedRoot("root");
|
||||||
|
@ -168,14 +166,14 @@ public class ImmutableNodeItemTest {
|
||||||
* Test that when we pass null we get an exception.
|
* Test that when we pass null we get an exception.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
@Category(NodeFindInPathTestsCategory.class)
|
|
||||||
public void shouldThrowNEWhenWalkTreeNull() {
|
public void shouldThrowNEWhenWalkTreeNull() {
|
||||||
//given
|
//given
|
||||||
immutableNode = Nodes.asImmutable(Nodes.unnamedRoot("subject"));
|
immutableNode = Nodes.asImmutable(Nodes.unnamedRoot("subject"));
|
||||||
exception.expect(NullPointerException.class);
|
|
||||||
exception.expectMessage("path");
|
|
||||||
//when
|
//when
|
||||||
immutableNode.findInPath(null);
|
assertThatNullPointerException()
|
||||||
|
.isThrownBy(() ->
|
||||||
|
immutableNode.findInPath(null))
|
||||||
|
.withMessageContaining("path");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -183,7 +181,6 @@ public class ImmutableNodeItemTest {
|
||||||
* a result.
|
* a result.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
@Category(NodeFindInPathTestsCategory.class)
|
|
||||||
public void shouldReturnEmptyForEmptyWalkTreePath() {
|
public void shouldReturnEmptyForEmptyWalkTreePath() {
|
||||||
//given
|
//given
|
||||||
immutableNode = Nodes.asImmutable(Nodes.unnamedRoot("subject"));
|
immutableNode = Nodes.asImmutable(Nodes.unnamedRoot("subject"));
|
||||||
|
@ -218,10 +215,11 @@ public class ImmutableNodeItemTest {
|
||||||
public void getChildShouldThrowNPEWhenThereIsNoChild() {
|
public void getChildShouldThrowNPEWhenThereIsNoChild() {
|
||||||
//given
|
//given
|
||||||
immutableNode = Nodes.asImmutable(Nodes.unnamedRoot("data"));
|
immutableNode = Nodes.asImmutable(Nodes.unnamedRoot("data"));
|
||||||
exception.expect(NullPointerException.class);
|
|
||||||
exception.expectMessage("child");
|
|
||||||
//when
|
//when
|
||||||
immutableNode.findChild(null);
|
assertThatNullPointerException()
|
||||||
|
.isThrownBy(() ->
|
||||||
|
immutableNode.findChild(null))
|
||||||
|
.withMessageContaining("child");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -258,19 +256,22 @@ public class ImmutableNodeItemTest {
|
||||||
public void removingParentThrowsException() {
|
public void removingParentThrowsException() {
|
||||||
//given
|
//given
|
||||||
immutableNode = Nodes.asImmutable(Nodes.unnamedRoot(null));
|
immutableNode = Nodes.asImmutable(Nodes.unnamedRoot(null));
|
||||||
expectImmutableException();
|
|
||||||
//when
|
//when
|
||||||
immutableNode.removeParent();
|
assertThatExceptionOfType(UnsupportedOperationException.class)
|
||||||
|
.isThrownBy(() ->
|
||||||
|
immutableNode.removeParent())
|
||||||
|
.withMessage("Immutable object");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void findChildNamedShouldThrowNPEWhenNameIsNull() {
|
public void findChildNamedShouldThrowNPEWhenNameIsNull() {
|
||||||
//given
|
//given
|
||||||
exception.expect(NullPointerException.class);
|
|
||||||
exception.expectMessage("name");
|
|
||||||
immutableNode = Nodes.asImmutable(Nodes.unnamedRoot(null));
|
immutableNode = Nodes.asImmutable(Nodes.unnamedRoot(null));
|
||||||
//when
|
//when
|
||||||
immutableNode.findChildByName(null);
|
assertThatNullPointerException()
|
||||||
|
.isThrownBy(() ->
|
||||||
|
immutableNode.findChildByName(null))
|
||||||
|
.withMessageContaining("name");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -301,27 +302,33 @@ public class ImmutableNodeItemTest {
|
||||||
public void removeChildThrowsExceptions() {
|
public void removeChildThrowsExceptions() {
|
||||||
//given
|
//given
|
||||||
immutableNode = Nodes.asImmutable(Nodes.unnamedRoot(null));
|
immutableNode = Nodes.asImmutable(Nodes.unnamedRoot(null));
|
||||||
expectImmutableException();
|
|
||||||
//then
|
//then
|
||||||
immutableNode.removeChild(null);
|
assertThatExceptionOfType(UnsupportedOperationException.class)
|
||||||
|
.isThrownBy(() ->
|
||||||
|
immutableNode.removeChild(null))
|
||||||
|
.withMessage("Immutable object");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void setDataShouldThrowException() {
|
public void setDataShouldThrowException() {
|
||||||
//given
|
//given
|
||||||
immutableNode = Nodes.asImmutable(Nodes.unnamedRoot("initial"));
|
immutableNode = Nodes.asImmutable(Nodes.unnamedRoot("initial"));
|
||||||
expectImmutableException();
|
|
||||||
//when
|
//when
|
||||||
immutableNode.setData("updated");
|
assertThatExceptionOfType(UnsupportedOperationException.class)
|
||||||
|
.isThrownBy(() ->
|
||||||
|
immutableNode.setData("updated"))
|
||||||
|
.withMessage("Immutable object");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createChildThrowsException() {
|
public void createChildThrowsException() {
|
||||||
//given
|
//given
|
||||||
immutableNode = Nodes.asImmutable(Nodes.unnamedRoot(null));
|
immutableNode = Nodes.asImmutable(Nodes.unnamedRoot(null));
|
||||||
expectImmutableException();
|
|
||||||
//when
|
//when
|
||||||
immutableNode.createChild("child data", "child name");
|
assertThatExceptionOfType(UnsupportedOperationException.class)
|
||||||
|
.isThrownBy(() ->
|
||||||
|
immutableNode.createChild("child data", "child name"))
|
||||||
|
.withMessage("Immutable object");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -338,36 +345,43 @@ public class ImmutableNodeItemTest {
|
||||||
public void createChildShouldThrowException() {
|
public void createChildShouldThrowException() {
|
||||||
//given
|
//given
|
||||||
immutableNode = Nodes.asImmutable(Nodes.unnamedRoot(""));
|
immutableNode = Nodes.asImmutable(Nodes.unnamedRoot(""));
|
||||||
expectImmutableException();
|
|
||||||
//when
|
//when
|
||||||
immutableNode.createChild("child");
|
assertThatExceptionOfType(UnsupportedOperationException.class)
|
||||||
|
.isThrownBy(() ->
|
||||||
|
immutableNode.createChild("child"))
|
||||||
|
.withMessage("Immutable object");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createDescendantLineShouldThrowException() {
|
public void createDescendantLineShouldThrowException() {
|
||||||
//given
|
//given
|
||||||
immutableNode = Nodes.asImmutable(Nodes.unnamedRoot(""));
|
immutableNode = Nodes.asImmutable(Nodes.unnamedRoot(""));
|
||||||
expectImmutableException();
|
|
||||||
//when
|
//when
|
||||||
immutableNode.createDescendantLine(Arrays.asList("child", "grandchild"));
|
assertThatExceptionOfType(UnsupportedOperationException.class)
|
||||||
|
.isThrownBy(() ->
|
||||||
|
immutableNode.createDescendantLine(Arrays.asList("child", "grandchild")))
|
||||||
|
.withMessage("Immutable object");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void insertInPathShouldThrowException() {
|
public void insertInPathShouldThrowException() {
|
||||||
//given
|
//given
|
||||||
immutableNode = Nodes.asImmutable(Nodes.unnamedRoot(""));
|
immutableNode = Nodes.asImmutable(Nodes.unnamedRoot(""));
|
||||||
expectImmutableException();
|
|
||||||
//when
|
//when
|
||||||
immutableNode.insertInPath(null, "");
|
assertThatExceptionOfType(UnsupportedOperationException.class)
|
||||||
|
.isThrownBy(() ->
|
||||||
|
immutableNode.insertInPath(null, ""))
|
||||||
|
.withMessage("Immutable object");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void AsImmutableShouldThrowIAEWhenNotRoot() {
|
public void AsImmutableShouldThrowIAEWhenNotRoot() {
|
||||||
//given
|
assertThatExceptionOfType(IllegalArgumentException.class)
|
||||||
exception.expect(IllegalArgumentException.class);
|
.isThrownBy(() ->
|
||||||
exception.expectMessage("source must be the root node");
|
Nodes.asImmutable(
|
||||||
//when
|
Nodes.unnamedChild("child",
|
||||||
Nodes.asImmutable(Nodes.unnamedChild("child", Nodes.unnamedRoot("root")));
|
Nodes.unnamedRoot("root"))))
|
||||||
|
.withMessage("source must be the root node");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -1,4 +0,0 @@
|
||||||
package net.kemitix.node;
|
|
||||||
|
|
||||||
public interface IsNamedCategory {
|
|
||||||
}
|
|
|
@ -1,10 +1,9 @@
|
||||||
package net.kemitix.node;
|
package net.kemitix.node;
|
||||||
|
|
||||||
import lombok.val;
|
import lombok.val;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.hamcrest.CoreMatchers.is;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.junit.Assert.assertThat;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for {@link NodeException}.
|
* Tests for {@link NodeException}.
|
||||||
|
@ -23,7 +22,8 @@ public class NodeExceptionTest {
|
||||||
//when
|
//when
|
||||||
val nodeException = new NodeException(message);
|
val nodeException = new NodeException(message);
|
||||||
//then
|
//then
|
||||||
assertThat(nodeException.getMessage(), is(message));
|
assertThat(nodeException.getMessage())
|
||||||
|
.isEqualTo(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +0,0 @@
|
||||||
package net.kemitix.node;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Category marker for tests relating to implementations of Node.findInPath(...).
|
|
||||||
*
|
|
||||||
* @author Paul Campbell
|
|
||||||
*/
|
|
||||||
public interface NodeFindInPathTestsCategory {
|
|
||||||
}
|
|
|
@ -2,10 +2,9 @@ package net.kemitix.node;
|
||||||
|
|
||||||
import lombok.val;
|
import lombok.val;
|
||||||
import org.assertj.core.api.SoftAssertions;
|
import org.assertj.core.api.SoftAssertions;
|
||||||
import org.junit.Rule;
|
import org.junit.jupiter.api.DisplayName;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Nested;
|
||||||
import org.junit.experimental.categories.Category;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.rules.ExpectedException;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
@ -13,7 +12,7 @@ import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test for {@link NodeItem}.
|
* Test for {@link NodeItem}.
|
||||||
|
@ -22,9 +21,6 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
*/
|
*/
|
||||||
public class NodeItemTest {
|
public class NodeItemTest {
|
||||||
|
|
||||||
@Rule
|
|
||||||
public ExpectedException exception = ExpectedException.none();
|
|
||||||
|
|
||||||
private Node<String> node;
|
private Node<String> node;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -140,10 +136,11 @@ public class NodeItemTest {
|
||||||
//given
|
//given
|
||||||
node = Nodes.unnamedRoot("subject");
|
node = Nodes.unnamedRoot("subject");
|
||||||
val child = Nodes.unnamedChild("child", node);
|
val child = Nodes.unnamedChild("child", node);
|
||||||
exception.expect(NodeException.class);
|
|
||||||
exception.expectMessage("Parent is a descendant");
|
|
||||||
//when
|
//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() {
|
public void shouldThrowNPEWhenSetParentNull() {
|
||||||
//given
|
//given
|
||||||
node = Nodes.unnamedRoot("subject");
|
node = Nodes.unnamedRoot("subject");
|
||||||
exception.expect(NullPointerException.class);
|
|
||||||
exception.expectMessage("parent");
|
|
||||||
//when
|
//when
|
||||||
node.setParent(null);
|
assertThatNullPointerException()
|
||||||
|
.isThrownBy(() ->
|
||||||
|
node.setParent(null))
|
||||||
|
.withMessageContaining("parent");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -199,10 +197,11 @@ public class NodeItemTest {
|
||||||
public void setParentShouldThrowNodeExceptionWhenParentIsSelf() {
|
public void setParentShouldThrowNodeExceptionWhenParentIsSelf() {
|
||||||
//given
|
//given
|
||||||
node = Nodes.unnamedRoot("subject");
|
node = Nodes.unnamedRoot("subject");
|
||||||
exception.expect(NodeException.class);
|
|
||||||
exception.expectMessage("Parent is a descendant");
|
|
||||||
//when
|
//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() {
|
public void shouldThrowNPEWhenAddingNullAsChild() {
|
||||||
//given
|
//given
|
||||||
node = Nodes.unnamedRoot("subject");
|
node = Nodes.unnamedRoot("subject");
|
||||||
exception.expect(NullPointerException.class);
|
|
||||||
exception.expectMessage("child");
|
|
||||||
//when
|
//when
|
||||||
node.addChild(null);
|
assertThatNullPointerException()
|
||||||
|
.isThrownBy(() ->
|
||||||
|
node.addChild(null))
|
||||||
|
.withMessageContaining("child");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -285,10 +285,11 @@ public class NodeItemTest {
|
||||||
public void addChildShouldThrowNodeExceptionWhenAddingANodeAsOwnChild() {
|
public void addChildShouldThrowNodeExceptionWhenAddingANodeAsOwnChild() {
|
||||||
//given
|
//given
|
||||||
node = Nodes.unnamedRoot("subject");
|
node = Nodes.unnamedRoot("subject");
|
||||||
exception.expect(NodeException.class);
|
|
||||||
exception.expectMessage("Child is an ancestor");
|
|
||||||
//then
|
//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() {
|
public void addChildShouldThrowNodeExceptionWhenAddingSelfAsChild() {
|
||||||
//given
|
//given
|
||||||
node = Nodes.unnamedRoot("subject");
|
node = Nodes.unnamedRoot("subject");
|
||||||
exception.expect(NodeException.class);
|
|
||||||
exception.expectMessage("Child is an ancestor");
|
|
||||||
//when
|
//when
|
||||||
node.addChild(node);
|
assertThatExceptionOfType(NodeException.class)
|
||||||
|
.isThrownBy(() ->
|
||||||
|
node.addChild(node))
|
||||||
|
.withMessage("Child is an ancestor");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -313,10 +315,11 @@ public class NodeItemTest {
|
||||||
//given
|
//given
|
||||||
val parent = Nodes.unnamedRoot("parent");
|
val parent = Nodes.unnamedRoot("parent");
|
||||||
node = Nodes.unnamedChild("subject", parent);
|
node = Nodes.unnamedChild("subject", parent);
|
||||||
exception.expect(NodeException.class);
|
|
||||||
exception.expectMessage("Child is an ancestor");
|
|
||||||
//when
|
//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 grandParent = Nodes.unnamedRoot("grandparent");
|
||||||
val parent = Nodes.unnamedChild("parent", grandParent);
|
val parent = Nodes.unnamedChild("parent", grandParent);
|
||||||
node = Nodes.unnamedChild("subject", parent);
|
node = Nodes.unnamedChild("subject", parent);
|
||||||
exception.expect(NodeException.class);
|
|
||||||
exception.expectMessage("Child is an ancestor");
|
|
||||||
//when
|
//when
|
||||||
node.addChild(grandParent);
|
assertThatExceptionOfType(NodeException.class)
|
||||||
|
.isThrownBy(() ->
|
||||||
|
node.addChild(grandParent))
|
||||||
|
.withMessage("Child is an ancestor");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -350,11 +354,14 @@ public class NodeItemTest {
|
||||||
.contains(node);
|
.contains(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nested
|
||||||
|
@DisplayName("findInPath")
|
||||||
|
public class FindInPathTests {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test that we can walk a tree to the target node.
|
* Test that we can walk a tree to the target node.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
@Category(NodeFindInPathTestsCategory.class)
|
|
||||||
public void shouldWalkTreeToNode() {
|
public void shouldWalkTreeToNode() {
|
||||||
//given
|
//given
|
||||||
val grandparent = "grandparent";
|
val grandparent = "grandparent";
|
||||||
|
@ -382,7 +389,6 @@ public class NodeItemTest {
|
||||||
* doesn't exist.
|
* doesn't exist.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
@Category(NodeFindInPathTestsCategory.class)
|
|
||||||
public void shouldNotFindNonExistentChildNode() {
|
public void shouldNotFindNonExistentChildNode() {
|
||||||
//given
|
//given
|
||||||
val parent = "parent";
|
val parent = "parent";
|
||||||
|
@ -400,14 +406,14 @@ public class NodeItemTest {
|
||||||
* Test that when we pass null we get an exception.
|
* Test that when we pass null we get an exception.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
@Category(NodeFindInPathTestsCategory.class)
|
|
||||||
public void shouldThrowNPEWhenWalkTreeNull() {
|
public void shouldThrowNPEWhenWalkTreeNull() {
|
||||||
//given
|
//given
|
||||||
node = Nodes.unnamedRoot("subject");
|
node = Nodes.unnamedRoot("subject");
|
||||||
exception.expect(NullPointerException.class);
|
|
||||||
exception.expectMessage("path");
|
|
||||||
//when
|
//when
|
||||||
node.findInPath(null);
|
assertThatNullPointerException()
|
||||||
|
.isThrownBy(() ->
|
||||||
|
node.findInPath(null))
|
||||||
|
.withMessageContaining("path");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -415,7 +421,6 @@ public class NodeItemTest {
|
||||||
* a result.
|
* a result.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
@Category(NodeFindInPathTestsCategory.class)
|
|
||||||
public void shouldReturnEmptyForEmptyWalkTreePath() {
|
public void shouldReturnEmptyForEmptyWalkTreePath() {
|
||||||
//given
|
//given
|
||||||
node = Nodes.unnamedRoot("subject");
|
node = Nodes.unnamedRoot("subject");
|
||||||
|
@ -424,6 +429,7 @@ public class NodeItemTest {
|
||||||
//then
|
//then
|
||||||
assertThat(result).isEmpty();
|
assertThat(result).isEmpty();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test that we can create a chain of descendant nodes.
|
* Test that we can create a chain of descendant nodes.
|
||||||
|
@ -472,10 +478,11 @@ public class NodeItemTest {
|
||||||
public void createDescendantLineShouldThrowNPEWhenDescendantsAreNull() {
|
public void createDescendantLineShouldThrowNPEWhenDescendantsAreNull() {
|
||||||
//given
|
//given
|
||||||
node = Nodes.unnamedRoot("subject");
|
node = Nodes.unnamedRoot("subject");
|
||||||
exception.expect(NullPointerException.class);
|
|
||||||
exception.expectMessage("descendants");
|
|
||||||
//when
|
//when
|
||||||
node.createDescendantLine(null);
|
assertThatNullPointerException()
|
||||||
|
.isThrownBy(() ->
|
||||||
|
node.createDescendantLine(null))
|
||||||
|
.withMessageContaining("descendants");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -519,10 +526,11 @@ public class NodeItemTest {
|
||||||
public void getChildShouldThrowNPEWhenThereIsNoChild() {
|
public void getChildShouldThrowNPEWhenThereIsNoChild() {
|
||||||
//given
|
//given
|
||||||
node = Nodes.unnamedRoot("data");
|
node = Nodes.unnamedRoot("data");
|
||||||
exception.expect(NullPointerException.class);
|
|
||||||
exception.expectMessage("child");
|
|
||||||
//when
|
//when
|
||||||
node.findChild(null);
|
assertThatNullPointerException()
|
||||||
|
.isThrownBy(() ->
|
||||||
|
node.findChild(null))
|
||||||
|
.withMessageContaining("child");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -554,10 +562,11 @@ public class NodeItemTest {
|
||||||
public void createChildShouldThrowNPEWhenChildIsNull() {
|
public void createChildShouldThrowNPEWhenChildIsNull() {
|
||||||
//given
|
//given
|
||||||
node = Nodes.unnamedRoot("subject");
|
node = Nodes.unnamedRoot("subject");
|
||||||
exception.expect(NullPointerException.class);
|
|
||||||
exception.expectMessage("child");
|
|
||||||
//when
|
//when
|
||||||
node.createChild(null);
|
assertThatNullPointerException()
|
||||||
|
.isThrownBy(() ->
|
||||||
|
node.createChild(null))
|
||||||
|
.withMessageContaining("child");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -573,10 +582,11 @@ public class NodeItemTest {
|
||||||
val alpha = Nodes.namedRoot("alpha data", "alpha");
|
val alpha = Nodes.namedRoot("alpha data", "alpha");
|
||||||
node.addChild(alpha);
|
node.addChild(alpha);
|
||||||
val beta = Nodes.namedRoot("beta data", "alpha");
|
val beta = Nodes.namedRoot("beta data", "alpha");
|
||||||
exception.expect(NodeException.class);
|
|
||||||
exception.expectMessage("Node with that name already exists here");
|
|
||||||
//when
|
//when
|
||||||
node.addChild(beta);
|
assertThatExceptionOfType(NodeException.class)
|
||||||
|
.isThrownBy(() ->
|
||||||
|
node.addChild(beta))
|
||||||
|
.withMessage("Node with that name already exists here");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -681,8 +691,6 @@ public class NodeItemTest {
|
||||||
@Test
|
@Test
|
||||||
public void placeNodeInTreeWhereNonEmptyNodeWithSameNameExists() {
|
public void placeNodeInTreeWhereNonEmptyNodeWithSameNameExists() {
|
||||||
//given
|
//given
|
||||||
exception.expect(NodeException.class);
|
|
||||||
exception.expectMessage("A non-empty node named 'grandchild' already exists here");
|
|
||||||
node = Nodes.unnamedRoot(null);
|
node = Nodes.unnamedRoot(null);
|
||||||
val child = Nodes.namedChild("child data", "child", node);
|
val child = Nodes.namedChild("child data", "child", node);
|
||||||
Nodes.namedChild("data", "grandchild", child);
|
Nodes.namedChild("data", "grandchild", child);
|
||||||
|
@ -690,7 +698,14 @@ public class NodeItemTest {
|
||||||
// only grandchild has data
|
// only grandchild has data
|
||||||
//when
|
//when
|
||||||
// attempt to add another node called 'grandchild' to 'child'
|
// 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
|
@Test
|
||||||
|
@ -730,15 +745,19 @@ public class NodeItemTest {
|
||||||
@Test
|
@Test
|
||||||
public void findChildNamedShouldThrowNPEWhenNameIsNull() {
|
public void findChildNamedShouldThrowNPEWhenNameIsNull() {
|
||||||
//given
|
//given
|
||||||
exception.expect(NullPointerException.class);
|
|
||||||
exception.expectMessage("name");
|
|
||||||
node = Nodes.unnamedRoot(null);
|
node = Nodes.unnamedRoot(null);
|
||||||
//when
|
//when
|
||||||
node.findChildByName(null);
|
assertThatNullPointerException()
|
||||||
|
.isThrownBy(() ->
|
||||||
|
node.findChildByName(null))
|
||||||
|
.withMessageContaining("name");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nested
|
||||||
|
@DisplayName("isNamed")
|
||||||
|
public class IsNamedTests {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Category(IsNamedCategory.class)
|
|
||||||
public void isNamedNull() {
|
public void isNamedNull() {
|
||||||
//given
|
//given
|
||||||
node = Nodes.namedRoot(null, null);
|
node = Nodes.namedRoot(null, null);
|
||||||
|
@ -747,7 +766,6 @@ public class NodeItemTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Category(IsNamedCategory.class)
|
|
||||||
public void isNamedEmpty() {
|
public void isNamedEmpty() {
|
||||||
//given
|
//given
|
||||||
node = Nodes.namedRoot(null, "");
|
node = Nodes.namedRoot(null, "");
|
||||||
|
@ -756,13 +774,13 @@ public class NodeItemTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@Category(IsNamedCategory.class)
|
|
||||||
public void isNamedNamed() {
|
public void isNamedNamed() {
|
||||||
//given
|
//given
|
||||||
node = Nodes.namedRoot(null, "named");
|
node = Nodes.namedRoot(null, "named");
|
||||||
//then
|
//then
|
||||||
assertThat(node.isNamed()).isTrue();
|
assertThat(node.isNamed()).isTrue();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package net.kemitix.node;
|
package net.kemitix.node;
|
||||||
|
|
||||||
import lombok.val;
|
import lombok.val;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ package net.kemitix.node;
|
||||||
|
|
||||||
import lombok.val;
|
import lombok.val;
|
||||||
import org.assertj.core.api.SoftAssertions;
|
import org.assertj.core.api.SoftAssertions;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static net.trajano.commons.testing.UtilityClassTestUtil
|
import static net.trajano.commons.testing.UtilityClassTestUtil
|
||||||
.assertUtilityClassWellDefined;
|
.assertUtilityClassWellDefined;
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
package net.kemitix.node;
|
package net.kemitix.node;
|
||||||
|
|
||||||
import lombok.val;
|
import lombok.val;
|
||||||
import org.junit.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import static org.hamcrest.CoreMatchers.is;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.junit.Assert.assertThat;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests for {@link OrphanedNodeException}.
|
* Tests for {@link OrphanedNodeException}.
|
||||||
|
@ -23,7 +22,8 @@ public class OrphanedNodeExceptionTest {
|
||||||
//when
|
//when
|
||||||
val nodeException = new OrphanedNodeException(message);
|
val nodeException = new OrphanedNodeException(message);
|
||||||
//then
|
//then
|
||||||
assertThat(nodeException.getMessage(), is(message));
|
assertThat(nodeException.getMessage())
|
||||||
|
.isEqualTo(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue