how to match an array of array with the same values in mockito

106 views Asked by At

I have the following call to match so as to return an object:

    String[][] parameters = new String[][] {
            new String[]{
                    eq("provider"),
                    eq("myProvider")
            }
    };

    when(supportApiNotificationsProvider.getByServiceName(
            "supportApiNotifications",
            parameters))
            .thenReturn(<an-object>);

but this way the mock always returns null. On the other hand, if I change the parameter offered to the mock as the following:

    String[][] parameters = new String[][] {
            new String[]{
                    anyString(),
                    anyString()
            }
    };

it works! I'm sure about the tho string values passed, hence I guess it's something about the eq matchers I defined.

1

There are 1 answers

0
Benoit On BEST ANSWER

I think the eq is misplaced, I would rather define parameters like this:

    String[][] parameters = eq(new String[][] {
            new String[]{
                    "provider",
                    "myProvider"
            }
    });