Skip to content

Instantly share code, notes, and snippets.

View robfletcher's full-sized avatar

Rob Fletcher robfletcher

View GitHub Profile
import io.mockk.Called
import io.mockk.every
import io.mockk.mockk
import io.mockk.verify
import org.junit.jupiter.api.Test
import java.util.function.Consumer
import java.util.function.Supplier
class NullOrUnitWasNotCalled {
@Test
@robfletcher
robfletcher / MockkUnitLambdaTest.kt
Created March 16, 2019 16:44
Demonstration of error verifying calls to a lambda that returns `Unit`
import io.mockk.mockk
import io.mockk.verify
import org.junit.jupiter.api.Test
class MockkUnitLambdaTest {
@Test
fun mockUnitLambda() {
val fn: (String) -> Unit = mockk(relaxUnitFun = true)
@robfletcher
robfletcher / SetPropertySpec.groovy
Last active February 25, 2019 21:46
Demonstrates issue with comparing objects with set properties whose elements are > 1 level deep value objects
import groovy.transform.TupleConstructor
import org.javers.core.JaversBuilder
import org.javers.core.diff.changetype.container.SetChange
import org.javers.core.diff.changetype.container.ValueAdded
import org.javers.core.metamodel.annotation.Id
import spock.lang.Specification
import static java.util.UUID.randomUUID
class SetPropertySpec extends Specification {
@robfletcher
robfletcher / ThinkSpec.kt
Created June 7, 2017 13:11
Example of trying to use `SubjectSpek` and `itBehavesLike` if the subject requires a collaborator
import org.jetbrains.spek.api.dsl.describe
import org.jetbrains.spek.api.dsl.given
import org.jetbrains.spek.api.dsl.it
import org.jetbrains.spek.api.dsl.on
import org.jetbrains.spek.subject.SubjectSpek
import org.jetbrains.spek.subject.itBehavesLike
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
open class Thing(protected val fn: () -> Unit) {
import org.jetbrains.spek.api.Spek
class TableSpec : Spek({
describe("using a table") {
table { a: String, b: Int ->
describe("$a and $b are parameters") {
it("should work") {
assert(a is String)
assert(b is Int)
}
import groovy.transform.*
@CompileStatic
Map<String, ?> makeMap() {
def map = [string: "string"]
map.number = 1
return map
}
def map = makeMap()
@robfletcher
robfletcher / InteropNullabilitySpec.kt
Last active February 24, 2016 18:26
Example of how Kotlin treats nullability of Java types
import org.jetbrains.spek.api.*
class InteropNullabilitySpec : Spek() {
init {
given("a java object with null state") {
val obj = JavaStringWrapper(null)
on("calling a getter that will return null") {
it("allows me to assign the result to a nullable type") {
val s: String? = obj.value
shouldBeNull(s)
@robfletcher
robfletcher / Diamond.kt
Last active February 18, 2016 16:09
The diamond kata in Kotlin
fun diamond(c: Char): String {
if (c !in 'A'..'Z') throw IllegalArgumentException()
return ('A'..c)
.map(row(c))
.mirrorDown()
.joinToString("\n")
}
private fun row(max: Char) = { next: Char ->
"$next"
ctx
.byMethod(spec ->
spec
.get(() -> ctx.render("GET"))
.post(() -> ctx.render("POST"))
);
import com.fasterxml.jackson.annotation.JsonSubTypes.Type
import com.fasterxml.jackson.annotation.JsonTypeInfo.Id
import com.fasterxml.jackson.annotation.{JsonSubTypes, JsonTypeInfo}
@JsonTypeInfo(use = Id.NAME, property = "name")
@JsonSubTypes(Array(
new Type(classOf[Vodka.type]),
new Type(classOf[Whiskey])
))
trait Spirit