Matching value in Map for using in Mockito.when

118 Views Asked by At

Dears, I'm trying to using Mockito to create different mocks based on a value contained in a Map. Following the documentation I created two different ArgumentMatchers that run the logic

private class ConsumerValidMap implements ArgumentMatcher<Map<String, Object>> {

    @Override
    public boolean matches(Map<String, Object> argument) {
        return argument.get("TYPE").equals("CONSUMER");
    }
}

private class BayValidMap implements ArgumentMatcher<Map<String, Object>> {

    @Override
    public boolean matches(Map<String, Object> argument) {
        return argument.get("TYPE").equals("BAY");
    }
}

If I create the Mock as following:

@Before
public void setUp() {
    Mockito.when(idAndTypeDtoMapper.toDto(argThat(new ConsumerValidMap()))).thenReturn(identityConsumer);
    Mockito.when(idAndTypeDtoMapper.toDto(argThat(new BayValidMap()))).thenReturn(identityBay); 
}

I got the errors:

[MockitoHint] 1. Unused... -> at com.virtualentity.unit.service.ExtractorServiceTest.setUp(ExtractorServiceTest.java:123)
[MockitoHint]  ...args ok? -> at com.virtualentity.unit.service.ExtractorServiceTest.setUp(ExtractorServiceTest.java:124)

Also I tried to create the istances of the ArgumentMatchers but still I got the errors. Any suggestions?

Thanks

0

There are 0 best solutions below