diff --git a/libs/nio/src/test/java/org/elasticsearch/nio/EventHandlerTests.java b/libs/nio/src/test/java/org/elasticsearch/nio/EventHandlerTests.java index 49c78cac3ee..c3f6fee9c35 100644 --- a/libs/nio/src/test/java/org/elasticsearch/nio/EventHandlerTests.java +++ b/libs/nio/src/test/java/org/elasticsearch/nio/EventHandlerTests.java @@ -68,7 +68,9 @@ public class EventHandlerTests extends ESTestCase { SocketChannel rawChannel = mock(SocketChannel.class); when(rawChannel.finishConnect()).thenReturn(true); NioSocketChannel channel = new NioSocketChannel(rawChannel); - when(rawChannel.socket()).thenReturn(mock(Socket.class)); + Socket socket = mock(Socket.class); + when(rawChannel.socket()).thenReturn(socket); + when(socket.getChannel()).thenReturn(rawChannel); context = new DoNotRegisterSocketContext(channel, selector, channelExceptionHandler, readWriteHandler); channel.setContext(context); handler.handleRegistration(context); diff --git a/libs/nio/src/test/java/org/elasticsearch/nio/SocketChannelContextTests.java b/libs/nio/src/test/java/org/elasticsearch/nio/SocketChannelContextTests.java index d61184bdf5c..8a44394533a 100644 --- a/libs/nio/src/test/java/org/elasticsearch/nio/SocketChannelContextTests.java +++ b/libs/nio/src/test/java/org/elasticsearch/nio/SocketChannelContextTests.java @@ -85,6 +85,7 @@ public class SocketChannelContextTests extends ESTestCase { }); rawSocket = mock(Socket.class); when(rawChannel.socket()).thenReturn(rawSocket); + when(rawSocket.getChannel()).thenReturn(rawChannel); } public void testIOExceptionSetIfEncountered() throws IOException {