Skip to content

Instantly share code, notes, and snippets.

View oleksiyp's full-sized avatar

Oleksiy Pylypenko oleksiyp

View GitHub Profile
@oleksiyp
oleksiyp / ExampleMockK.kt
Created October 20, 2017 18:04
Example tests written with MockK usage
package io.github.oleksiyp.proxy.controller
import io.github.oleksiyp.netty.JsonScope
import io.github.oleksiyp.netty.RequestHttpHandlerScope
import io.github.oleksiyp.proxy.service.ProxyConnection
import io.github.oleksiyp.proxy.service.ProxyOps
import io.kotlintest.matchers.shouldBe
import io.kotlintest.specs.StringSpec
import io.netty.handler.codec.http.HttpMethod
import io.netty.handler.codec.http.HttpResponseStatus
@oleksiyp
oleksiyp / envoy-1.16.0.jsonschema
Created November 6, 2020 08:21
Envyo 1.16.0 schema
{
"$schema": "http://json-schema.org/draft-04/schema#",
"properties": {
"node": {
"properties": {
"id": {
"type": "string",
"description": "An opaque node identifier for the Envoy node. This also provides the local\n service node name. It should be set if any of the following features are\n used: :ref:`statsd \u003carch_overview_statistics\u003e`, :ref:`CDS\n \u003cconfig_cluster_manager_cds\u003e`, and :ref:`HTTP tracing\n \u003carch_overview_tracing\u003e`, either in this message or via\n :option:`--service-node`."
},
"cluster": {
Abc def
Abc def
@oleksiyp
oleksiyp / Channel$Subclass0-broken.txt
Created January 26, 2019 19:43
Classes produced by ByteBuddy when using subclass
Classfile /home/oleksiyp/workspace/playground-issue219/broken/Channel$Subclass0.class
Last modified Jan 26, 2019; size 5600 bytes
MD5 checksum 59659ef9d1918d11c3ee4ae1e4431de1
public class kotlinx.coroutines.channels.Channel$Subclass0 implements kotlinx.coroutines.channels.Channel
minor version: 0
major version: 54
flags: (0x0021) ACC_PUBLIC, ACC_SUPER
this_class: #2 // kotlinx/coroutines/channels/Channel$Subclass0
super_class: #4 // java/lang/Object
interfaces: 1, fields: 20, methods: 26, attributes: 1
@oleksiyp
oleksiyp / Coroutine.kt
Created November 2, 2018 18:53
"MockK: intentions" coroutines
coEvery { mock.suspendFn() } returns 5
@oleksiyp
oleksiyp / GenericFn.kt
Created November 2, 2018 18:45
"MockK: intentions" generic function
interface Cls {
fun <T>genericFn(): T
fun otherFn(param: Int) = param + 1
}
val mock = mockk<Cls>()
every {
mock.otherFn(mock.genericFn())
@oleksiyp
oleksiyp / ObjectMockK.kt
Created November 2, 2018 18:41
"MockK: intentions" object mock
object Obj {
fun objectFn() = 5
}
mockkObject(Obj)
every { Obj.objectFn() } returns 6
@oleksiyp
oleksiyp / DSLExamples.kt
Last active November 2, 2018 18:38
"MockK: intentions" DSL examples
// --- many chained calls ---
val presenter : LoginPresenter = spyk<LoginPresenter>()
val viewCallback = mockk<LoginContract.LoginViewCallBack>()
val cookieStore = mockk<PianoCookieStore>()
val loginRequest = LoginRequest("user", "pwd")
val customerResponse = CustomerResponse("j", "r")
every { presenter.accountDelegator.login(loginRequest) } returns Single.just(Response.success(any()))
@oleksiyp
oleksiyp / StaticMockK.kt
Created November 2, 2018 18:38
"MockK: intentions" static mockk
// --- top level function ---
mockkStatic("pkg.FileKt")
every { topLevelFunctionInFileKt() } returns 5
// --- Java static function ---
mockkStatic(Uri::class)
every { Uri.parse("http://test/path") } returns Uri("http", "test", "path")
@oleksiyp
oleksiyp / CompositeMatcher.kt
Created November 2, 2018 06:24
"MockK: intentions" example about composite matchers
/**
* Boolean logic "AND" and "OR" matcher composed of two other matchers
*/
data class AndOrMatcher<T : Any>(
val and: Boolean,
val first: T,
val second: T
) : Matcher<T>, CompositeMatcher<T>, CapturingMatcher {
override val operandValues: List<T>
get() = listOf(first, second)