Skip to content

Commit

Permalink
Improve code layout for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-yevsyukov committed Nov 17, 2023
1 parent 358fdef commit 7fcadc0
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 16 deletions.
4 changes: 2 additions & 2 deletions java-runtime/src/main/kotlin/io/spine/validate/Diags.kt
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,14 @@ public object Diags {
*/
public object Required {
public const val singularErrorMsg: String = "The field must be set."
public const val collectionErrorMsg: String = "The collection must not be empty.";
public const val collectionErrorMsg: String = "The collection must not be empty."
}

/**
* Messages associated with the `is_required` constraint of `oneof` fields.
*/
public object IsRequired {
public const val operatorDescription: String = "One of the fields must be set.";
public const val operatorDescription: String = "One of the fields must be set."
public fun errorMessage(oneofName: String): String =
"One of the fields in the `$oneofName` group must be set."
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,8 @@ import org.junit.jupiter.api.assertThrows
@Disabled("Until 'skipValidation()` is turned off.")
internal class IfMissingErrorMsgSpec : ValidationOfConstraintTest() {

@Nested
@DisplayName("to obtain custom error message when validating on runtime if")
inner class RuntimeValidation {
@Nested inner class
`to obtain custom error message when validating on runtime if` {

@Test
fun `'Message' field is NOT set`() = assertErrorMessage(
Expand Down Expand Up @@ -86,9 +85,8 @@ internal class IfMissingErrorMsgSpec : ValidationOfConstraintTest() {
}
}

@Nested
@DisplayName("to obtain custom error message when validating on 'build' method")
inner class OnBuild {
@Nested inner class
`to obtain custom error message when validating on 'build' method` {

@Test
fun `'Message' field`() = assertErrorMessage(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,8 @@ internal class AnyValidationSpec : ValidationOfConstraintTest() {
@Test
fun `consider 'Any' valid if validation is not required`() {
val content = AnyPacker.pack(invalidMessage)

val builder = UncheckedAnyContainer.newBuilder().setAny(content)

assertDoesNotThrow { builder.build() }

assertValid(builder.build())
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,18 +99,15 @@ internal class EnclosedMessageValidationSpec : ValidationOfConstraintTest() {
validate(msg)

val violation = singleViolation()

violation.msgFormat shouldBe "The message must have valid properties."

assertFieldPathIs(
violation,
ENCLOSED_FIELD_NAME
)

val innerViolations = violation.violationList
innerViolations shouldHaveSize 1

val innerViolation = innerViolations[0]

innerViolation.msgFormat shouldStartWith Diags.Regex.prefix

assertFieldPathIs(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ internal class GoesSpec : ValidationOfConstraintTest() {
}

@Test
fun `not filled simultaneously` () {
fun `not filled separately` () {
assertNotValid(
payment {
id = paymentId
Expand Down

0 comments on commit 7fcadc0

Please sign in to comment.