Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using mockito with wildcard agruments

Tags:

java

mockito

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

selectGatewayInfoConfig(Operation<?> o)

What I am trying to do is:

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

Thanks in advance.

like image 461
user1554427 Avatar asked Nov 19 '14 13:11

user1554427


1 Answers

How 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";
    }
}
like image 70
Ross Taylor-Turner Avatar answered Oct 22 '22 14:10

Ross Taylor-Turner