lundi 22 mai 2017

Mockito verify method called once

I'm trying to use mockito to verify if method is called. Here is an example:

@Test
public void t(){
    InvokedFromTest ift = mock(InvokedFromTest.class);
    TestClass t = new TestClass();
    t.ift = ift;

    t.mm(new String(ByteBuffer.allocate(4).put("123".getBytes()).array()));
    verify(ift, times(1)).m("123");
}

private static class TestClass{
    public InvokedFromTest ift;
    public void mm(String s){ ift.m(s); }
}

private static class InvokedFromTest{
    public void m(String s){}
}

But when runnig t() I got the following exception:

Argument(s) are different! Wanted:
invokedFromTest.m("123");
-> at com.pack.age.TableRowIgniteProcessingLogicTest.t(TableRowIgniteProcessingLogicTest.java:62)
Actual invocation has different arguments:
invokedFromTest.m("123");
-> at com.pack.age.TableRowIgniteProcessingLogicTest$TestClass.mm(TableRowIgniteProcessingLogicTest.java:67)

Why? Why did I get this error? How to make this test work as expected?

Aucun commentaire:

Enregistrer un commentaire