### Question:
AmqpConnectionHandler extends ChannelInboundHandlerAdapter { public int closeConnection(String reason, boolean force, boolean used) throws ValidationException { int numberOfChannels = channels.size(); if (!used && numberOfChannels > 0) { throw new ValidationException("Cannot close connection. " + numberOfChannels + " active channels exist " + "and used parameter is not set."); } if (force) { forceCloseConnection(reason); } else { closeConnection(reason); } return numberOfChannels; } 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 testCloseConnection() throws Exception { int channelCount = 5; for (int i = 1; i <= channelCount; i++) { connectionHandler.createChannel(i); } try { connectionHandler.closeConnection("something", false, false); Assert.fail("Expected ValidationException not thrown"); } catch (ValidationException e) { Assert.assertEquals(e.getMessage(), "Cannot close connection. " + channelCount + " active channels exist and used " + "parameter is not set."); } }