Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#152 support value classes #849

Merged
merged 22 commits into from Jul 26, 2022
Merged
Changes from 3 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
4c936b1
#152 add failing tests for value classes
aSemy Jul 20, 2022
b6670b7
Merge branch 'kotlin-1-7' into fix/152-value-classes
aSemy Jul 20, 2022
7da1ad8
Merge branch 'master' into fix/152-value-classes
aSemy Jul 21, 2022
514e014
add support for value class any() matcher
aSemy Jul 22, 2022
cd368da
fix value classes & slots
aSemy Jul 22, 2022
32ade90
update 'inline class' to 'value class'
aSemy Jul 22, 2022
0ffba57
update TODO, apply some auto-fixes to remove warnings
aSemy Jul 22, 2022
f2e6c7a
refactor mock-dsl-jvm to re-use ValueClassSupport code, and add TODOs…
aSemy Jul 23, 2022
1c5e442
test for #729
aSemy Jul 23, 2022
9cc892f
test #729, extension fun with UInt return
aSemy Jul 23, 2022
bcd427e
rm 'actual' from 'expect' object
aSemy Jul 23, 2022
201b43d
fix kdoc typo
aSemy Jul 23, 2022
65e8643
fix kdoc typo
aSemy Jul 23, 2022
5e7851b
refactor: simplify ValueClassSupport
qoomon Jul 23, 2022
ed8ab0c
Merge remote-tracking branch 'aSemy/mockk/fix/152-value-classes' into…
aSemy Jul 24, 2022
aafe7af
more testing for value classes - pre-merge in https://github.com/aSem…
aSemy Jul 24, 2022
fd6b24e
Merge pull request #1 from qoomon/fix/152-value-classes
aSemy Jul 24, 2022
360b08e
Merge remote-tracking branch 'aSemy/fix/152-value-classes' into fix/1…
aSemy Jul 24, 2022
af349e7
disable wrapped value class tests, rename tests for consistency
aSemy Jul 24, 2022
592bdaf
rename file to match obj name
aSemy Jul 24, 2022
fcaef2e
added timeout for Gradle test tasks
aSemy Jul 24, 2022
8b8017c
bump test timeout
aSemy Jul 24, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
46 changes: 46 additions & 0 deletions mockk/common/src/test/kotlin/io/mockk/it/ValueClassTest.kt
@@ -1,6 +1,7 @@
package io.mockk.it

import io.mockk.*
import kotlin.jvm.JvmInline
import kotlin.test.Test
import kotlin.test.assertEquals

Expand Down Expand Up @@ -43,6 +44,43 @@ class ValueClassTest {

verify { mock.processValue(DummyValue(1)) }
}

@Test
fun `any matcher for value class`() {
val mock = mockk<ValueServiceDummy>(relaxed = true)
val givenResult = 1
every { mock.doSomething(any()) } returns givenResult

val result = mock.doSomething(ValueDummy("moin"))

assertEquals(givenResult, result)
}

@Test
fun `slot for value class`() {
val mock = mockk<ValueServiceDummy>(relaxed = true)
val slot = slot<ValueDummy>()
val givenResult = 1
every { mock.doSomething(capture(slot)) } returns givenResult

val givenParameter = ValueDummy("s")

val result = mock.doSomething(givenParameter)

assertEquals(givenResult, result)
assertEquals(givenParameter, slot.captured)
}

@Test
fun `value class as return value`() {
val mock = mockk<ValueServiceDummy>(relaxed = true)
val givenResult = ValueDummy("moin")
every { mock.getSomething() } returns givenResult

val result = mock.getSomething()

assertEquals(givenResult, result)
}
}

// TODO should be value class in kotlin 1.5+
Expand All @@ -54,3 +92,11 @@ private class DummyService {

fun processValue(value: DummyValue) = DummyValue(0)
}

@JvmInline
value class ValueDummy(val value: String)

interface ValueServiceDummy {
fun doSomething(value: ValueDummy): Int
fun getSomething(): ValueDummy
}