Skip to content

Issues stubbing and capturing value classes in latest snapshot #555

@jselbo

Description

@jselbo

Hello,
I think there are issues introduced by the recent commits
d8fe7c7 "Add value class support to KArgumentCaptor"
cd674c4 "Add value class support to eq() argument matcher"

I am trying to integrate the latest mockito-kotlin snapshot build with our suite of tests and I'm encountering these issues with value classes that wrap primitive types (like kotlin.time.Duration):

  1. anyOrNull with nullable primitive value class matcher throws IllegalStateException

See 7a19a0a for a repro and a fix - I can open a PR if desired but I don't want to step on the toes of existing work

  1. any/eq don't work for primitive value class
@JvmInline value class PrimitiveValueClass(val value: Long)

// method:
fun nullablePrimitiveValueClass(v: PrimitiveValueClass?)

// test:
mock<SynchronousFunctions>().apply {
  nullablePrimitiveValueClass(PrimitiveValueClass(123))
  verify(this).nullablePrimitiveValueClass(any())
}

fails with:

Argument(s) are different! Wanted:
synchronousFunctions.nullablePrimitiveValueClass-2LcYgm0(
    <any long>
);
-> at test.MatchersTest$AnyOrNullMatchersTest.anyOrNullNullableValueClass(MatchersTest.kt:375)
Actual invocations have different arguments:
synchronousFunctions.nullablePrimitiveValueClass-2LcYgm0(
    PrimitiveValueClass(value=123)
);

I think the any() wrongly unwraps the value class type when it is not actually inlined here.

I also saw some failures related to kotlin.Result<T> unwrapping but I'm not sure if that's a separate issue.

cc: @m-koops

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions