From 211fdb18959b73f8b38c91e8829a573f57958768 Mon Sep 17 00:00:00 2001 From: FyloZ Date: Thu, 8 Apr 2021 17:23:44 -0400 Subject: [PATCH] Corrections des tests de FileService --- .../service/files/FileServiceTest.kt | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/test/kotlin/dev/fyloz/colorrecipesexplorer/service/files/FileServiceTest.kt b/src/test/kotlin/dev/fyloz/colorrecipesexplorer/service/files/FileServiceTest.kt index bc1b1db..756d7de 100644 --- a/src/test/kotlin/dev/fyloz/colorrecipesexplorer/service/files/FileServiceTest.kt +++ b/src/test/kotlin/dev/fyloz/colorrecipesexplorer/service/files/FileServiceTest.kt @@ -11,6 +11,7 @@ import org.springframework.web.multipart.MultipartFile import java.io.File import java.io.IOException import java.io.InputStream +import java.nio.file.Paths import kotlin.test.assertEquals import kotlin.test.assertFalse import kotlin.test.assertTrue @@ -80,13 +81,15 @@ class FileServiceTest { @Test fun `write() transfers data from the given MultipartFile to the file at the given path and returns true`() { withMultipartFile { multipartFile -> - val file = File(path) + val file = mock() + val filePath = Paths.get(path) + whenever(file.toPath()).doReturn(filePath) doAnswer { file }.whenever(service).create(path) assertTrue { service.write(multipartFile, path) } - verify(multipartFile).transferTo(file) + verify(multipartFile).transferTo(filePath) } } @@ -102,10 +105,12 @@ class FileServiceTest { @Test fun `write() returns false when the data transfer throw an IOException`() { withMultipartFile { multipartFile -> - val file = File(path) + val file = mock() + val filePath = Paths.get(path) + whenever(file.toPath()).doReturn(filePath) + whenever(multipartFile.transferTo(filePath)).doThrow(IOException()) doAnswer { file }.whenever(service).create(path) - whenever(multipartFile.transferTo(file)).doThrow(IOException()) assertFalse { service.write(multipartFile, path) } }