Using mockito with templates

I am trying to pass wildcard to the mockito any () method. This is the method

selectGatewayInfoConfig(Operation<?> o) 

I am trying to do the following:

 when(gatewayConfigSelector.selectGatewayInfoConfig( any(**!!!!!! HERE I NEED THIS WILDCARD !!!!**)); .thenReturn(...something...); 

Thanks in advance.

+5
source share
1 answer

What about?

 when(gatewayConfigSelector.selectGatewayInfoConfig( any(Operation.class)); .thenReturn(...something...); 

Example:

 @Test public void test() { Tester mock = Mockito.mock(Tester.class); Mockito.when(mock.selectGatewayInfoConfig(Mockito.any(Operation.class))).thenReturn("blah"); System.out.println(mock.selectGatewayInfoConfig(null)); } class Operation<T> { } class Tester { public String selectGatewayInfoConfig(Operation<?> o) { return "hi"; } } 
+5
source

Source: https://habr.com/ru/post/1207217/


All Articles