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:
Preben Ingvaldsen 2015-04-07 14:09:21 -07:00
parent 6c011b5e4a
commit c2b2c10d38
2 changed files with 10 additions and 24 deletions

View File

@ -252,7 +252,7 @@ class ConfigDocumentTest extends TestUtils {
@Test
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 document = ConfigDocumentFactory.parseString(origText)
@ -272,17 +272,10 @@ class ConfigDocumentTest extends TestUtils {
// will fail
val origText = "{\"foo\": \"bar\", \"baz\": \"qux\"}"
val document = ConfigDocumentFactory.parseString(origText, ConfigParseOptions.defaults().setSyntax(ConfigSyntax.JSON))
var exceptionThrown = false
try {
document.setValue("foo", "unquoted")
} catch {
case e: Exception =>
exceptionThrown = true
assertTrue(e.isInstanceOf[ConfigException])
val e = intercept[ConfigException] { document.setValue("foo", "unquoted") }
assertTrue(e.getMessage.contains("Token not allowed in valid JSON"))
}
assertTrue(exceptionThrown)
}
@Test
def configDocumentJSONReplaceWithConcatenationFailure {
@ -290,17 +283,10 @@ class ConfigDocumentTest extends TestUtils {
// fail
val origText = "{\"foo\": \"bar\", \"baz\": \"qux\"}"
val document = ConfigDocumentFactory.parseString(origText, ConfigParseOptions.defaults().setSyntax(ConfigSyntax.JSON))
var exceptionThrown = false
try {
document.setValue("foo", "1 2 3 concatenation")
} catch {
case e: Exception =>
exceptionThrown = true
assertTrue(e.isInstanceOf[ConfigException])
val e = intercept[ConfigException] { 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"))
}
assertTrue(exceptionThrown)
}
@Test
def configDocumentFileParse {
@ -427,7 +413,7 @@ class ConfigDocumentTest extends TestUtils {
}
@Test
def configDocumentIndentationValueWithIncludeTest {
def configDocumentIndentationValueWithInclude {
val origText = "a {\n b {\n c : 22\n }\n}"
val configDocument = ConfigDocumentFactory.parseString(origText)
@ -436,7 +422,7 @@ class ConfigDocumentTest extends TestUtils {
}
@Test
def configDocumentIndentationBadedOnIncludeNode {
def configDocumentIndentationBasedOnIncludeNode {
val origText = "a : b\n include \"foo\"\n"
val configDocument = ConfigDocumentFactory.parseString(origText)