### Question:
AmqpConnectionHandler extends ChannelInboundHandlerAdapter { public void closeChannel(int channelId) { AmqpChannel channel = channels.remove(channelId); if (Objects.nonNull(channel)) { closeChannel(channel); } } AmqpConnectionHandler(AmqpMetricManager metricManager, AmqpChannelFactory amqpChannelFactory,
                                 AmqpConnectionManager amqpConnectionManager); void channelRegistered(ChannelHandlerContext ctx); @Override void channelRead(ChannelHandlerContext ctx, Object msg); @Override void channelReadComplete(ChannelHandlerContext ctx); @Override void channelWritabilityChanged(ChannelHandlerContext ctx); @Override void exceptionCaught(ChannelHandlerContext ctx, Throwable cause); void createChannel(int channelId); AmqpChannel getChannel(int channelId); void closeChannel(int channelId); void closeAllChannels(); Broker getBroker(); void attachBroker(Broker broker); boolean isWritable(); String getRemoteAddress(); int getChannelCount(); long getConnectedTime(); int getId(); int closeConnection(String reason, boolean force, boolean used); void closeChannel(int channelId, boolean used, String reason); Collection<AmqpChannelView> getChannelViews();  }### Answer:
@Test public void testCloseChannel() throws Exception { int channelId = 1; int consumerCount = 5; connectionHandler.createChannel(channelId); Mockito.when(amqpChannel.getConsumerCount()).thenReturn(consumerCount); try { connectionHandler.closeChannel(channelId, false, "something"); Assert.fail("Expected ValidationException not thrown"); } catch (ValidationException e) { Assert.assertEquals(e.getMessage(), "Cannot close channel. " + consumerCount + " active consumers exist and used " + "parameter is not set."); } }