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

@ -14,7 +14,7 @@ class ConfigDocumentParserTest extends TestUtils {
private def parseJSONFailuresTest(origText: String, containsMessage: String) {
var exceptionThrown = false
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))
}

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,16 +272,9 @@ 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])
assertTrue(e.getMessage.contains("Token not allowed in valid JSON"))
}
assertTrue(exceptionThrown)
val e = intercept[ConfigException] { document.setValue("foo", "unquoted") }
assertTrue(e.getMessage.contains("Token not allowed in valid JSON"))
}
@Test
@ -290,16 +283,9 @@ 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])
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)
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"))
}
@Test
@ -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)