This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class IrisMockGradlePlugin : Plugin<Project> { | |
override fun apply(target: Project) { | |
project.configurations.getByName("implementation").dependencies.add( | |
project.dependencies.create("dev.arildo:iris-mock:$PLUGIN_VERSION") | |
) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
plugins { | |
id("com.google.devtools.ksp") | |
id("dev.arildo.iris-mock-plugin") version "1.0.1" | |
} | |
dependencies { | |
implementation("dev.arildo:iris-mock:1.0.1") | |
ksp("dev.arildo:iris-mock-compiler:1.0.1") | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@IrisMockInterceptor | |
class MyInterceptor : Interceptor { | |
override fun intercept(chain: Interceptor.Chain) = irisMockScope(chain) { | |
onGet(contains = "user/profile") mockResponse userProfileJson | |
onPost(endsWith = "/login") then { | |
delay(2_000) // simulating a slow response | |
if (requestContains("validPassword")) mockResponse(successLoginJson) | |
else mockResponse(errorPasswordJson) | |
} | |
enableLogs() // you can also log the calls |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@IrisMockInterceptor | |
class MockInterceptor : Interceptor { | |
override fun intercept(chain: Interceptor.Chain) = irisMockScope(chain) { | |
onGet(endsWith = "starred") mockResponse getListOfReposBeingStarredJson | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
plugins { | |
id("dev.arildo.iris-mock-plugin") version "1.1.0" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val client = OkHttpClient.Builder() | |
.addInterceptor(MockInterceptor()) | |
.build() | |
} | |
val retrofit = Retrofit.Builder() | |
.client(client) | |
.baseUrl(BASE_URL) | |
.build() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MockInterceptor : Interceptor { | |
override fun intercept(chain: Interceptor.Chain): Response { | |
val uri = chain.request().url().uri().toString() | |
val responseString = when { | |
uri.endsWith("starred") -> getListOfReposBeingStarredJson | |
else -> "" | |
} | |
return chain.proceed(chain.request()) | |
.newBuilder() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Scaffold( | |
timeText = { TimeText() } | |
) { | |
TunerScreen(viewModel.tunerState.observeAsState().value) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun Double.isInPermittedTolerance() = this in -0.5..0.5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun getCurrentPitchState(pitchHz: Double): TunerState { | |
val closestFrequency = getClosestFrequencyInAllNotes(pitchHz) | |
val note = getNoteByFrequency(closestFrequency) | |
val diff = if (closestFrequency > pitchHz) { | |
abs(closestFrequency - pitchHz).unaryMinus() | |
} else { | |
abs(pitchHz - closestFrequency) | |
} |
NewerOlder