Skip to content

Commit

Permalink
[FEAT] DDMock now allows returning of any content type by filename ex…
Browse files Browse the repository at this point in the history
…tension (if you add the content type key to MockEntry INIT )
  • Loading branch information
David Sawick authored and David Sawick committed Jul 24, 2020
1 parent db1d988 commit 2b9bfac
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 6 deletions.
3 changes: 1 addition & 2 deletions ddmock/src/main/java/com/dd/DDMock.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.dd

import android.app.Application
import android.content.res.AssetManager
import android.util.Log
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
Expand Down Expand Up @@ -41,7 +40,7 @@ object DDMock {
if (result.contains(key)) {
result[key]?.files?.add(fullFilePath)
} else {
result[key] = com.dd.MockEntry(key, arrayListOf(fullFilePath), mediaType2 = getMediaType(extension))
result[key] = com.dd.MockEntry(key, arrayListOf(fullFilePath), mediaType = getMediaType(extension))
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions ddmock/src/main/java/com/dd/MockEntry.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ class MockEntry(
var selectedFile: Int = 0,
var statusCode: Int = HttpURLConnection.HTTP_OK,
var responseTime: Long = DEFAULT_MOCK_RESPONSE_DELAY_MS,
var mediaType2: MediaType?
var mediaType: MediaType?
) {
companion object {
const val CONTENT_TYPE_APPLICATION_JSON = "application/json; charset=utf-8"
const val CONTENT_TYPE_APPLICATION_PDF = "application/pdf; charset=utf-8"
}
val mediaType = MediaType.parse(CONTENT_TYPE_APPLICATION_JSON)
}
4 changes: 2 additions & 2 deletions ddmock/src/main/java/com/dd/MockInterceptor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ class MockInterceptor : Interceptor {
.message("MOCK")
.header(
"Content-Type",
if (mockEntry.mediaType2 != null) mockEntry.mediaType2.toString() else MockEntry.CONTENT_TYPE_APPLICATION_JSON
if (mockEntry.mediaType != null) mockEntry.mediaType.toString() else MockEntry.CONTENT_TYPE_APPLICATION_JSON
)
.request(request)
.body(ResponseBody.create(mockEntry.mediaType2, buffer.size(), buffer))
.body(ResponseBody.create(mockEntry.mediaType, buffer.size(), buffer))
.build()
}
}

0 comments on commit 2b9bfac

Please sign in to comment.