Skip to content

Commit

Permalink
Add test case for serializing ValidationFailed
Browse files Browse the repository at this point in the history
  • Loading branch information
iantabolt committed Oct 6, 2017
1 parent 3d44d90 commit 7f14426
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -280,13 +280,13 @@ class ConfigValueTest extends TestUtils {
}

/**
* Reproduces the issue <a href=https://github.com/typesafehub/config/issues/461>#461</a>.
* <p>
* We use a custom de-/serializer that encodes String objects in a JDK-incompatible way. Encoding used here
* is rather simplistic: a long indicating the length in bytes (JDK uses a variable length integer) followed
* by the string's bytes. Running this test with the original SerializedConfigValue.readExternal()
* implementation results in an EOFException thrown during deserialization.
*/
* Reproduces the issue <a href=https://github.com/typesafehub/config/issues/461>#461</a>.
* <p>
* We use a custom de-/serializer that encodes String objects in a JDK-incompatible way. Encoding used here
* is rather simplistic: a long indicating the length in bytes (JDK uses a variable length integer) followed
* by the string's bytes. Running this test with the original SerializedConfigValue.readExternal()
* implementation results in an EOFException thrown during deserialization.
*/
@Test
def configConfigCustomSerializable() {
val aMap = configMap("a" -> 1, "b" -> 2, "c" -> 3)
Expand All @@ -295,7 +295,7 @@ class ConfigValueTest extends TestUtils {

assertEquals(expected, actual)
}

@Test
def configListEquality() {
val aScalaSeq = Seq(1, 2, 3) map { intValue(_): AbstractConfigValue }
Expand Down
10 changes: 5 additions & 5 deletions config/src/test/scala/com/typesafe/config/impl/TestUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ abstract trait TestUtils {
private object notEqualToAnything extends NotEqualToAnythingElse

private def checkNotEqualToRandomOtherThing(a: Any) {
assertFalse(a.equals(notEqualToAnything))
assertFalse(notEqualToAnything.equals(a))
assertFalse("not any", a.equals(notEqualToAnything))
assertFalse("any not", notEqualToAnything.equals(a))
}

protected def checkNotEqualObjects(a: Any, b: Any) {
Expand All @@ -92,9 +92,9 @@ abstract trait TestUtils {
}

protected def checkEqualObjects(a: Any, b: Any) {
assertTrue(a.equals(b))
assertTrue(b.equals(a))
assertTrue(a.hashCode() == b.hashCode())
assertTrue("a equals b", a.equals(b))
assertTrue("b equals a", b.equals(a))
assertTrue("a.hashCode equals b.hashCode", a.hashCode() == b.hashCode())
checkNotEqualToRandomOtherThing(a)
checkNotEqualToRandomOtherThing(b)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,21 @@ class ValidationTest extends TestUtils {
checkValidationException(e, expecteds)
}

@Test
def validationFailedSerializable(): Unit = {
// Reusing a previous test case to generate an error
val reference = parseConfig("""{ a : [{},{},{}] }""")
val conf = parseConfig("""{ a : 42 }""")
val e = intercept[ConfigException.ValidationFailed] {
conf.checkValid(reference)
}

val expecteds = Seq(WrongType("a", 1, "list", "number"))

val actual = checkSerializableNoMeaningfulEquals(e)
checkValidationException(actual, expecteds)
}

@Test
def validationAllowsListOverriddenWithSameTypeList() {
val reference = parseConfig("""{ a : [1,2,3] }""")
Expand Down

0 comments on commit 7f14426

Please sign in to comment.