Refactor validation tests to use test subject property

This commit is contained in:
Wolf-Martell Montwé 2023-06-15 18:09:57 +02:00
parent d04a91f566
commit 8a3cb578e7
No known key found for this signature in database
GPG key ID: 6D45B21512ACBF72
10 changed files with 57 additions and 111 deletions

View file

@ -9,29 +9,25 @@ import org.junit.Test
class ValidateAccountNameTest {
private val testSubject = ValidateAccountName()
@Test
fun `should succeed when account name is set`() {
val useCase = ValidateAccountName()
val result = useCase.execute("account name")
val result = testSubject.execute("account name")
assertThat(result).isInstanceOf(ValidationResult.Success::class)
}
@Test
fun `should succeed when account name is empty`() {
val useCase = ValidateAccountName()
val result = useCase.execute("")
val result = testSubject.execute("")
assertThat(result).isInstanceOf(ValidationResult.Success::class)
}
@Test
fun `should fail when account name is blank`() {
val useCase = ValidateAccountName()
val result = useCase.execute(" ")
val result = testSubject.execute(" ")
assertThat(result).isInstanceOf(ValidationResult.Failure::class)
.prop(ValidationResult.Failure::error)

View file

@ -8,38 +8,32 @@ import org.junit.Test
class ValidateConfigurationApprovalTest {
private val testSubject = ValidateConfigurationApproval()
@Test
fun `should succeed when auto discovery is approved and trusted`() {
val useCase = ValidateConfigurationApproval()
val result = useCase.execute(isApproved = true, isAutoDiscoveryTrusted = true)
val result = testSubject.execute(isApproved = true, isAutoDiscoveryTrusted = true)
assertThat(result).isInstanceOf(ValidationResult.Success::class)
}
@Test
fun `should succeed when auto discovery not approved but is trusted`() {
val useCase = ValidateConfigurationApproval()
val result = useCase.execute(isApproved = false, isAutoDiscoveryTrusted = true)
val result = testSubject.execute(isApproved = false, isAutoDiscoveryTrusted = true)
assertThat(result).isInstanceOf(ValidationResult.Success::class)
}
@Test
fun `should succeed when auto discovery is approved but not trusted`() {
val useCase = ValidateConfigurationApproval()
val result = useCase.execute(isApproved = true, isAutoDiscoveryTrusted = false)
val result = testSubject.execute(isApproved = true, isAutoDiscoveryTrusted = false)
assertThat(result).isInstanceOf(ValidationResult.Success::class)
}
@Test
fun `should fail when auto discovery is not approved and not trusted`() {
val useCase = ValidateConfigurationApproval()
val result = useCase.execute(isApproved = false, isAutoDiscoveryTrusted = false)
val result = testSubject.execute(isApproved = false, isAutoDiscoveryTrusted = false)
assertThat(result).isInstanceOf(ValidationResult.Failure::class)
.prop(ValidationResult.Failure::error)
@ -48,18 +42,14 @@ class ValidateConfigurationApprovalTest {
@Test
fun `should succeed when auto discovery isApproved null and is trusted`() {
val useCase = ValidateConfigurationApproval()
val result = useCase.execute(isApproved = null, isAutoDiscoveryTrusted = true)
val result = testSubject.execute(isApproved = null, isAutoDiscoveryTrusted = true)
assertThat(result).isInstanceOf(ValidationResult.Success::class)
}
@Test
fun `should fail when auto discovery is isApproved null and is not trusted`() {
val useCase = ValidateConfigurationApproval()
val result = useCase.execute(isApproved = null, isAutoDiscoveryTrusted = false)
val result = testSubject.execute(isApproved = null, isAutoDiscoveryTrusted = false)
assertThat(result).isInstanceOf(ValidationResult.Failure::class)
.prop(ValidationResult.Failure::error)
@ -68,9 +58,7 @@ class ValidateConfigurationApprovalTest {
@Test
fun `should fail when auto discovery is approved and trusted is null`() {
val useCase = ValidateConfigurationApproval()
val result = useCase.execute(isApproved = false, isAutoDiscoveryTrusted = null)
val result = testSubject.execute(isApproved = false, isAutoDiscoveryTrusted = null)
assertThat(result).isInstanceOf(ValidationResult.Failure::class)
.prop(ValidationResult.Failure::error)
@ -79,9 +67,7 @@ class ValidateConfigurationApprovalTest {
@Test
fun `should fail when auto discovery is not approved and trusted is null`() {
val useCase = ValidateConfigurationApproval()
val result = useCase.execute(isApproved = false, isAutoDiscoveryTrusted = null)
val result = testSubject.execute(isApproved = false, isAutoDiscoveryTrusted = null)
assertThat(result).isInstanceOf(ValidationResult.Failure::class)
.prop(ValidationResult.Failure::error)

View file

@ -9,20 +9,18 @@ import org.junit.Test
class ValidateDisplayNameTest {
private val testSubject = ValidateDisplayName()
@Test
fun `should succeed when display name is set`() {
val useCase = ValidateDisplayName()
val result = useCase.execute("display name")
val result = testSubject.execute("display name")
assertThat(result).isInstanceOf(ValidationResult.Success::class)
}
@Test
fun `should fail when display name is empty`() {
val useCase = ValidateDisplayName()
val result = useCase.execute("")
val result = testSubject.execute("")
assertThat(result).isInstanceOf(ValidationResult.Failure::class)
.prop(ValidationResult.Failure::error)
@ -31,9 +29,7 @@ class ValidateDisplayNameTest {
@Test
fun `should fail when display name is blank`() {
val useCase = ValidateDisplayName()
val result = useCase.execute(" ")
val result = testSubject.execute(" ")
assertThat(result).isInstanceOf(ValidationResult.Failure::class)
.prop(ValidationResult.Failure::error)

View file

@ -9,20 +9,18 @@ import org.junit.Test
class ValidateEmailAddressTest {
private val testSubject = ValidateEmailAddress()
@Test
fun `should succeed when email address is valid`() {
val useCase = ValidateEmailAddress()
val result = useCase.execute("test@example.com")
val result = testSubject.execute("test@example.com")
assertThat(result).isInstanceOf(ValidationResult.Success::class)
}
@Test
fun `should fail when email address is blank`() {
val useCase = ValidateEmailAddress()
val result = useCase.execute(" ")
val result = testSubject.execute(" ")
assertThat(result).isInstanceOf(ValidationResult.Failure::class)
.prop(ValidationResult.Failure::error)
@ -31,9 +29,7 @@ class ValidateEmailAddressTest {
@Test
fun `should fail when email address is invalid`() {
val useCase = ValidateEmailAddress()
val result = useCase.execute("test")
val result = testSubject.execute("test")
assertThat(result).isInstanceOf(ValidationResult.Failure::class)
.prop(ValidationResult.Failure::error)

View file

@ -9,29 +9,25 @@ import org.junit.Test
class ValidateEmailSignatureTest {
private val testSubject = ValidateEmailSignature()
@Test
fun `should succeed when email signature is set`() {
val useCase = ValidateEmailSignature()
val result = useCase.execute("email signature")
val result = testSubject.execute("email signature")
assertThat(result).isInstanceOf(ValidationResult.Success::class)
}
@Test
fun `should succeed when email signature is empty`() {
val useCase = ValidateEmailSignature()
val result = useCase.execute("")
val result = testSubject.execute("")
assertThat(result).isInstanceOf(ValidationResult.Success::class)
}
@Test
fun `should fail when email signature is blank`() {
val useCase = ValidateEmailSignature()
val result = useCase.execute(" ")
val result = testSubject.execute(" ")
assertThat(result).isInstanceOf(ValidationResult.Failure::class)
.prop(ValidationResult.Failure::error)

View file

@ -8,29 +8,25 @@ import org.junit.Test
class ValidateImapPrefixTest {
private val testSubject = ValidateImapPrefix()
@Test
fun `should success when imap prefix is set`() {
val useCase = ValidateImapPrefix()
val result = useCase.execute("imap")
val result = testSubject.execute("imap")
assertThat(result).isInstanceOf(ValidationResult.Success::class)
}
@Test
fun `should succeed when imap prefix is empty`() {
val useCase = ValidateImapPrefix()
val result = useCase.execute("")
val result = testSubject.execute("")
assertThat(result).isInstanceOf(ValidationResult.Success::class)
}
@Test
fun `should fail when imap prefix is blank`() {
val useCase = ValidateImapPrefix()
val result = useCase.execute(" ")
val result = testSubject.execute(" ")
assertThat(result).isInstanceOf(ValidationResult.Failure::class)
.prop(ValidationResult.Failure::error)

View file

@ -8,20 +8,18 @@ import org.junit.Test
class ValidatePasswordTest {
private val testSubject = ValidatePassword()
@Test
fun `should succeed when password is set`() {
val useCase = ValidatePassword()
val result = useCase.execute("password")
val result = testSubject.execute("password")
assertThat(result).isInstanceOf(ValidationResult.Success::class)
}
@Test
fun `should fail when password is empty`() {
val useCase = ValidatePassword()
val result = useCase.execute("")
val result = testSubject.execute("")
assertThat(result).isInstanceOf(ValidationResult.Failure::class)
.prop(ValidationResult.Failure::error)
@ -30,9 +28,7 @@ class ValidatePasswordTest {
@Test
fun `should fail when password is blank`() {
val useCase = ValidatePassword()
val result = useCase.execute(" ")
val result = testSubject.execute(" ")
assertThat(result).isInstanceOf(ValidationResult.Failure::class)
.prop(ValidationResult.Failure::error)

View file

@ -9,20 +9,18 @@ import org.junit.Test
class ValidatePortTest {
private val testSubject = ValidatePort()
@Test
fun `should succeed when port is set`() {
val useCase = ValidatePort()
val result = useCase.execute(123L)
val result = testSubject.execute(123L)
assertThat(result).isInstanceOf(ValidationResult.Success::class)
}
@Test
fun `should fail when port is negative`() {
val useCase = ValidatePort()
val result = useCase.execute(-1L)
val result = testSubject.execute(-1L)
assertThat(result).isInstanceOf(ValidationResult.Failure::class)
.prop(ValidationResult.Failure::error)
@ -31,9 +29,7 @@ class ValidatePortTest {
@Test
fun `should fail when port is zero`() {
val useCase = ValidatePort()
val result = useCase.execute(0)
val result = testSubject.execute(0)
assertThat(result).isInstanceOf(ValidationResult.Failure::class)
.prop(ValidationResult.Failure::error)
@ -42,9 +38,7 @@ class ValidatePortTest {
@Test
fun `should fail when port exceeds maximum`() {
val useCase = ValidatePort()
val result = useCase.execute(65536L)
val result = testSubject.execute(65536L)
assertThat(result).isInstanceOf(ValidationResult.Failure::class)
.prop(ValidationResult.Failure::error)
@ -53,9 +47,7 @@ class ValidatePortTest {
@Test
fun `should fail when port is null`() {
val useCase = ValidatePort()
val result = useCase.execute(null)
val result = testSubject.execute(null)
assertThat(result).isInstanceOf(ValidationResult.Failure::class)
.prop(ValidationResult.Failure::error)

View file

@ -8,20 +8,18 @@ import org.junit.Test
class ValidateServerTest {
private val testSubject = ValidateServer()
@Test
fun `should succeed when server is set`() {
val useCase = ValidateServer()
val result = useCase.execute("server")
val result = testSubject.execute("server")
assertThat(result).isInstanceOf(ValidationResult.Success::class)
}
@Test
fun `should fail when server is empty`() {
val useCase = ValidateServer()
val result = useCase.execute("")
val result = testSubject.execute("")
assertThat(result).isInstanceOf(ValidationResult.Failure::class)
.prop(ValidationResult.Failure::error)
@ -30,9 +28,7 @@ class ValidateServerTest {
@Test
fun `should fail when server is blank`() {
val useCase = ValidateServer()
val result = useCase.execute(" ")
val result = testSubject.execute(" ")
assertThat(result).isInstanceOf(ValidationResult.Failure::class)
.prop(ValidationResult.Failure::error)

View file

@ -8,20 +8,18 @@ import org.junit.Test
class ValidateUsernameTest {
private val testSubject = ValidateUsername()
@Test
fun `should succeed when username is set`() {
val useCase = ValidateUsername()
val result = useCase.execute("username")
val result = testSubject.execute("username")
assertThat(result).isInstanceOf(ValidationResult.Success::class)
}
@Test
fun `should fail when username is empty`() {
val useCase = ValidateUsername()
val result = useCase.execute("")
val result = testSubject.execute("")
assertThat(result).isInstanceOf(ValidationResult.Failure::class)
.prop(ValidationResult.Failure::error)
@ -30,9 +28,7 @@ class ValidateUsernameTest {
@Test
fun `should fail when username is blank`() {
val useCase = ValidateUsername()
val result = useCase.execute(" ")
val result = testSubject.execute(" ")
assertThat(result).isInstanceOf(ValidationResult.Failure::class)
.prop(ValidationResult.Failure::error)