mirror of
https://github.com/lightbend/config.git
synced 2025-02-19 15:50:47 +08:00
Clean up ConfigDocument tests
Clean up the ConfigDocument tests by renaming certain tests and modifying all exception testing to use the intercept method.
This commit is contained in:
parent
6c011b5e4a
commit
c2b2c10d38
@ -14,7 +14,7 @@ class ConfigDocumentParserTest extends TestUtils {
|
|||||||
private def parseJSONFailuresTest(origText: String, containsMessage: String) {
|
private def parseJSONFailuresTest(origText: String, containsMessage: String) {
|
||||||
var exceptionThrown = false
|
var exceptionThrown = false
|
||||||
val e = intercept[ConfigException] {
|
val e = intercept[ConfigException] {
|
||||||
ConfigDocumentParser.parse(tokenize(origText), fakeOrigin(), ConfigParseOptions.defaults().setSyntax(ConfigSyntax.JSON))
|
ConfigDocumentParser.parse(tokenize(origText), fakeOrigin(), ConfigParseOptions.defaults().setSyntax(ConfigSyntax.JSON))
|
||||||
}
|
}
|
||||||
assertTrue(e.getMessage.contains(containsMessage))
|
assertTrue(e.getMessage.contains(containsMessage))
|
||||||
}
|
}
|
||||||
|
@ -252,7 +252,7 @@ class ConfigDocumentTest extends TestUtils {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
def configDocumentArrayFailures {
|
def configDocumentArrayFailures {
|
||||||
// Attempting a replace on a ConfigDocument parsed from an array throws an error
|
// Attempting certain methods on a ConfigDocument parsed from an array throws an error
|
||||||
val origText = "[1, 2, 3, 4, 5]"
|
val origText = "[1, 2, 3, 4, 5]"
|
||||||
val document = ConfigDocumentFactory.parseString(origText)
|
val document = ConfigDocumentFactory.parseString(origText)
|
||||||
|
|
||||||
@ -272,16 +272,9 @@ class ConfigDocumentTest extends TestUtils {
|
|||||||
// will fail
|
// will fail
|
||||||
val origText = "{\"foo\": \"bar\", \"baz\": \"qux\"}"
|
val origText = "{\"foo\": \"bar\", \"baz\": \"qux\"}"
|
||||||
val document = ConfigDocumentFactory.parseString(origText, ConfigParseOptions.defaults().setSyntax(ConfigSyntax.JSON))
|
val document = ConfigDocumentFactory.parseString(origText, ConfigParseOptions.defaults().setSyntax(ConfigSyntax.JSON))
|
||||||
var exceptionThrown = false
|
|
||||||
try {
|
val e = intercept[ConfigException] { document.setValue("foo", "unquoted") }
|
||||||
document.setValue("foo", "unquoted")
|
assertTrue(e.getMessage.contains("Token not allowed in valid JSON"))
|
||||||
} catch {
|
|
||||||
case e: Exception =>
|
|
||||||
exceptionThrown = true
|
|
||||||
assertTrue(e.isInstanceOf[ConfigException])
|
|
||||||
assertTrue(e.getMessage.contains("Token not allowed in valid JSON"))
|
|
||||||
}
|
|
||||||
assertTrue(exceptionThrown)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -290,16 +283,9 @@ class ConfigDocumentTest extends TestUtils {
|
|||||||
// fail
|
// fail
|
||||||
val origText = "{\"foo\": \"bar\", \"baz\": \"qux\"}"
|
val origText = "{\"foo\": \"bar\", \"baz\": \"qux\"}"
|
||||||
val document = ConfigDocumentFactory.parseString(origText, ConfigParseOptions.defaults().setSyntax(ConfigSyntax.JSON))
|
val document = ConfigDocumentFactory.parseString(origText, ConfigParseOptions.defaults().setSyntax(ConfigSyntax.JSON))
|
||||||
var exceptionThrown = false
|
|
||||||
try {
|
val e = intercept[ConfigException] { document.setValue("foo", "1 2 3 concatenation") }
|
||||||
document.setValue("foo", "1 2 3 concatenation")
|
assertTrue(e.getMessage.contains("Parsing JSON and the value set in setValue was either a concatenation or had trailing whitespace, newlines, or comments"))
|
||||||
} catch {
|
|
||||||
case e: Exception =>
|
|
||||||
exceptionThrown = true
|
|
||||||
assertTrue(e.isInstanceOf[ConfigException])
|
|
||||||
assertTrue(e.getMessage.contains("Parsing JSON and the value set in setValue was either a concatenation or had trailing whitespace, newlines, or comments"))
|
|
||||||
}
|
|
||||||
assertTrue(exceptionThrown)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -427,7 +413,7 @@ class ConfigDocumentTest extends TestUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
def configDocumentIndentationValueWithIncludeTest {
|
def configDocumentIndentationValueWithInclude {
|
||||||
val origText = "a {\n b {\n c : 22\n }\n}"
|
val origText = "a {\n b {\n c : 22\n }\n}"
|
||||||
val configDocument = ConfigDocumentFactory.parseString(origText)
|
val configDocument = ConfigDocumentFactory.parseString(origText)
|
||||||
|
|
||||||
@ -436,7 +422,7 @@ class ConfigDocumentTest extends TestUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
def configDocumentIndentationBadedOnIncludeNode {
|
def configDocumentIndentationBasedOnIncludeNode {
|
||||||
val origText = "a : b\n include \"foo\"\n"
|
val origText = "a : b\n include \"foo\"\n"
|
||||||
val configDocument = ConfigDocumentFactory.parseString(origText)
|
val configDocument = ConfigDocumentFactory.parseString(origText)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user