### Question:
MessageWriter { Future<Boolean> writeInitializeMessage(InitializationInput initializationInput) { return writeMessage(new InitializeMessage(initializationInput)); } MessageWriter();   }### Answer:
@Test public void writeInitializeMessageTest() throws IOException, InterruptedException, ExecutionException { Future<Boolean> future = this.messageWriter.writeInitializeMessage(InitializationInput.builder().shardId(shardId).build()); future.get(); verify(this.stream, Mockito.atLeastOnce()).write(Mockito.any(byte[].class), Mockito.anyInt(), Mockito.anyInt()); verify(this.stream, Mockito.atLeastOnce()).flush(); }
@Test public void streamIOExceptionTest() throws IOException, InterruptedException, ExecutionException { Mockito.doThrow(IOException.class).when(stream).flush(); Future<Boolean> initializeTask = this.messageWriter.writeInitializeMessage(InitializationInput.builder().shardId(shardId).build()); Boolean result = initializeTask.get(); Assert.assertNotNull(result); Assert.assertFalse(result); }