commit
c6cc3ec9d9
15 changed files with 502 additions and 183 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -12,3 +12,6 @@
|
||||||
|
|
||||||
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
||||||
hs_err_pid*
|
hs_err_pid*
|
||||||
|
|
||||||
|
/.idea/libraries/
|
||||||
|
/.idea/workspace.xml
|
||||||
|
|
104
.idea/codeStyleSettings.xml
Normal file
104
.idea/codeStyleSettings.xml
Normal file
|
@ -0,0 +1,104 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectCodeStyleSettingsManager">
|
||||||
|
<option name="PER_PROJECT_SETTINGS">
|
||||||
|
<value>
|
||||||
|
<option name="GENERATE_FINAL_LOCALS" value="true" />
|
||||||
|
<option name="GENERATE_FINAL_PARAMETERS" value="true" />
|
||||||
|
<option name="VISIBILITY" value="packageLocal" />
|
||||||
|
<option name="CLASS_COUNT_TO_USE_IMPORT_ON_DEMAND" value="9999" />
|
||||||
|
<option name="NAMES_COUNT_TO_USE_IMPORT_ON_DEMAND" value="9999" />
|
||||||
|
<option name="PACKAGES_TO_USE_IMPORT_ON_DEMAND">
|
||||||
|
<value />
|
||||||
|
</option>
|
||||||
|
<option name="IMPORT_LAYOUT_TABLE">
|
||||||
|
<value>
|
||||||
|
<package name="" withSubpackages="true" static="false" />
|
||||||
|
<emptyLine />
|
||||||
|
<package name="" withSubpackages="true" static="true" />
|
||||||
|
<emptyLine />
|
||||||
|
<package name="java" withSubpackages="true" static="false" />
|
||||||
|
<emptyLine />
|
||||||
|
<package name="javax" withSubpackages="true" static="false" />
|
||||||
|
<emptyLine />
|
||||||
|
<package name="org.springframework" withSubpackages="true" static="false" />
|
||||||
|
<emptyLine />
|
||||||
|
<package name="uk.ac.fife" withSubpackages="true" static="false" />
|
||||||
|
<emptyLine />
|
||||||
|
<package name="net.kemitix" withSubpackages="true" static="false" />
|
||||||
|
</value>
|
||||||
|
</option>
|
||||||
|
<option name="JD_ADD_BLANK_AFTER_PARM_COMMENTS" value="true" />
|
||||||
|
<option name="JD_ADD_BLANK_AFTER_RETURN" value="true" />
|
||||||
|
<option name="WRAP_COMMENTS" value="true" />
|
||||||
|
<JavaCodeStyleSettings>
|
||||||
|
<option name="ANNOTATION_PARAMETER_WRAP" value="1" />
|
||||||
|
</JavaCodeStyleSettings>
|
||||||
|
<XML>
|
||||||
|
<option name="XML_LEGACY_SETTINGS_IMPORTED" value="true" />
|
||||||
|
</XML>
|
||||||
|
<codeStyleSettings language="JAVA">
|
||||||
|
<option name="RIGHT_MARGIN" value="80" />
|
||||||
|
<option name="KEEP_LINE_BREAKS" value="false" />
|
||||||
|
<option name="KEEP_FIRST_COLUMN_COMMENT" value="false" />
|
||||||
|
<option name="KEEP_CONTROL_STATEMENT_IN_ONE_LINE" value="false" />
|
||||||
|
<option name="KEEP_BLANK_LINES_IN_DECLARATIONS" value="1" />
|
||||||
|
<option name="KEEP_BLANK_LINES_IN_CODE" value="1" />
|
||||||
|
<option name="KEEP_BLANK_LINES_BEFORE_RBRACE" value="1" />
|
||||||
|
<option name="BLANK_LINES_AROUND_FIELD" value="1" />
|
||||||
|
<option name="BLANK_LINES_AROUND_FIELD_IN_INTERFACE" value="1" />
|
||||||
|
<option name="BLANK_LINES_AFTER_CLASS_HEADER" value="1" />
|
||||||
|
<option name="INDENT_CASE_FROM_SWITCH" value="false" />
|
||||||
|
<option name="ALIGN_MULTILINE_CHAINED_METHODS" value="true" />
|
||||||
|
<option name="ALIGN_MULTILINE_THROWS_LIST" value="true" />
|
||||||
|
<option name="SPACE_BEFORE_ARRAY_INITIALIZER_LBRACE" value="true" />
|
||||||
|
<option name="SPACE_BEFORE_ANNOTATION_ARRAY_INITIALIZER_LBRACE" value="true" />
|
||||||
|
<option name="CALL_PARAMETERS_WRAP" value="1" />
|
||||||
|
<option name="METHOD_PARAMETERS_WRAP" value="1" />
|
||||||
|
<option name="METHOD_PARAMETERS_LPAREN_ON_NEXT_LINE" value="true" />
|
||||||
|
<option name="RESOURCE_LIST_WRAP" value="1" />
|
||||||
|
<option name="EXTENDS_LIST_WRAP" value="1" />
|
||||||
|
<option name="THROWS_LIST_WRAP" value="1" />
|
||||||
|
<option name="EXTENDS_KEYWORD_WRAP" value="1" />
|
||||||
|
<option name="THROWS_KEYWORD_WRAP" value="1" />
|
||||||
|
<option name="METHOD_CALL_CHAIN_WRAP" value="5" />
|
||||||
|
<option name="BINARY_OPERATION_WRAP" value="1" />
|
||||||
|
<option name="BINARY_OPERATION_SIGN_ON_NEXT_LINE" value="true" />
|
||||||
|
<option name="TERNARY_OPERATION_WRAP" value="5" />
|
||||||
|
<option name="TERNARY_OPERATION_SIGNS_ON_NEXT_LINE" value="true" />
|
||||||
|
<option name="FOR_STATEMENT_WRAP" value="1" />
|
||||||
|
<option name="ARRAY_INITIALIZER_WRAP" value="1" />
|
||||||
|
<option name="ASSIGNMENT_WRAP" value="1" />
|
||||||
|
<option name="PLACE_ASSIGNMENT_SIGN_ON_NEXT_LINE" value="true" />
|
||||||
|
<option name="ASSERT_STATEMENT_WRAP" value="1" />
|
||||||
|
<option name="ASSERT_STATEMENT_COLON_ON_NEXT_LINE" value="true" />
|
||||||
|
<option name="IF_BRACE_FORCE" value="3" />
|
||||||
|
<option name="DOWHILE_BRACE_FORCE" value="3" />
|
||||||
|
<option name="WHILE_BRACE_FORCE" value="3" />
|
||||||
|
<option name="FOR_BRACE_FORCE" value="3" />
|
||||||
|
<option name="WRAP_LONG_LINES" value="true" />
|
||||||
|
<option name="PARAMETER_ANNOTATION_WRAP" value="1" />
|
||||||
|
<option name="VARIABLE_ANNOTATION_WRAP" value="1" />
|
||||||
|
<option name="ENUM_CONSTANTS_WRAP" value="1" />
|
||||||
|
<arrangement>
|
||||||
|
<groups>
|
||||||
|
<group>
|
||||||
|
<type>GETTERS_AND_SETTERS</type>
|
||||||
|
<order>KEEP</order>
|
||||||
|
</group>
|
||||||
|
<group>
|
||||||
|
<type>OVERRIDDEN_METHODS</type>
|
||||||
|
<order>KEEP</order>
|
||||||
|
</group>
|
||||||
|
<group>
|
||||||
|
<type>DEPENDENT_METHODS</type>
|
||||||
|
<order>BREADTH_FIRST</order>
|
||||||
|
</group>
|
||||||
|
</groups>
|
||||||
|
</arrangement>
|
||||||
|
</codeStyleSettings>
|
||||||
|
</value>
|
||||||
|
</option>
|
||||||
|
<option name="USE_PER_PROJECT_SETTINGS" value="true" />
|
||||||
|
</component>
|
||||||
|
</project>
|
33
.idea/compiler.xml
Normal file
33
.idea/compiler.xml
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="CompilerConfiguration">
|
||||||
|
<option name="DEFAULT_COMPILER" value="Javac" />
|
||||||
|
<resourceExtensions />
|
||||||
|
<wildcardResourcePatterns>
|
||||||
|
<entry name="!?*.java" />
|
||||||
|
<entry name="!?*.form" />
|
||||||
|
<entry name="!?*.class" />
|
||||||
|
<entry name="!?*.groovy" />
|
||||||
|
<entry name="!?*.scala" />
|
||||||
|
<entry name="!?*.flex" />
|
||||||
|
<entry name="!?*.kt" />
|
||||||
|
<entry name="!?*.clj" />
|
||||||
|
<entry name="!?*.aj" />
|
||||||
|
</wildcardResourcePatterns>
|
||||||
|
<annotationProcessing>
|
||||||
|
<profile default="true" name="Default" enabled="false">
|
||||||
|
<processorPath useClasspath="true" />
|
||||||
|
</profile>
|
||||||
|
<profile default="false" name="Maven default annotation processors profile" enabled="true">
|
||||||
|
<sourceOutputDir name="target/generated-sources/annotations" />
|
||||||
|
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
|
||||||
|
<outputRelativeToContentRoot value="true" />
|
||||||
|
<processorPath useClasspath="true" />
|
||||||
|
<module name="node" />
|
||||||
|
</profile>
|
||||||
|
</annotationProcessing>
|
||||||
|
<bytecodeTargetLevel>
|
||||||
|
<module name="node" target="1.8" />
|
||||||
|
</bytecodeTargetLevel>
|
||||||
|
</component>
|
||||||
|
</project>
|
7
.idea/encodings.xml
Normal file
7
.idea/encodings.xml
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="Encoding">
|
||||||
|
<file url="file://$PROJECT_DIR$" charset="UTF-8" />
|
||||||
|
<file url="PROJECT" charset="UTF-8" />
|
||||||
|
</component>
|
||||||
|
</project>
|
59
.idea/inspectionProfiles/Project_Default.xml
Normal file
59
.idea/inspectionProfiles/Project_Default.xml
Normal file
|
@ -0,0 +1,59 @@
|
||||||
|
<component name="InspectionProjectProfileManager">
|
||||||
|
<profile version="1.0">
|
||||||
|
<option name="myName" value="Project Default" />
|
||||||
|
<option name="myLocal" value="true" />
|
||||||
|
<inspection_tool class="AssertEqualsCalledOnArray" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||||
|
<inspection_tool class="AssertEqualsMayBeAssertSame" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||||
|
<inspection_tool class="AssertsWithoutMessages" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||||
|
<inspection_tool class="BeforeClassOrAfterClassIsPublicStaticVoidNoArg" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||||
|
<inspection_tool class="BeforeOrAfterIsPublicVoidNoArg" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||||
|
<inspection_tool class="ConstantJUnitAssertArgument" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||||
|
<inspection_tool class="ExpectedExceptionNeverThrown" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||||
|
<inspection_tool class="IgnoredJUnitTest" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||||
|
<inspection_tool class="JUnit3MethodNamingConvention" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||||
|
<inspection_tool class="JUnit3StyleTestMethodInJUnit4Class" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||||
|
<inspection_tool class="JUnit4MethodNamingConvention" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||||
|
<inspection_tool class="JUnitAbstractTestClassNamingConvention" enabled="true" level="WARNING" enabled_by_default="true">
|
||||||
|
<option name="m_regex" value="[A-Z][A-Za-z\d]*TestCase" />
|
||||||
|
<option name="m_minLength" value="12" />
|
||||||
|
<option name="m_maxLength" value="64" />
|
||||||
|
</inspection_tool>
|
||||||
|
<inspection_tool class="JUnitDatapoint" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||||
|
<inspection_tool class="JUnitRule" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||||
|
<inspection_tool class="JUnitTestClassNamingConvention" enabled="true" level="WARNING" enabled_by_default="true">
|
||||||
|
<option name="m_regex" value="[A-Z][A-Za-z\d]*(Test|IT)" />
|
||||||
|
<option name="m_minLength" value="8" />
|
||||||
|
<option name="m_maxLength" value="64" />
|
||||||
|
</inspection_tool>
|
||||||
|
<inspection_tool class="LoggerInitializedWithForeignClass" enabled="false" level="WARNING" enabled_by_default="false">
|
||||||
|
<option name="loggerClassName" value="org.apache.log4j.Logger,org.slf4j.LoggerFactory,org.apache.commons.logging.LogFactory,java.util.logging.Logger" />
|
||||||
|
<option name="loggerFactoryMethodName" value="getLogger,getLogger,getLog,getLogger" />
|
||||||
|
</inspection_tool>
|
||||||
|
<inspection_tool class="MigrateAssertToMatcherAssert" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||||
|
<inspection_tool class="MisorderedAssertEqualsParameters" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||||
|
<inspection_tool class="MisspelledSetUp" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||||
|
<inspection_tool class="MisspelledTearDown" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||||
|
<inspection_tool class="MultipleExceptionsDeclaredOnTestMethod" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||||
|
<inspection_tool class="ParameterizedParametersStaticCollection" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||||
|
<inspection_tool class="SetupCallsSuperSetup" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||||
|
<inspection_tool class="SetupIsPublicVoidNoArg" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||||
|
<inspection_tool class="SimplifiableJUnitAssertion" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||||
|
<inspection_tool class="StaticSuite" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||||
|
<inspection_tool class="SuperTearDownInFinally" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||||
|
<inspection_tool class="TeardownCallsSuperTeardown" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||||
|
<inspection_tool class="TeardownIsPublicVoidNoArg" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||||
|
<inspection_tool class="TestCaseInProductCode" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||||
|
<inspection_tool class="TestCaseWithConstructor" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||||
|
<inspection_tool class="TestCaseWithNoTestMethods" enabled="true" level="WARNING" enabled_by_default="true">
|
||||||
|
<option name="ignoreSupers" value="false" />
|
||||||
|
</inspection_tool>
|
||||||
|
<inspection_tool class="TestMethodInProductCode" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||||
|
<inspection_tool class="TestMethodIsPublicVoidNoArg" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||||
|
<inspection_tool class="TestMethodWithoutAssertion" enabled="true" level="WARNING" enabled_by_default="true">
|
||||||
|
<option name="assertionMethods" value="org.junit.Assert,assert.*|fail.*,junit.framework.Assert,assert.*|fail.*,org.mockito.Mockito,verify.*,org.mockito.InOrder,verify,org.junit.rules.ExpectedException,expect.*,org.hamcrest.MatcherAssert,assertThat" />
|
||||||
|
<option name="assertKeywordIsAssertion" value="false" />
|
||||||
|
</inspection_tool>
|
||||||
|
<inspection_tool class="UnconstructableTestCase" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||||
|
<inspection_tool class="UseOfObsoleteAssert" enabled="true" level="WARNING" enabled_by_default="true" />
|
||||||
|
</profile>
|
||||||
|
</component>
|
7
.idea/inspectionProfiles/profiles_settings.xml
Normal file
7
.idea/inspectionProfiles/profiles_settings.xml
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
<component name="InspectionProjectProfileManager">
|
||||||
|
<settings>
|
||||||
|
<option name="PROJECT_PROFILE" value="Project Default" />
|
||||||
|
<option name="USE_PROJECT_PROFILE" value="true" />
|
||||||
|
<version value="1.0" />
|
||||||
|
</settings>
|
||||||
|
</component>
|
42
.idea/misc.xml
Normal file
42
.idea/misc.xml
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="EntryPointsManager">
|
||||||
|
<entry_points version="2.0" />
|
||||||
|
</component>
|
||||||
|
<component name="MavenProjectsManager">
|
||||||
|
<option name="originalFiles">
|
||||||
|
<list>
|
||||||
|
<option value="$PROJECT_DIR$/pom.xml" />
|
||||||
|
</list>
|
||||||
|
</option>
|
||||||
|
</component>
|
||||||
|
<component name="ProjectLevelVcsManager" settingsEditedManually="false">
|
||||||
|
<OptionsSetting value="true" id="Add" />
|
||||||
|
<OptionsSetting value="true" id="Remove" />
|
||||||
|
<OptionsSetting value="true" id="Checkout" />
|
||||||
|
<OptionsSetting value="true" id="Update" />
|
||||||
|
<OptionsSetting value="true" id="Status" />
|
||||||
|
<OptionsSetting value="true" id="Edit" />
|
||||||
|
<ConfirmationsSetting value="0" id="Add" />
|
||||||
|
<ConfirmationsSetting value="0" id="Remove" />
|
||||||
|
</component>
|
||||||
|
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_6" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
|
||||||
|
<output url="file://$PROJECT_DIR$/classes" />
|
||||||
|
</component>
|
||||||
|
<component name="masterDetails">
|
||||||
|
<states>
|
||||||
|
<state key="ProjectJDKs.UI">
|
||||||
|
<settings>
|
||||||
|
<last-edited>1.8</last-edited>
|
||||||
|
<splitter-proportions>
|
||||||
|
<option name="proportions">
|
||||||
|
<list>
|
||||||
|
<option value="0.2" />
|
||||||
|
</list>
|
||||||
|
</option>
|
||||||
|
</splitter-proportions>
|
||||||
|
</settings>
|
||||||
|
</state>
|
||||||
|
</states>
|
||||||
|
</component>
|
||||||
|
</project>
|
8
.idea/modules.xml
Normal file
8
.idea/modules.xml
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/node.iml" filepath="$PROJECT_DIR$/node.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
6
.idea/vcs.xml
Normal file
6
.idea/vcs.xml
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
18
node.iml
Normal file
18
node.iml
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8" inherit-compiler-output="false">
|
||||||
|
<output url="file://$MODULE_DIR$/target/classes" />
|
||||||
|
<output-test url="file://$MODULE_DIR$/target/test-classes" />
|
||||||
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/target" />
|
||||||
|
</content>
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
<orderEntry type="library" scope="TEST" name="Maven: org.projectlombok:lombok:1.16.8" level="project" />
|
||||||
|
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.12" level="project" />
|
||||||
|
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
|
||||||
|
</component>
|
||||||
|
</module>
|
7
pom.xml
7
pom.xml
|
@ -1,7 +1,6 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>net.kemitix</groupId>
|
|
||||||
<artifactId>node</artifactId>
|
<artifactId>node</artifactId>
|
||||||
<version>0.2.0-SNAPSHOT</version>
|
<version>0.2.0-SNAPSHOT</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
@ -31,6 +30,12 @@
|
||||||
<inceptionYear>2016</inceptionYear>
|
<inceptionYear>2016</inceptionYear>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok</artifactId>
|
||||||
|
<version>1.16.8</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>junit</groupId>
|
||||||
<artifactId>junit</artifactId>
|
<artifactId>junit</artifactId>
|
||||||
|
|
|
@ -7,8 +7,9 @@ import java.util.Set;
|
||||||
/**
|
/**
|
||||||
* An interface for tree node items.
|
* An interface for tree node items.
|
||||||
*
|
*
|
||||||
* @author pcampbell
|
|
||||||
* @param <T> the type of data held in each node
|
* @param <T> the type of data held in each node
|
||||||
|
*
|
||||||
|
* @author pcampbell
|
||||||
*/
|
*/
|
||||||
public interface Node<T> {
|
public interface Node<T> {
|
||||||
|
|
||||||
|
@ -21,7 +22,6 @@ public interface Node<T> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fetch the parent node.
|
* Fetch the parent node.
|
||||||
*
|
|
||||||
* <p>
|
* <p>
|
||||||
* If the node is a root node, i.e. has no parent, then this will return
|
* If the node is a root node, i.e. has no parent, then this will return
|
||||||
* null.
|
* null.
|
||||||
|
|
|
@ -18,7 +18,7 @@ public class NodeItem<T> implements Node<T> {
|
||||||
|
|
||||||
private Node<T> parent;
|
private Node<T> parent;
|
||||||
|
|
||||||
private Set<Node<T>> children;
|
private final Set<Node<T>> children = new HashSet<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a root node.
|
* Creates a root node.
|
||||||
|
@ -43,7 +43,6 @@ public class NodeItem<T> implements Node<T> {
|
||||||
if (parent != null) {
|
if (parent != null) {
|
||||||
setParent(parent);
|
setParent(parent);
|
||||||
}
|
}
|
||||||
this.children = new HashSet<>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -109,19 +108,15 @@ public class NodeItem<T> implements Node<T> {
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public boolean isChildOf(final Node<T> node) {
|
public boolean isChildOf(final Node<T> node) {
|
||||||
if (node.equals(parent)) {
|
return parent != null && (node.equals(parent) || parent.isChildOf(
|
||||||
return true;
|
node));
|
||||||
}
|
|
||||||
if (parent != null) {
|
|
||||||
return parent.isChildOf(node);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Walks the node tree using the path to select each child.
|
* Walks the node tree using the path to select each child.
|
||||||
*
|
*
|
||||||
* @param path the path to the desired child
|
* @param path the path to the desired child
|
||||||
|
*
|
||||||
* @return the child or null
|
* @return the child or null
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
|
@ -153,9 +148,8 @@ public class NodeItem<T> implements Node<T> {
|
||||||
throw new NullPointerException("descendants");
|
throw new NullPointerException("descendants");
|
||||||
}
|
}
|
||||||
if (!descendants.isEmpty()) {
|
if (!descendants.isEmpty()) {
|
||||||
findOrCreateChild(descendants.get(0))
|
findOrCreateChild(descendants.get(0)).createDescendantLine(
|
||||||
.createDescendantLine(
|
descendants.subList(1, descendants.size()));
|
||||||
descendants.subList(1, descendants.size()));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -172,12 +166,7 @@ public class NodeItem<T> implements Node<T> {
|
||||||
if (child == null) {
|
if (child == null) {
|
||||||
throw new NullPointerException("child");
|
throw new NullPointerException("child");
|
||||||
}
|
}
|
||||||
Optional<Node<T>> found = getChild(child);
|
return getChild(child).orElseGet(() -> createChild(child));
|
||||||
if (found.isPresent()) {
|
|
||||||
return found.get();
|
|
||||||
} else {
|
|
||||||
return createChild(child);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -193,8 +182,8 @@ public class NodeItem<T> implements Node<T> {
|
||||||
throw new NullPointerException("child");
|
throw new NullPointerException("child");
|
||||||
}
|
}
|
||||||
return children.stream()
|
return children.stream()
|
||||||
.filter((Node<T> t) -> t.getData().equals(child))
|
.filter((Node<T> t) -> t.getData().equals(child))
|
||||||
.findAny();
|
.findAny();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
package net.kemitix.node;
|
package net.kemitix.node;
|
||||||
|
|
||||||
import net.kemitix.node.NodeException;
|
import lombok.val;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import static org.hamcrest.CoreMatchers.is;
|
import static org.hamcrest.CoreMatchers.is;
|
||||||
|
@ -14,20 +13,15 @@ import static org.junit.Assert.assertThat;
|
||||||
*/
|
*/
|
||||||
public class NodeExceptionTest {
|
public class NodeExceptionTest {
|
||||||
|
|
||||||
/**
|
|
||||||
* Class under test.
|
|
||||||
*/
|
|
||||||
private NodeException nodeException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test that message provided to constructor is returned.
|
* Test that message provided to constructor is returned.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void shouldReturnConstructorMessage() {
|
public void shouldReturnConstructorMessage() {
|
||||||
//given
|
//given
|
||||||
final String message = "this is the message";
|
val message = "this is the message";
|
||||||
//when
|
//when
|
||||||
nodeException = new NodeException(message);
|
val nodeException = new NodeException(message);
|
||||||
//then
|
//then
|
||||||
assertThat(nodeException.getMessage(), is(message));
|
assertThat(nodeException.getMessage(), is(message));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,18 +1,17 @@
|
||||||
package net.kemitix.node;
|
package net.kemitix.node;
|
||||||
|
|
||||||
|
import lombok.val;
|
||||||
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import static org.hamcrest.CoreMatchers.hasItem;
|
||||||
|
import static org.hamcrest.CoreMatchers.is;
|
||||||
|
import static org.hamcrest.CoreMatchers.nullValue;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
import static org.hamcrest.CoreMatchers.hasItem;
|
|
||||||
import static org.hamcrest.CoreMatchers.is;
|
|
||||||
import static org.junit.Assert.assertFalse;
|
|
||||||
import static org.junit.Assert.assertNull;
|
|
||||||
import static org.junit.Assert.assertThat;
|
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test for {@link NodeItem}.
|
* Test for {@link NodeItem}.
|
||||||
*
|
*
|
||||||
|
@ -26,22 +25,21 @@ public class NodeItemTest {
|
||||||
private Node<String> node;
|
private Node<String> node;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test {@link NodeItem#Node(java.lang.Object) } that node data is
|
* Test that node data is recoverable.
|
||||||
* recoverable.
|
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void shouldReturnNodeData() {
|
public void shouldReturnNodeData() {
|
||||||
//given
|
//given
|
||||||
final String data = "this node data";
|
val data = "this node data";
|
||||||
//when
|
//when
|
||||||
node = new NodeItem<>(data);
|
node = new NodeItem<>(data);
|
||||||
//then
|
//then
|
||||||
assertThat(node.getData(), is(data));
|
Assert.assertThat("can get the data from a node", node.getData(),
|
||||||
|
is(data));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test {@link NodeItem#Node(java.lang.Object) } that passing null as node
|
* Test that passing null as node data throws exception.
|
||||||
* data throws exception.
|
|
||||||
*/
|
*/
|
||||||
@Test(expected = NullPointerException.class)
|
@Test(expected = NullPointerException.class)
|
||||||
public void shouldThrowNPEWhenDataIsNull() {
|
public void shouldThrowNPEWhenDataIsNull() {
|
||||||
|
@ -50,78 +48,79 @@ public class NodeItemTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test {@link NodeItem#Node(java.lang.Object) } that default node parent is
|
* Test that default node parent is null.
|
||||||
* null.
|
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void shouldHaveNullForDefaulParent() {
|
public void shouldHaveNullForDefaultParent() {
|
||||||
//given
|
//given
|
||||||
node = new NodeItem<>("data");
|
node = new NodeItem<>("data");
|
||||||
//then
|
//then
|
||||||
assertNull(node.getParent());
|
Assert.assertThat("node created without a parent has null as parent",
|
||||||
|
node.getParent(), nullValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test {@link NodeItem#Node(java.lang.Object, net.kemitix.node.Node) } that
|
* Test that provided node parent is returned.
|
||||||
* provided node parent is returned.
|
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void shouldReturnNodeParent() {
|
public void shouldReturnNodeParent() {
|
||||||
//given
|
//given
|
||||||
Node<String> parent = new NodeItem<>("parent");
|
val parent = new NodeItem<String>("parent");
|
||||||
//when
|
//when
|
||||||
node = new NodeItem<>("subject", parent);
|
node = new NodeItem<>("subject", parent);
|
||||||
//then
|
//then
|
||||||
assertThat(node.getParent(), is(parent));
|
Assert.assertThat("node created with a parent can return the parent",
|
||||||
|
node.getParent(), is(parent));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test {@link NodeItem#Node(java.lang.Object, net.kemitix.node.Node) } that
|
* Test that setting the parent on a node where the proposed parent is a
|
||||||
* setting the parent on a node where the proposed parent is a child of the
|
* child of the node throws an exception.
|
||||||
* node throws an exception.
|
|
||||||
*/
|
*/
|
||||||
@Test(expected = NodeException.class)
|
@Test(expected = NodeException.class)
|
||||||
public void shouldThrowNEWhenSettingParentToAChild() {
|
public void shouldThrowNEWhenSettingParentToAChild() {
|
||||||
//given
|
//given
|
||||||
node = new NodeItem<>("subject");
|
node = new NodeItem<>("subject");
|
||||||
Node<String> child = new NodeItem<>("child", node);
|
val child = new NodeItem<String>("child", node);
|
||||||
//when
|
//when
|
||||||
node.setParent(child);
|
node.setParent(child);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test {@link NodeItem#Node(java.lang.Object, net.kemitix.node.Node) } that
|
* Test that when parent is added to created node, the created node is now a
|
||||||
* when parent is added to created node, the created node is now a child of
|
* child of the parent.
|
||||||
* the parent.
|
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void shouldAddNewNodeAsChildToParent() {
|
public void shouldAddNewNodeAsChildToParent() {
|
||||||
//given
|
//given
|
||||||
Node<String> parent = new NodeItem<>("parent");
|
val parent = new NodeItem<String>("parent");
|
||||||
//when
|
//when
|
||||||
node = new NodeItem<>("subject", parent);
|
node = new NodeItem<>("subject", parent);
|
||||||
//then
|
//then
|
||||||
assertThat(parent.getChildren(), hasItem(node));
|
Assert.assertThat(
|
||||||
|
"when a node is created with a parent, the parent has the new"
|
||||||
|
+ " node among it's children", parent.getChildren(),
|
||||||
|
hasItem(node));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test {@link NodeItem#setParent(net.kemitix.node.Node) } that we return
|
* Test that we return the same parent when set.
|
||||||
* the same parent when set.
|
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void shouldReturnSetParent() {
|
public void shouldReturnSetParent() {
|
||||||
//given
|
//given
|
||||||
node = new NodeItem<>("subject");
|
node = new NodeItem<>("subject");
|
||||||
Node<String> parent = new NodeItem<>("parent");
|
val parent = new NodeItem<String>("parent");
|
||||||
//when
|
//when
|
||||||
node.setParent(parent);
|
node.setParent(parent);
|
||||||
//then
|
//then
|
||||||
assertThat(node.getParent(), is(parent));
|
Assert.assertThat(
|
||||||
|
"when a node is assigned a new parent that parent can be "
|
||||||
|
+ "returned", node.getParent(), is(parent));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test {@link NodeItem#setParent(net.kemitix.node.Node) } that we throw an
|
* Test that we throw an exception when passed null.
|
||||||
* exception when passed null.
|
|
||||||
*/
|
*/
|
||||||
@Test(expected = NullPointerException.class)
|
@Test(expected = NullPointerException.class)
|
||||||
public void shouldThrowNPEWhenSetParentNull() {
|
public void shouldThrowNPEWhenSetParentNull() {
|
||||||
|
@ -132,8 +131,8 @@ public class NodeItemTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test {@link NodeItem#setParent(net.kemitix.node.Node) } that we throw an
|
* Test that we throw an exceptions when attempting to node as its own
|
||||||
* exceptions when attempting to node as its own parent.
|
* parent.
|
||||||
*/
|
*/
|
||||||
@Test(expected = NodeException.class)
|
@Test(expected = NodeException.class)
|
||||||
public void shouldThrowNEWhenSetParentSelf() {
|
public void shouldThrowNEWhenSetParentSelf() {
|
||||||
|
@ -144,44 +143,53 @@ public class NodeItemTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test {@link NodeItem#setParent(net.kemitix.node.Node) } that when a node
|
* Test that when a node with an existing parent is assigned a new parent,
|
||||||
* with an existing parent is assigned a new parent, that the old parent no
|
* that the old parent no longer sees it as one of its children.
|
||||||
* longer sees it as one of its children.
|
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void shouldUpdateOldParentWhenNodeSetToNewParent() {
|
public void shouldUpdateOldParentWhenNodeSetToNewParent() {
|
||||||
//given
|
//given
|
||||||
node = new NodeItem<>("subject");
|
node = new NodeItem<>("subject");
|
||||||
Node<String> child = node.createChild("child");
|
val child = node.createChild("child");
|
||||||
Node<String> newParent = new NodeItem<>("newParent");
|
val newParent = new NodeItem<String>("newParent");
|
||||||
//when
|
//when
|
||||||
child.setParent(newParent);
|
child.setParent(newParent);
|
||||||
//then
|
//then
|
||||||
assertThat(child.getParent(), is(newParent));
|
Assert.assertThat(
|
||||||
assertFalse(node.getChild("child").isPresent());
|
"when a node is assigned a new parent, the old parent is "
|
||||||
|
+ "replaced", child.getParent(), is(newParent));
|
||||||
|
Assert.assertThat(
|
||||||
|
"when a node is assigned a new parent, the old parent no "
|
||||||
|
+ "longer has the node among it's children",
|
||||||
|
node.getChild("child").isPresent(), is(false));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test {@link NodeItem#addChild(net.kemitix.node.Node) } that when a node
|
* Test that when a node is added as a child to another node, that it's
|
||||||
* is added as a child to another node, that it's previous parent no longer
|
* previous parent no longer has it as a child.
|
||||||
* has it as a child.
|
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void shouldRemoveNodeFromOldParentWhenAddedAsChildToNewParent() {
|
public void shouldRemoveNodeFromOldParentWhenAddedAsChildToNewParent() {
|
||||||
//given
|
//given
|
||||||
node = new NodeItem<>("subject");
|
node = new NodeItem<>("subject");
|
||||||
Node<String> child = node.createChild("child");
|
val child = node.createChild("child");
|
||||||
Node<String> newParent = new NodeItem<>("newParent");
|
val newParent = new NodeItem<String>("newParent");
|
||||||
//when
|
//when
|
||||||
newParent.addChild(child);
|
newParent.addChild(child);
|
||||||
//then
|
//then
|
||||||
assertThat(child.getParent(), is(newParent));
|
Assert.assertThat(
|
||||||
assertFalse(node.getChild("child").isPresent());
|
"when a node with an existing parent is added as a child "
|
||||||
|
+ "to another node, then the old parent is replaced",
|
||||||
|
child.getParent(), is(newParent));
|
||||||
|
Assert.assertThat(
|
||||||
|
"when a node with an existing parent is added as a child to "
|
||||||
|
+ "another node, then the old parent no longer has "
|
||||||
|
+ "the node among it's children",
|
||||||
|
node.getChild("child").isPresent(), is(false));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test {@link NodeItem#addChild(net.kemitix.node.Node) } that adding null
|
* Test that adding null as a child throws an exception.
|
||||||
* as a child throws an exception.
|
|
||||||
*/
|
*/
|
||||||
@Test(expected = NullPointerException.class)
|
@Test(expected = NullPointerException.class)
|
||||||
public void shouldThrowNPEWhenAddingNullAsChild() {
|
public void shouldThrowNPEWhenAddingNullAsChild() {
|
||||||
|
@ -192,23 +200,23 @@ public class NodeItemTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test {@link NodeItem#addChild(net.kemitix.node.Node) } that adding a
|
* Test that adding a child is returned.
|
||||||
* child is returned.
|
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void shouldReturnAddedChild() {
|
public void shouldReturnAddedChild() {
|
||||||
//given
|
//given
|
||||||
Node<String> child = new NodeItem<>("child");
|
|
||||||
node = new NodeItem<>("subject");
|
node = new NodeItem<>("subject");
|
||||||
|
val child = new NodeItem<String>("child");
|
||||||
//when
|
//when
|
||||||
node.addChild(child);
|
node.addChild(child);
|
||||||
//then
|
//then
|
||||||
assertThat(node.getChildren(), hasItem(child));
|
Assert.assertThat(
|
||||||
|
"when a node is added as a child, the node is among the "
|
||||||
|
+ "children", node.getChildren(), hasItem(child));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test {@link NodeItem#addChild(net.kemitix.node.Node) } that adding a node
|
* Test that adding a node as it's own child throws an exception.
|
||||||
* as it's own child throws an exception.
|
|
||||||
*/
|
*/
|
||||||
@Test(expected = NodeException.class)
|
@Test(expected = NodeException.class)
|
||||||
public void shouldThrowNEWhenAddingANodeAsOwnChild() {
|
public void shouldThrowNEWhenAddingANodeAsOwnChild() {
|
||||||
|
@ -219,8 +227,7 @@ public class NodeItemTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test {@link NodeItem#addChild(net.kemitix.node.Node) } that adding a node
|
* Test that adding a node to itself as a child causes an exception.
|
||||||
* to itself as a child causes an exception.
|
|
||||||
*/
|
*/
|
||||||
@Test(expected = NodeException.class)
|
@Test(expected = NodeException.class)
|
||||||
public void shouldThrowWhenAddingSelfAsChild() {
|
public void shouldThrowWhenAddingSelfAsChild() {
|
||||||
|
@ -231,89 +238,93 @@ public class NodeItemTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test {@link NodeItem#addChild(net.kemitix.node.Node) } that adding the
|
* Test that adding the parent of a node to the node as a child causes an
|
||||||
* parent to node causes an exception.
|
* exception.
|
||||||
*/
|
*/
|
||||||
@Test(expected = NodeException.class)
|
@Test(expected = NodeException.class)
|
||||||
public void shouldThrowWhenAddingParentAsChild() {
|
public void shouldThrowWhenAddingParentAsChild() {
|
||||||
//given
|
//given
|
||||||
Node<String> parent = new NodeItem<>("parent");
|
val parent = new NodeItem<String>("parent");
|
||||||
node = new NodeItem<>("subject", parent);
|
node = new NodeItem<>("subject", parent);
|
||||||
//when
|
//when
|
||||||
node.addChild(parent);
|
node.addChild(parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test {@link NodeItem#addChild(net.kemitix.node.Node) } that adding the
|
* Test that adding the grandparent to a node as a child causes an
|
||||||
* grandparent to node causes an exception.
|
* exception.
|
||||||
*/
|
*/
|
||||||
@Test(expected = NodeException.class)
|
@Test(expected = NodeException.class)
|
||||||
public void shouldThrowWhenAddingGrandParentAsChild() {
|
public void shouldThrowWhenAddingGrandParentAsChild() {
|
||||||
//given
|
//given
|
||||||
Node<String> grandParent = new NodeItem<>("grandparent");
|
val grandParent = new NodeItem<String>("grandparent");
|
||||||
Node<String> parent = new NodeItem<>("parent", grandParent);
|
val parent = new NodeItem<String>("parent", grandParent);
|
||||||
node = new NodeItem<>("subject", parent);
|
node = new NodeItem<>("subject", parent);
|
||||||
//when
|
//when
|
||||||
node.addChild(grandParent);
|
node.addChild(grandParent);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test {@link NodeItem#addChild(net.kemitix.node.Node) } that adding a
|
* Test that adding a child to a node, sets the child's parent node.
|
||||||
* child to a node, sets the child's parent node.
|
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void shouldSetParentOnChildWhenAddedAsChild() {
|
public void shouldSetParentOnChildWhenAddedAsChild() {
|
||||||
//given
|
//given
|
||||||
Node<String> child = new NodeItem<>("child");
|
val child = new NodeItem<String>("child");
|
||||||
node = new NodeItem<>("subject");
|
node = new NodeItem<>("subject");
|
||||||
//when
|
//when
|
||||||
node.addChild(child);
|
node.addChild(child);
|
||||||
//then
|
//then
|
||||||
assertThat(child.getParent(), is(node));
|
Assert.assertThat(
|
||||||
|
"when a node is added as a child, the child has the node as "
|
||||||
|
+ "its parent", child.getParent(), is(node));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test {@link NodeItem#walkTree(java.util.List) } that we can walk a tree
|
* Test that we can walk a tree to the target node.
|
||||||
* to the target node.
|
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void shouldWalkTreeToNode() {
|
public void shouldWalkTreeToNode() {
|
||||||
//given
|
//given
|
||||||
final String grandparent = "grandparent";
|
val grandparent = "grandparent";
|
||||||
Node<String> grandParentNode = new NodeItem<>(grandparent);
|
val grandParentNode = new NodeItem<String>(grandparent);
|
||||||
final String parent = "parent";
|
val parent = "parent";
|
||||||
Node<String> parentNode = new NodeItem<>(parent, grandParentNode);
|
val parentNode = new NodeItem<String>(parent, grandParentNode);
|
||||||
final String subject = "subject";
|
val subject = "subject";
|
||||||
node = new NodeItem<>(subject, parentNode);
|
node = new NodeItem<>(subject, parentNode);
|
||||||
//when
|
//when
|
||||||
Optional<Node<String>> result = grandParentNode.walkTree(Arrays.asList(
|
val result = grandParentNode.walkTree(Arrays.asList(parent, subject));
|
||||||
parent, subject));
|
|
||||||
//then
|
//then
|
||||||
assertTrue(result.isPresent());
|
Assert.assertThat("when we walk the tree to a node it is found",
|
||||||
assertThat(result.get(), is(node));
|
result.isPresent(), is(true));
|
||||||
|
if (result.isPresent()) {
|
||||||
|
Assert.assertThat(
|
||||||
|
"when we walk the tree to a node the correct node is found",
|
||||||
|
result.get(), is(node));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test {@link NodeItem#walkTree(java.util.List) } that we get an empty
|
* Test that we get an empty {@link Optional} when walking a path that
|
||||||
* {@link Optional} when walking a path that doesn't exist.
|
* doesn't exist.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void shouldNotFindNonExistantChildNode() {
|
public void shouldNotFindNonExistentChildNode() {
|
||||||
//given
|
//given
|
||||||
final String parent = "parent";
|
val parent = "parent";
|
||||||
Node<String> parentNode = new NodeItem<>(parent);
|
val parentNode = new NodeItem<String>(parent);
|
||||||
final String subject = "subject";
|
val subject = "subject";
|
||||||
node = new NodeItem<>(subject, parentNode);
|
node = new NodeItem<>(subject, parentNode);
|
||||||
//when
|
//when
|
||||||
Optional<Node<String>> result = parentNode.walkTree(Arrays.asList(
|
val result = parentNode.walkTree(Arrays.asList(subject, "no child"));
|
||||||
subject, "no child"));
|
|
||||||
//then
|
//then
|
||||||
assertFalse(result.isPresent());
|
Assert.assertThat(
|
||||||
|
"when we walk the tree to a node that doesn't exists, nothing"
|
||||||
|
+ " is found", result.isPresent(), is(false));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test {@link NodeItem#walkTree(java.util.List) } that when we pass null we
|
* Test that when we pass null we get an exception.
|
||||||
* get an exception.
|
|
||||||
*/
|
*/
|
||||||
@Test(expected = NullPointerException.class)
|
@Test(expected = NullPointerException.class)
|
||||||
public void shouldThrowNEWhenWalkTreeNull() {
|
public void shouldThrowNEWhenWalkTreeNull() {
|
||||||
|
@ -324,8 +335,8 @@ public class NodeItemTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test {@link NodeItem#walkTree(java.util.List) } that when we pass an
|
* Test that when we pass an empty path we get and empty {@link Optional} as
|
||||||
* empty path we get and empty {@link Optional} as a result.
|
* a result.
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void shouldReturnEmptyForEmptyWalkTreePath() {
|
public void shouldReturnEmptyForEmptyWalkTreePath() {
|
||||||
|
@ -336,37 +347,58 @@ public class NodeItemTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test {@link NodeItem#createDescendantLine(java.util.List) } that we can
|
* Test that we can create a chain of descendant nodes.
|
||||||
* create a chain of descendant nodes.
|
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void shouldCreateDescendantNodes() {
|
public void shouldCreateDescendantNodes() {
|
||||||
//given
|
//given
|
||||||
node = new NodeItem<>("subject");
|
node = new NodeItem<>("subject");
|
||||||
final String alphaData = "alpha";
|
val alphaData = "alpha";
|
||||||
final String betaData = "beta";
|
val betaData = "beta";
|
||||||
final String gammaData = "gamma";
|
val gammaData = "gamma";
|
||||||
//when
|
//when
|
||||||
node.createDescendantLine(
|
node.createDescendantLine(
|
||||||
Arrays.asList(alphaData, betaData, gammaData));
|
Arrays.asList(alphaData, betaData, gammaData));
|
||||||
//then
|
//then
|
||||||
final Optional<Node<String>> alphaOptional = node.getChild(alphaData);
|
val alphaOptional = node.getChild(alphaData);
|
||||||
assertTrue(alphaOptional.isPresent());
|
Assert.assertThat(
|
||||||
Node<String> alpha = alphaOptional.get();
|
"when creating a descendant line, the first element is found",
|
||||||
assertThat(alpha.getParent(), is(node));
|
alphaOptional.isPresent(), is(true));
|
||||||
final Optional<Node<String>> betaOptional = alpha.getChild(betaData);
|
if (alphaOptional.isPresent()) {
|
||||||
assertTrue(betaOptional.isPresent());
|
val alpha = alphaOptional.get();
|
||||||
Node<String> beta = betaOptional.get();
|
Assert.assertThat(
|
||||||
assertThat(beta.getParent(), is(alpha));
|
"when creating a descendant line, the first element has "
|
||||||
final Optional<Node<String>> gammaOptional = beta.getChild(gammaData);
|
+ "the current node as its parent",
|
||||||
assertTrue(gammaOptional.isPresent());
|
alpha.getParent(), is(node));
|
||||||
Node<String> gamma = gammaOptional.get();
|
val betaOptional = alpha.getChild(betaData);
|
||||||
assertThat(gamma.getParent(), is(beta));
|
Assert.assertThat(
|
||||||
|
"when creating a descendant line, the second element is "
|
||||||
|
+ "found", betaOptional.isPresent(), is(true));
|
||||||
|
if (betaOptional.isPresent()) {
|
||||||
|
val beta = betaOptional.get();
|
||||||
|
Assert.assertThat(
|
||||||
|
"when creating a descendant line, the second element "
|
||||||
|
+ "has the first as its parent",
|
||||||
|
beta.getParent(), is(alpha));
|
||||||
|
val gammaOptional = beta.getChild(gammaData);
|
||||||
|
Assert.assertThat(
|
||||||
|
"when creating a descendant line, the third element "
|
||||||
|
+ "is found", gammaOptional.isPresent(),
|
||||||
|
is(true));
|
||||||
|
if (gammaOptional.isPresent()) {
|
||||||
|
val gamma = gammaOptional.get();
|
||||||
|
Assert.assertThat(
|
||||||
|
"when creating a descendant line, the third "
|
||||||
|
+ "element has the second as its parent",
|
||||||
|
gamma.getParent(), is(beta));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test {@link NodeItem#createDescendantLine(java.util.List) } that if we
|
* Test that if we pass null to create a chain of descendant nodes we get an
|
||||||
* pass null to create a chain of descendant nodes we get an exception.
|
* exception.
|
||||||
*/
|
*/
|
||||||
@Test(expected = NullPointerException.class)
|
@Test(expected = NullPointerException.class)
|
||||||
public void shouldThrowNPEWhenCreateDescendantNull() {
|
public void shouldThrowNPEWhenCreateDescendantNull() {
|
||||||
|
@ -377,8 +409,7 @@ public class NodeItemTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test {@link NodeItem#createDescendantLine(java.util.List) } that if we
|
* Test that if we pass an empty list nothing is changed.
|
||||||
* pass an empty list nothing is changed.
|
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void shouldChangeNothingWhenCreateDescendantEmpty() {
|
public void shouldChangeNothingWhenCreateDescendantEmpty() {
|
||||||
|
@ -387,43 +418,46 @@ public class NodeItemTest {
|
||||||
//when
|
//when
|
||||||
node.createDescendantLine(Collections.emptyList());
|
node.createDescendantLine(Collections.emptyList());
|
||||||
//then
|
//then
|
||||||
assertThat(node.getChildren().size(), is(0));
|
Assert.assertThat(
|
||||||
|
"when creating a descendant line from an empty list, nothing "
|
||||||
|
+ "is created", node.getChildren().size(), is(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test {@link NodeItem#findOrCreateChild(java.lang.Object) } that we can
|
* Test that we can find a child of a node.
|
||||||
* find a child of a node.
|
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void shouldFindExistingChildNode() {
|
public void shouldFindExistingChildNode() {
|
||||||
//given
|
//given
|
||||||
node = new NodeItem<>("subject");
|
node = new NodeItem<>("subject");
|
||||||
final String childData = "child";
|
val childData = "child";
|
||||||
Node<String> child = new NodeItem<>(childData, node);
|
val child = new NodeItem<String>(childData, node);
|
||||||
//when
|
//when
|
||||||
Node<String> found = node.findOrCreateChild(childData);
|
val found = node.findOrCreateChild(childData);
|
||||||
//then
|
//then
|
||||||
assertThat(found, is(child));
|
Assert.assertThat(
|
||||||
|
"when searching for a child by data, the matching child is "
|
||||||
|
+ "found", found, is(child));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test {@link NodeItem#findOrCreateChild(java.lang.Object) } that we create
|
* Test that we create a missing child of a node.
|
||||||
* a missing child of a node.
|
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void shouldFindCreateNewChildNode() {
|
public void shouldFindCreateNewChildNode() {
|
||||||
//given
|
//given
|
||||||
node = new NodeItem<>("subject");
|
node = new NodeItem<>("subject");
|
||||||
final String childData = "child";
|
val childData = "child";
|
||||||
//when
|
//when
|
||||||
Node<String> found = node.findOrCreateChild(childData);
|
val found = node.findOrCreateChild(childData);
|
||||||
//then
|
//then
|
||||||
assertThat(found.getData(), is(childData));
|
Assert.assertThat(
|
||||||
|
"when searching for a child by data, a new node is created",
|
||||||
|
found.getData(), is(childData));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test {@link NodeItem#findOrCreateChild(java.lang.Object) } that if we
|
* Test that if we pass null we get an exception.
|
||||||
* pass null we get an exception.
|
|
||||||
*/
|
*/
|
||||||
@Test(expected = NullPointerException.class)
|
@Test(expected = NullPointerException.class)
|
||||||
public void shouldThrowNPEFWhenFindOrCreateChildNull() {
|
public void shouldThrowNPEFWhenFindOrCreateChildNull() {
|
||||||
|
@ -434,26 +468,29 @@ public class NodeItemTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test {@link NodeItem#getChild(java.lang.Object) } that we can get the
|
* Test that we can get the node for a child.
|
||||||
* node for a child.
|
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void shouldGetChild() {
|
public void shouldGetChild() {
|
||||||
//given
|
//given
|
||||||
node = new NodeItem<>("subject");
|
node = new NodeItem<>("subject");
|
||||||
final String childData = "child";
|
val childData = "child";
|
||||||
Node<String> child = new NodeItem<>(childData);
|
val child = new NodeItem<String>(childData);
|
||||||
node.addChild(child);
|
node.addChild(child);
|
||||||
//when
|
//when
|
||||||
Optional<Node<String>> found = node.getChild(childData);
|
val found = node.getChild(childData);
|
||||||
//then
|
//then
|
||||||
assertTrue(found.isPresent());
|
Assert.assertThat("when retrieving a child by its data, it is found",
|
||||||
assertThat(found.get(), is(child));
|
found.isPresent(), is(true));
|
||||||
|
if (found.isPresent()) {
|
||||||
|
Assert.assertThat(
|
||||||
|
"when retrieving a child by its data, it is the expected "
|
||||||
|
+ "node", found.get(), is(child));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test {@link NodeItem#getChild(java.lang.Object) } that we throw an
|
* Test that we throw an exception when passed null.
|
||||||
* exception when passed null.
|
|
||||||
*/
|
*/
|
||||||
@Test(expected = NullPointerException.class)
|
@Test(expected = NullPointerException.class)
|
||||||
public void shouldThrowNPEWhenGetChildNull() {
|
public void shouldThrowNPEWhenGetChildNull() {
|
||||||
|
@ -464,22 +501,29 @@ public class NodeItemTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test {@link NodeItem#createChild(java.lang.Object) } that we create a
|
* Test that we create a child as a child of the current node and with the
|
||||||
* child as a child of the current node and with the current node as its
|
* current node as its parent.
|
||||||
* parent.
|
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void shoudCreateChild() {
|
public void shouldCreateChild() {
|
||||||
//given
|
//given
|
||||||
node = new NodeItem<>("subject");
|
node = new NodeItem<>("subject");
|
||||||
final String childData = "child";
|
val childData = "child";
|
||||||
//when
|
//when
|
||||||
Node<String> child = node.createChild(childData);
|
val child = node.createChild(childData);
|
||||||
//then
|
//then
|
||||||
assertThat(child.getParent(), is(node));
|
Assert.assertThat(
|
||||||
final Optional<Node<String>> foundChild = node.getChild(childData);
|
"when creating a child node, the child has the current node "
|
||||||
assertTrue(foundChild.isPresent());
|
+ "as its parent", child.getParent(), is(node));
|
||||||
assertThat(foundChild.get(), is(child));
|
val foundChild = node.getChild(childData);
|
||||||
|
Assert.assertThat(
|
||||||
|
"when creating a child node, the child can be found by its "
|
||||||
|
+ "data", foundChild.isPresent(), is(true));
|
||||||
|
if (foundChild.isPresent()) {
|
||||||
|
Assert.assertThat(
|
||||||
|
"when creating a child node, the correct child can be "
|
||||||
|
+ "found by its data", foundChild.get(), is(child));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue