Skip to content
This repository has been archived by the owner on Jul 19, 2022. It is now read-only.

Commit

Permalink
Release: v1.0.0
Browse files Browse the repository at this point in the history
#Every mock can be disable
#fix HttpStatus code null exception
  • Loading branch information
enciyo committed Jun 24, 2021
1 parent 5dcc342 commit aca1703
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
# Changelog
Added HTTP Methods, Status Code

## v1.0.0
Every mock can be disable
fix HttpStatus code null exception

## v0.0.9
2 changes: 1 addition & 1 deletion flipmock/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ android {
minSdkVersion 21
targetSdkVersion 30
versionCode 1
versionName "0.0.9"
versionName "1.0.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ internal fun FlipperObject.mapMock() = Mock(
dummyJsonData = map("dummyJsonData"),
uniqueId = map("uniqueId"),
queryParams = map("queryParams"),
httpCode = (map<String>("statusCode").toInt()),
requestType = MockRequestMethods.safeValueOf(map("httpMethod"))
httpCode = map("statusCode"),
requestType = MockRequestMethods.safeValueOf(map("httpMethod")),
isMockEnable = map("isMockEnable")
)

internal fun FlipperObject.mapConfig() = Config(
Expand All @@ -55,9 +56,14 @@ internal fun FlipperArray.mapMock(): List<Mock> {
}

inline fun <reified T> FlipperObject.map(param:String) : T{
val result = this[param]
val result = when(T::class.simpleName){
String::class.simpleName -> this.getString(param)
Int::class.simpleName -> this.getInt(param)
Boolean::class.simpleName -> this.getBoolean(param)
else-> throw NotSerializableException("$param expected ${T::class.simpleName} but return ${this[param]} ${this[param]::class.simpleName}")
}
if (result as? T == null){
throw NotSerializableException("$param expected ${T::class.simpleName} but return $result")
throw NotSerializableException("$param expected ${T::class.simpleName} but return $result ${result::class.simpleName}")
}
return result
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ internal class MockInterceptor(private val management: MockManagement) : FlipMoc
val isLoggable = management.config.isLoggable
if (isMockEnable) {
val existMock = management.findFirstOrNullMock(request.mapMock())
if (existMock != null) {
if (existMock != null && existMock.isMockEnable) {
if (isLoggable) log(existMock)
return existMock.mapResponseBody(request)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ internal data class Mock @JvmOverloads constructor(
val httpCode: Int = HttpURLConnection.HTTP_OK, // Feature
val requestType: MockRequestMethods? = null, // Feature
val contentTypes: MockContentTypes = MockContentTypes.JSON, // Feature
val isMockEnable: Boolean = true
)

internal fun Mock.isSameEndpoint(outMock: Mock) =
Expand All @@ -27,7 +28,6 @@ internal fun Mock.isSameMock(outMock: Mock) =
(if (queryParams.isEmpty()) true else queryParams == outMock.queryParams) && isSameRequestType(outMock)



internal fun Mock.isSameRequestType(outMock: Mock) =
requestType == null ||
outMock.requestType == requestType

0 comments on commit aca1703

Please sign in to comment.