Skip to content

Commit

Permalink
Merge pull request #34 from speekha/develop
Browse files Browse the repository at this point in the history
Publish 1.1.5
  • Loading branch information
speekha authored Jul 17, 2019
2 parents 5a27eb7 + e2eea39 commit 4c88b2b
Show file tree
Hide file tree
Showing 40 changed files with 782 additions and 499 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ hs_err_pid*
build
.idea
*.iml
local.properties

# Ignore Gradle GUI config
gradle-app.setting
Expand Down
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ configuration files instead. The interceptor will also allow to record scenarios
## Current Version

```gradle
httpmocker_version = '1.1.4'
httpmocker_version = '1.1.5'
```

## Gradle
Expand Down Expand Up @@ -55,27 +55,27 @@ you need to add is the corresponding

```gradle
// Parses JSON scenarios using Jackson
implementation "fr.speekha.httpmocker:jackson-adapter:1.1.4"
implementation "fr.speekha.httpmocker:jackson-adapter:1.1.5"
// Parses JSON scenarios using Gson
implementation "fr.speekha.httpmocker:gson-adapter:1.1.4"
implementation "fr.speekha.httpmocker:gson-adapter:1.1.5"
// Parses JSON scenarios using Moshi
implementation "fr.speekha.httpmocker:moshi-adapter:1.1.4"
implementation "fr.speekha.httpmocker:moshi-adapter:1.1.5"
// Parses JSON scenarios using Kotlinx Serialization
implementation "fr.speekha.httpmocker:kotlinx-adapter:1.1.4"
implementation "fr.speekha.httpmocker:kotlinx-adapter:1.1.5"
// Parses JSON scenarios using a custom JSON parser
implementation "fr.speekha.httpmocker:custom-adapter:1.1.4"
implementation "fr.speekha.httpmocker:custom-adapter:1.1.5"
```

If none of those options suits your needs or if you would prefer to only use dynamic mocks, you can add
the main dependency to your project (using static mocks will require that you provide your own implementation
of the `Mapper` class):

```gradle
implementation "fr.speekha.httpmocker:mocker:1.1.4"
implementation "fr.speekha.httpmocker:mocker:1.1.5"
```

#### External dependencies
Expand Down
4 changes: 0 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ buildscript {

allprojects {

ext {
httpmock_version = '1.1.4'
}

group 'fr.speekha.httpmocker'
version "$httpmock_version" + (Boolean.valueOf(System.getProperty("snapshot")) ? "-SNAPSHOT" : "")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ internal fun Matcher.toJson(): String = """ {
"""

internal fun RequestDescriptor.toJson(): String = listOf(
"protocol" to protocol.wrap(),
"method" to method.wrap(),
"host" to host.wrap(),
"port" to port.wrap(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ internal class RequestAdapter : BaseObjectAdapter<RequestDescriptor>() {
reader: JsonStringReader,
builder: RequestDescriptor
): RequestDescriptor = when (val field = reader.readFieldName()) {
"protocol" -> builder.copy(protocol = reader.readString())
"method" -> builder.copy(method = reader.readString())
"port" -> builder.copy(port = reader.readInt())
"host" -> builder.copy(host = reader.readString())
Expand Down
13 changes: 7 additions & 6 deletions demo/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ apply plugin: 'kotlin-android-extensions'


android {
compileSdkVersion 28
compileSdkVersion 29
sourceSets {
main.kotlin.srcDirs += 'src/main/kotlin'
}
defaultConfig {
applicationId "fr.speekha.httpmocker.demo"
minSdkVersion 21
targetSdkVersion 28
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
Expand Down Expand Up @@ -61,14 +61,15 @@ dependencies {
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutines_version"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$coroutines_version"

implementation "com.android.support:appcompat-v7:$support_version"
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation "com.android.support:design:$support_version"
implementation "androidx.appcompat:appcompat:$support_version"
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'androidx.recyclerview:recyclerview:1.0.0'
implementation 'com.google.android.material:material:1.1.0-alpha08'

implementation "com.squareup.retrofit2:retrofit:$retrofit_version"
implementation "com.squareup.retrofit2:converter-jackson:$retrofit_version"

implementation 'org.koin:koin-android:2.0.1'
implementation "org.koin:koin-android:2.0.1"
implementation "org.slf4j:slf4j-android:$slf4j_version"

//implementation "fr.speekha.httpmocker:jackson-adapter:$httpmock_version"
Expand Down
36 changes: 21 additions & 15 deletions demo/src/main/java/fr/speekha/httpmocker/demo/ui/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,15 @@

package fr.speekha.httpmocker.demo.ui

import android.Manifest.permission.*
import android.Manifest.permission.WRITE_EXTERNAL_STORAGE
import android.content.pm.PackageManager
import android.os.Build
import android.os.Bundle
import android.support.v4.app.ActivityCompat
import android.support.v7.app.AppCompatActivity
import android.support.v7.widget.LinearLayoutManager
import androidx.annotation.IntegerRes
import androidx.appcompat.app.AppCompatActivity
import androidx.core.app.ActivityCompat
import androidx.recyclerview.widget.LinearLayoutManager
import fr.speekha.httpmocker.MockResponseInterceptor
import fr.speekha.httpmocker.demo.R
import fr.speekha.httpmocker.demo.model.Repo
import kotlinx.android.synthetic.main.activity_main.*
Expand All @@ -39,15 +41,19 @@ class MainActivity : AppCompatActivity(), MainContract.View {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

radioState.setOnCheckedChangeListener { _, checkedId ->
presenter.setMode(
when (checkedId) {
R.id.stateEnabled -> 1
R.id.stateMixed -> 2
R.id.stateRecord -> 3
else -> 0
}
)
radioState.addOnButtonCheckedListener { _, checkedId, isChecked ->
if (isChecked) {
presenter.setMode(
when (checkedId) {
R.id.stateEnabled -> MockResponseInterceptor.Mode.ENABLED
R.id.stateMixed -> MockResponseInterceptor.Mode.MIXED
R.id.stateRecord -> MockResponseInterceptor.Mode.RECORD
else -> MockResponseInterceptor.Mode.DISABLED
}
)
} else {
if (-1 == radioState.checkedButtonId) radioState.check(R.id.stateDisabled)
}
}

btnCall.setOnClickListener {
Expand Down Expand Up @@ -80,7 +86,7 @@ class MainActivity : AppCompatActivity(), MainContract.View {
}
}

override fun updateStorageLabel(enabled: Boolean) {
tvDirectory.isEnabled = enabled
override fun updateDescriptionLabel(@IntegerRes resId: Int) {
tvMessage.setText(resId)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package fr.speekha.httpmocker.demo.ui

import androidx.annotation.IntegerRes
import fr.speekha.httpmocker.MockResponseInterceptor
import fr.speekha.httpmocker.demo.model.Repo

interface MainContract {
Expand All @@ -24,12 +26,12 @@ interface MainContract {
fun setResult(result: List<Repo>)
fun setError(message: String?)
fun checkPermission()
fun updateStorageLabel(enabled: Boolean)
fun updateDescriptionLabel(@IntegerRes resId: Int)
}

interface Presenter {
fun stop()
fun callService()
fun setMode(mode: Int)
fun setMode(mode: MockResponseInterceptor.Mode)
}
}
35 changes: 24 additions & 11 deletions demo/src/main/java/fr/speekha/httpmocker/demo/ui/MainPresenter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,13 @@ package fr.speekha.httpmocker.demo.ui

import android.util.Log
import fr.speekha.httpmocker.MockResponseInterceptor
import fr.speekha.httpmocker.demo.R
import fr.speekha.httpmocker.demo.service.GithubApiEndpoints
import kotlinx.coroutines.*
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.cancel
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext


class MainPresenter(
Expand Down Expand Up @@ -48,21 +53,29 @@ class MainPresenter(
apiService.listRepositoriesForOrganisation(org)
}

private suspend fun loadTopContributor(org: String, repo: String) = withContext(Dispatchers.IO) {
try {
apiService.listContributorsForRepository(org, repo)
} catch (e: Throwable) {
Log.e("Presenter", e.message, e)
null
private suspend fun loadTopContributor(org: String, repo: String) =
withContext(Dispatchers.IO) {
try {
apiService.listContributorsForRepository(org, repo)
} catch (e: Throwable) {
Log.e("Presenter", e.message, e)
null
}
}
}

override fun setMode(mode: Int) {
mocker.mode = MockResponseInterceptor.Mode.values()[mode]
override fun setMode(mode: MockResponseInterceptor.Mode) {
mocker.mode = mode
if (mocker.mode == MockResponseInterceptor.Mode.RECORD) {
view.checkPermission()
}
view.updateStorageLabel(mocker.mode == MockResponseInterceptor.Mode.RECORD)
view.updateDescriptionLabel(
when (mocker.mode) {
MockResponseInterceptor.Mode.DISABLED -> R.string.disabled_description
MockResponseInterceptor.Mode.ENABLED -> R.string.enabled_description
MockResponseInterceptor.Mode.MIXED -> R.string.mixed_description
MockResponseInterceptor.Mode.RECORD -> R.string.record_description
}
)
}

override fun stop() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
package fr.speekha.httpmocker.demo.ui

import android.content.Context
import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import fr.speekha.httpmocker.demo.R
import fr.speekha.httpmocker.demo.model.Repo

Expand Down
Loading

0 comments on commit 4c88b2b

Please sign in to comment.