0

This won't compile. I get an UnfinishedStubbingException. I've read the Mockito api and other questions on this site and I think that my syntax shouldn't be wrong, but it fails at doAnswer(new Answer() {, so I figure it has to be wrong, but I don't know where. Thanks.

doAnswer(new Answer() {
            @Override
            public Object answer(InvocationOnMock invocation) throws Throwable {
                Object[] args = invocation.getArguments();
                ((CrestronNioSocketHandler.NioEventReceiver) args[0]).onDataReceived(new byte[wantedNumber]);
                return null;
            }
        }).when(mockedChannel.read(any(ByteBuffer.class)));
sschale
  • 5,096
  • 3
  • 28
  • 35

1 Answers1

3

It should be like this

doAnswer(new Answer() {
            @Override
            public Object answer(InvocationOnMock invocation) throws Throwable {
                Object[] args = invocation.getArguments();
                ((CrestronNioSocketHandler.NioEventReceiver) args[0]).onDataReceived(new byte[wantedNumber]);
                return null;
            }
        }).when(mockedChannel).read(any(ByteBuffer.class));

Check this question about different ways of stubbing with Mockito.

Community
  • 1
  • 1
Sergii Bishyr
  • 7,893
  • 5
  • 33
  • 66