-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added unit tests for ElementPath.kt, and added an extra check to ensu…
…re ElementPaths with nodes containing whitespaces cannot be created
- Loading branch information
1 parent
f3cad9a
commit 4bff8a7
Showing
4 changed files
with
78 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
src/test/kotlin/io/arkosammy12/monkeyconfig/util/TestElementPath.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package io.arkosammy12.monkeyconfig.util | ||
|
||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.assertThrows | ||
import kotlin.test.assertEquals | ||
|
||
class TestElementPath { | ||
|
||
@Test | ||
fun `ElementPath should not accept empty nodes`() { | ||
|
||
assertThrows<IllegalArgumentException> { | ||
ElementPath("") | ||
} | ||
|
||
assertThrows<IllegalArgumentException> { | ||
ElementPath("node1", "", "node3") | ||
} | ||
|
||
assertThrows<IllegalArgumentException> { | ||
ElementPath(".") | ||
} | ||
|
||
assertThrows<IllegalArgumentException> { | ||
ElementPath("node1..node3") | ||
} | ||
|
||
} | ||
|
||
@Test | ||
fun `Element Path should not accept nodes with whitespaces`() { | ||
|
||
assertThrows<IllegalArgumentException> { | ||
ElementPath(" ") | ||
} | ||
|
||
assertThrows<IllegalArgumentException> { | ||
ElementPath("node1", " node2", "node3") | ||
} | ||
|
||
assertThrows<IllegalArgumentException> { | ||
ElementPath(". ") | ||
} | ||
|
||
assertThrows<IllegalArgumentException> { | ||
ElementPath("node1. .node3") | ||
} | ||
|
||
} | ||
|
||
@Test | ||
fun `Element Path creation with node lists results in proper string representation`() { | ||
|
||
assertEquals(ElementPath("node").string, "node") | ||
|
||
assertEquals(ElementPath("node1", "node2").string, "node1.node2") | ||
|
||
assertEquals(ElementPath(listOf("node1", "node2", "node3")).string, "node1.node2.node3") | ||
|
||
} | ||
|
||
@Test | ||
fun `Element Path creation with strings results in proper list representation`() { | ||
|
||
assertEquals(ElementPath("node").asList, listOf("node")) | ||
|
||
assertEquals(ElementPath("node1.node2").asList, listOf("node1", "node2")) | ||
|
||
assertEquals(ElementPath("node1.node2.node3").asList, listOf("node1", "node2", "node3")) | ||
|
||
} | ||
|
||
} |