Skip to content

Commit

Permalink
Migrate tests from DynaTest to JUnit5
Browse files Browse the repository at this point in the history
  • Loading branch information
mvysny committed Jan 31, 2025
1 parent ba7a56a commit 98b869c
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions src/test/kotlin/com/github/vokorm/ValidationTest.kt
Original file line number Diff line number Diff line change
@@ -1,32 +1,31 @@
package com.github.vokorm

import com.github.mvysny.dynatest.DynaTest
import com.github.mvysny.dynatest.expectThrows
import com.gitlab.mvysny.jdbiorm.Entity
import jakarta.validation.ValidationException
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertThrows
import kotlin.test.expect
import kotlin.test.fail

class ValidationTest : DynaTest({
class ValidationTest : AbstractH2DatabaseTest() {
// this is not really testing the database: we're testing Entity.validate().
// Therefore, it's enough to run this battery on H2 only.
usingH2Database()
test("Validation on empty name fails") {
expectThrows(ValidationException::class) {
@Test fun `Validation on empty name fails`() {
assertThrows<ValidationException> {
Person(name = "", age = 20).validate()
}
expect(false) { Person(name = "", age = 20).isValid }
}
test("Validation on non-empty name succeeds") {
@Test fun `Validation on non-empty name succeeds`() {
Person(name = "Valid Name", age = 20).validate()
expect(true) { Person(name = "Valid Name", age = 20).isValid }
}
test("save() fails when the bean is invalid") {
expectThrows(ValidationException::class, "name: length must be between 1 and 2147483647") {
@Test fun `save() fails when the bean is invalid`() {
expectThrows<ValidationException>("name: length must be between 1 and 2147483647") {
Person(name = "", age = 20).save()
}
}
test("validation is skipped when save(false) is called") {
@Test fun `validation is skipped when save(false) is called`() {
data class ValidationAlwaysFails(private var id: Long?) : Entity<Long> {
override fun setId(id: Long?) { this.id = id }
override fun getId(): Long? = id
Expand All @@ -35,4 +34,4 @@ class ValidationTest : DynaTest({
db { ddl("create table ValidationAlwaysFails ( id bigint primary key auto_increment )") }
ValidationAlwaysFails(null).save(false)
}
})
}

0 comments on commit 98b869c

Please sign in to comment.