Corrections des tests de FileService
This commit is contained in:
parent
f3d1230e75
commit
211fdb1895
|
@ -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<File>()
|
||||
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<File>()
|
||||
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) }
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue