Source:
<code>public void testDefeatRecovery() throws Exception { final Channel channel1 = mock(Channel.class); when(channel1.isOpen()).thenReturn(true); willAnswer(i -> { <START> return null; <END> }).given(channel1).close(); final Channel channel2 = mock(Channel.class); when(channel2.isOpen()).thenReturn(true); final com.rabbitmq.client.Connection rabbitConn = mock(AutorecoveringConnection.class); when(rabbitConn.isOpen()).thenReturn(true); com.rabbitmq.client.ConnectionFactory cf = mock(com.rabbitmq.client.ConnectionFactory.class); doAnswer(invocation -> rabbitConn).when(cf).newConnection(any(ExecutorService.class), anyString()); when(rabbitConn.createChannel()).thenReturn(channel1).thenReturn(channel2); CachingConnectionFactory ccf = new CachingConnectionFactory(cf); Connection conn1 = ccf.createConnection(); Channel channel = conn1.createChannel(false); verifyChannelIs(channel1, channel); channel.close(); conn1.close(); Connection conn2 = ccf.createConnection(); assertSame(conn1, conn2); channel = conn1.createChannel(false); verifyChannelIs(channel1, channel); channel.close(); conn2.close(); when(rabbitConn.isOpen()).thenReturn(false).thenReturn(true); when(channel1.isOpen()).thenReturn(false); conn2 = ccf.createConnection(); try { channel = conn2.createChannel(false); } catch (AmqpException e) { assertThat(e.getMessage(), equalTo("Auto recovery connection is not currently open")); } channel = conn2.createChannel(false); verifyChannelIs(channel2, channel); channel.close(); verify(rabbitConn, never()).close(); verify(channel1).close(); }</code><technical_language>Minor. simplified: i -> null</technical_language>

Target:
public void testDefeatRecovery() throws Exception { final Channel channel1 = mock(Channel.class); when(channel1.isOpen()).thenReturn(true); final Channel channel2 = mock(Channel.class); when(channel2.isOpen()).thenReturn(true); final com.rabbitmq.client.Connection rabbitConn = mock(AutorecoveringConnection.class); when(rabbitConn.isOpen()).thenReturn(true); com.rabbitmq.client.ConnectionFactory cf = mock(com.rabbitmq.client.ConnectionFactory.class); doAnswer(invocation -> rabbitConn).when(cf).newConnection(any(ExecutorService.class), anyString()); when(rabbitConn.createChannel()).thenReturn(channel1).thenReturn(channel2); CachingConnectionFactory ccf = new CachingConnectionFactory(cf); Connection conn1 = ccf.createConnection(); Channel channel = conn1.createChannel(false); verifyChannelIs(channel1, channel); channel.close(); conn1.close(); Connection conn2 = ccf.createConnection(); assertSame(conn1, conn2); channel = conn1.createChannel(false); verifyChannelIs(channel1, channel); channel.close(); conn2.close(); when(rabbitConn.isOpen()).thenReturn(false).thenReturn(true); when(channel1.isOpen()).thenReturn(false); conn2 = ccf.createConnection(); try { conn2.createChannel(false); fail("Expected AutoRecoverConnectionNotCurrentlyOpenException"); } catch (AutoRecoverConnectionNotCurrentlyOpenException e) { assertThat(e.getMessage(), equalTo("Auto recovery connection is not currently open")); } channel = conn2.createChannel(false); verifyChannelIs(channel2, channel); channel.close(); verify(rabbitConn, never()).close(); verify(channel1).close(); }