Mocking unsigned Kotlin types ends in `java.lang.ClassCastException`
See original GitHub issueI’m mocking simple function returning UInt
but after that method is executed in the test it crashes with java.lang.ClassCastException
.
every { calculator.compute(any()) } returns 23859762u
Expected Behavior
No crash, mocked function returns unsigned number result.
Current Behavior
Exception java.lang.ClassCastException: kotlin.UInt cannot be cast to java.lang.Integer
is thrown in case of UInt return type.
Steps to Reproduce
- Write mockk
every
function for a method returning unsigned number like UInt - Call this function in the test
- Exception is thrown
Context
- MockK version: 1.10.0
- OS: macOS Catalina
- Kotlin version: 1.3.72
- JUnit version: 4.12
- Type of test: unit test
Minimal reproducible code (the gist of this issue)
every { calculator.compute(any()) } returns 23859762u
assertEquals(23859762u, calculator.compute(42))
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:7
Top Results From Across the Web
Mocking unsigned Kotlin types ends in `java.lang.ClassCastException`
I'm mocking simple function returning UInt but after that method is executed in the test it crashes with java.lang.ClassCastException .
Read more >Mocking a generic method in Kotlin causes CCE
I am trying to mock a method call with a type argument in Kotlin ... Method.invoke(Method.java:566) at org.junit.platform.commons.util.
Read more >Integer - Android Developers
Returns the unsigned quotient of dividing the first argument by the second where each argument and the result is interpreted as an unsigned...
Read more >Groovy Language Documentation
SAM type coercion; Differences with Java 8 default methods ... A consequence of slash escaping is that a slashy string can't end with...
Read more >The jOOQ Release Note History
#11560, java.lang.ClassCastException: class org.jooq.impl.ResultImpl cannot be cast to class java.sql.ResultSet when mocking Oracle SYS_REFCURSOR procedure.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Unsigned integer support in Kotlin is still in beta, so I guess @d35h is right.
Same issue here trying to mock a
UByte
:As result, I have the next:
class java.lang.Byte cannot be cast to class kotlin.UByte (java.lang.Byte is in module java.base of loader 'bootstrap'; kotlin.UByte is in unnamed module of loader 'app') java.lang.ClassCastException: class java.lang.Byte cannot be cast to class kotlin.UByte (java.lang.Byte is in module java.base of loader 'bootstrap'; kotlin.UByte is in unnamed module of loader 'app')