From 546f2faf3ad2aeb4eb7dc52c5d04ea87efc93282 Mon Sep 17 00:00:00 2001 From: az Date: Wed, 30 Nov 2022 09:56:15 +0100 Subject: [PATCH] [skip ci] add tests DefaultConfigFileRepository.kt --- .../DefaultConfigFileRepository.kt | 2 +- .../DefaultApplicationFileRepositoryKtTest.kt | 16 ++++---- .../DefaultConfigFileRepositoryKtTest.kt | 41 +++++++++++++++++++ 3 files changed, 50 insertions(+), 9 deletions(-) create mode 100644 src/test/kotlin/org/domaindrivenarchitecture/provs/server/infrastructure/DefaultConfigFileRepositoryKtTest.kt diff --git a/src/main/kotlin/org/domaindrivenarchitecture/provs/configuration/infrastructure/DefaultConfigFileRepository.kt b/src/main/kotlin/org/domaindrivenarchitecture/provs/configuration/infrastructure/DefaultConfigFileRepository.kt index a228ec1..b08f3d6 100644 --- a/src/main/kotlin/org/domaindrivenarchitecture/provs/configuration/infrastructure/DefaultConfigFileRepository.kt +++ b/src/main/kotlin/org/domaindrivenarchitecture/provs/configuration/infrastructure/DefaultConfigFileRepository.kt @@ -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.") } } } diff --git a/src/test/kotlin/org/domaindrivenarchitecture/provs/server/infrastructure/DefaultApplicationFileRepositoryKtTest.kt b/src/test/kotlin/org/domaindrivenarchitecture/provs/server/infrastructure/DefaultApplicationFileRepositoryKtTest.kt index 86c1123..eb57bd6 100644 --- a/src/test/kotlin/org/domaindrivenarchitecture/provs/server/infrastructure/DefaultApplicationFileRepositoryKtTest.kt +++ b/src/test/kotlin/org/domaindrivenarchitecture/provs/server/infrastructure/DefaultApplicationFileRepositoryKtTest.kt @@ -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( @@ -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 diff --git a/src/test/kotlin/org/domaindrivenarchitecture/provs/server/infrastructure/DefaultConfigFileRepositoryKtTest.kt b/src/test/kotlin/org/domaindrivenarchitecture/provs/server/infrastructure/DefaultConfigFileRepositoryKtTest.kt new file mode 100644 index 0000000..91b2981 --- /dev/null +++ b/src/test/kotlin/org/domaindrivenarchitecture/provs/server/infrastructure/DefaultConfigFileRepositoryKtTest.kt @@ -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( + "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 + } +} \ No newline at end of file