[skip ci] add tests DefaultConfigFileRepository.kt

This commit is contained in:
az 2022-11-30 09:56:15 +01:00
parent 0ef50ea233
commit 546f2faf3a
3 changed files with 50 additions and 9 deletions

View file

@ -8,7 +8,7 @@ class DefaultConfigFileRepository : ConfigFileRepository {
override fun assertExists(configFileName: ConfigFileName?) {
if (configFileName != null && !checkLocalFile(configFileName.fullqualified())) {
throw RuntimeException("Application file ${configFileName.fileName} not found. Please check if path is correct.")
throw RuntimeException("Config file ${configFileName.fileName} not found. Please check if path is correct.")
}
}
}

View file

@ -1,10 +1,10 @@
package org.domaindrivenarchitecture.provs.server.infrastructure
import org.domaindrivenarchitecture.provs.server.domain.k3s.ApplicationFileName
import org.domaindrivenarchitecture.provs.server.domain.k3s.ApplicationFileRepository
import org.domaindrivenarchitecture.provs.configuration.domain.ConfigFileName
import org.domaindrivenarchitecture.provs.configuration.infrastructure.DefaultConfigFileRepository
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertThrows
import org.junit.jupiter.api.Assertions.assertEquals
import java.io.File
internal class DefaultApplicationFileRepositoryKtTest {
@ -12,8 +12,8 @@ internal class DefaultApplicationFileRepositoryKtTest {
@Test
fun assertExistsThrowsRuntimeException() {
// when
val invalidFileName = ApplicationFileName("iDontExist")
val repo: ApplicationFileRepository = DefaultApplicationFileRepository()
val invalidFileName = ConfigFileName("iDontExist")
val repo = DefaultConfigFileRepository()
// then
val exception = assertThrows<RuntimeException>(
@ -21,7 +21,7 @@ internal class DefaultApplicationFileRepositoryKtTest {
) { repo.assertExists(invalidFileName) }
assertEquals(
"Application file iDontExist not found. Please check if path is correct.",
"Config file iDontExist not found. Please check if path is correct.",
exception.message)
}
@ -31,8 +31,8 @@ internal class DefaultApplicationFileRepositoryKtTest {
val validFileName = "src/test/resources/existing_file"
// when
val validFile = ApplicationFileName(File(validFileName).path)
val repo: ApplicationFileRepository = DefaultApplicationFileRepository()
val validFile = ConfigFileName(File(validFileName).path)
val repo = DefaultConfigFileRepository()
repo.assertExists(validFile)
// then

View file

@ -0,0 +1,41 @@
package org.domaindrivenarchitecture.provs.server.infrastructure
import org.domaindrivenarchitecture.provs.server.domain.k3s.ApplicationFileName
import org.domaindrivenarchitecture.provs.server.domain.k3s.ApplicationFileRepository
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertThrows
import org.junit.jupiter.api.Assertions.assertEquals
import java.io.File
internal class DefaultConfigFileRepositoryKtTest {
@Test
fun assertExistsThrowsRuntimeException() {
// when
val invalidFileName = ApplicationFileName("iDontExist")
val repo: ApplicationFileRepository = DefaultApplicationFileRepository()
// then
val exception = assertThrows<RuntimeException>(
"Should not find the file."
) { repo.assertExists(invalidFileName) }
assertEquals(
"Application file iDontExist not found. Please check if path is correct.",
exception.message)
}
@Test
fun assertExistsPasses() {
// given
val validFileName = "src/test/resources/existing_file"
// when
val validFile = ApplicationFileName(File(validFileName).path)
val repo: ApplicationFileRepository = DefaultApplicationFileRepository()
repo.assertExists(validFile)
// then
// no exception is thrown
}
}