Git Product home page Git Product logo

mokkery's People

Contributors

lupuuss avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

mokkery's Issues

Mocks incompatible with value classes

It seems that using value class, e.g. kotlin.Result in mocks will fail the test with exception

Given the interface

interface TestInterfaceWithValueClass {
    fun test(): Result<String>
}

Calling the test

    @Test
    fun testReturnsMockableInterfaceWithValueClassImpl() {
        val mocked = mock<TestInterfaceWithValueClass> {
            every { test() } returns Result.success("test")
        }
        assertEquals(Result.success("test"), mocked.test())
    }

Will fail with exception

java.lang.NullPointerException: Cannot invoke "kotlin.Result.unbox-impl()" because the return value of "dev.mokkery.internal.MokkeryInterceptor.interceptCall(dev.mokkery.internal.CallContext)" is null
	at dev.mokkery.test.TestInterfaceWithValueClassb7d4c11efdfd4d2aa2c67574e6dd5d5eMock.test-d1pmJ48(MockTest.kt)
	at dev.mokkery.test.MockTest$testReturnsMockableInterfaceWithValueClassImpl$mocked$1$1.invoke-IoAF18A(MockTest.kt:23)
	at dev.mokkery.test.MockTest$testReturnsMockableInterfaceWithValueClassImpl$mocked$1$1.invoke(MockTest.kt)
	at dev.mokkery.internal.EveryKt.internalEvery(Every.kt:21)
	at dev.mokkery.test.MockTest$testReturnsMockableInterfaceWithValueClassImpl$mocked$1.invoke(MockTest.kt)
	at dev.mokkery.test.MockTest$testReturnsMockableInterfaceWithValueClassImpl$mocked$1.invoke(MockTest.kt:22)
	at dev.mokkery.test.TestInterfaceWithValueClassb7d4c11efdfd4d2aa2c67574e6dd5d5eMock.<init>(MockTest.kt)
	at dev.mokkery.test.MockTest.testReturnsMockableInterfaceWithValueClassImpl(MockTest.kt:22)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
	at java.base/java.lang.reflect.Method.invoke(Unknown Source)
	...

mokkery version: 1.9.23-1.6.0
kotlin version: 1.9.23

Is not possible to mock a `data class`

I have the implementation of this data class:

@Serializable
data class WordPair(
    val wordsTotal: Int,
    val wordsFound: List<String>
)

at first run, I get this error:

Type ''com.alejandrorios.bogglemultiplatform.data.models.WordPair'' is final and cannot be used with ''mock''!

which I know it is because of one of the limitations of the library, then I'm including the @OpenForMokkery annotation to the data class, and now I get this error:

Class ''com.alejandrorios.bogglemultiplatform.data.models.WordPair'' has no default constructor and cannot be used with ''mock''!

Is it possible to solve this without adding default values to the data class?, maybe I'm missing something else.

Kotlin 2.0.0 support

Hey team Mokkery,

This is more of an information request than an issue, just wondering, if and when we can expect support for Kotlin 2.0?

I'm aware it's still in beta, but we'd love to start testing it asap, but since mokkery is a crucial part of the application we're a bit blocked.

Best,
-martin

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.