Skip to content

Incorrect "has following stubbing(s) with different arguments" message when using Argument Matchers #2468

@vcvitaly

Description

@vcvitaly

Hello,
I have a following error when running one of my tests:

org.mockito.exceptions.misusing.PotentialStubbingProblem: 
Strict stubbing argument mismatch. Please check:
 - this invocation of 'prepareCommonCostsLinesForCommonCosts' method:
    contractLinePreparationHelperServiceMock.prepareCommonCostsLinesForCommonCosts(
    8L,
    com.zpot.contract.core.dto.contract.line.LinePreparationCharacteristicsBO@57b9e423,
    [com.zpot.contract.core.dto.contract.line.LinePreparationBaseInfoBO@304a3655]
);
    -> at com.zpot.contract.core.service.contract.impl.ReadyContractService.prepareCommonCostsLineBOs(ReadyContractService.java:953)
 - has following stubbing(s) with different arguments:
    1. contractLinePreparationHelperServiceMock.prepareCommonCostsLinesForCommonCosts(
    0L,
    null,
    null
);
      -> at com.zpot.contract.core.service.contract.impl.ReadyContractServiceTest.createContractSuccessWithSignedByBothPartiesStatusTest(ReadyContractServiceTest.java:470)

I use argument matches so that what my code at line 470 looks like:

when(contractLinePreparationHelperServiceMock.prepareCommonCostsLinesForCommonCosts(eq(CONTRACT_ID),
                argThat(charBO -> charBO.getTenantVatType() == StandardVatType.COMPLIANT),
                argThat((List<LinePreparationBaseInfoBO<CommonCostsBO>> lineBaseInfos) -> lineBaseInfos.size() == 1 &&
                        lineBaseInfos.get(0).getCalculationType() == RentCalculationType.FIXED &&
                        BigDecimalUtils.is(lineBaseInfos.get(0).getYearlyBasePrice()).eq(BigDecimal.ONE) &&
                        lineBaseInfos.get(0).getQuantity().equals(INCLUSIVE_AREA))))
                .thenReturn(singletonList(commonCostsLineBO));

Clearly there is nothing like 0L, null, null in stubbing, it's just Mockito cannot properly recognise matchers and prints nulls instead, it distracted me for a while to understand where this 0L comes from until I started suspecting that some matcher might not work.

Do you think that can be classified as an issue?

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