fix(kanban): address PR correctness and CI regressions (#1137)
This commit is contained in:
1 parent
190a93a4cf
commit
1735de7d9d
25 files changed
+809
-159
No files matched your search
@@ -0,0 +1,68 @@
|
||||
package com.m57.hermescontrol.util
|
||||
|
||||
import android.content.ContentResolver
|
||||
import android.net.Uri
|
||||
import io.mockk.every
|
||||
import io.mockk.mockk
|
||||
import okhttp3.MediaType.Companion.toMediaTypeOrNull
|
||||
import okio.Buffer
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
import java.io.ByteArrayInputStream
|
||||
import java.io.IOException
|
||||
|
||||
class StreamingUriRequestBodyTest {
|
||||
@Test
|
||||
fun testStreamsDirectlyIntoSink() {
|
||||
val testData = "test archive data streaming content".toByteArray(Charsets.UTF_8)
|
||||
val mockResolver = mockk<ContentResolver>()
|
||||
val mockUri = mockk<Uri>()
|
||||
|
||||
every { mockResolver.openInputStream(mockUri) } answers {
|
||||
ByteArrayInputStream(testData)
|
||||
}
|
||||
|
||||
val mediaType = "application/gzip".toMediaTypeOrNull()
|
||||
val requestBody =
|
||||
StreamingUriRequestBody(
|
||||
contentResolver = mockResolver,
|
||||
uri = mockUri,
|
||||
contentType = mediaType,
|
||||
contentLength = testData.size.toLong(),
|
||||
)
|
||||
|
||||
assertEquals(mediaType, requestBody.contentType())
|
||||
assertEquals(testData.size.toLong(), requestBody.contentLength())
|
||||
|
||||
val buffer = Buffer()
|
||||
requestBody.writeTo(buffer)
|
||||
|
||||
assertEquals("test archive data streaming content", buffer.readUtf8())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testThrowsWhenInputStreamCannotBeOpened() {
|
||||
val mockResolver = mockk<ContentResolver>()
|
||||
val mockUri = mockk<Uri>()
|
||||
|
||||
every { mockResolver.openInputStream(mockUri) } returns null
|
||||
|
||||
val requestBody =
|
||||
StreamingUriRequestBody(
|
||||
contentResolver = mockResolver,
|
||||
uri = mockUri,
|
||||
contentType = null,
|
||||
)
|
||||
|
||||
var thrown = false
|
||||
try {
|
||||
val buffer = Buffer()
|
||||
requestBody.writeTo(buffer)
|
||||
} catch (e: IOException) {
|
||||
thrown = true
|
||||
}
|
||||
|
||||
assertTrue(thrown)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user