@Test
 public void testMultipleChannelsWithSelector() {
   QueueChannel channel1 = new QueueChannel();
   QueueChannel channel2 = new QueueChannel();
   channel1.send(new GenericMessage<String>("test1"));
   channel1.send(new GenericMessage<String>("test2"));
   channel1.send(new GenericMessage<String>("test3"));
   channel2.send(new GenericMessage<String>("test1"));
   channel2.send(new GenericMessage<String>("test2"));
   channel2.send(new GenericMessage<String>("test3"));
   ChannelPurger purger =
       new ChannelPurger(
           new MessageSelector() {
             public boolean accept(Message<?> message) {
               return (message.getPayload().equals("test2"));
             }
           },
           channel1,
           channel2);
   List<Message<?>> purgedMessages = purger.purge();
   assertEquals(4, purgedMessages.size());
   Message<?> message1 = channel1.receive(0);
   assertNotNull(message1);
   assertEquals("test2", message1.getPayload());
   assertNull(channel1.receive(0));
   Message<?> message2 = channel2.receive(0);
   assertNotNull(message2);
   assertEquals("test2", message2.getPayload());
   assertNull(channel2.receive(0));
 }
 @Test
 public void testMultipleChannelsWithNoSelector() {
   QueueChannel channel1 = new QueueChannel();
   QueueChannel channel2 = new QueueChannel();
   channel1.send(new GenericMessage<String>("test1"));
   channel1.send(new GenericMessage<String>("test2"));
   channel2.send(new GenericMessage<String>("test1"));
   channel2.send(new GenericMessage<String>("test2"));
   ChannelPurger purger = new ChannelPurger(channel1, channel2);
   List<Message<?>> purgedMessages = purger.purge();
   assertEquals(4, purgedMessages.size());
   assertNull(channel1.receive(0));
   assertNull(channel2.receive(0));
 }
 @Test
 public void testPurgeNoneWithSelector() {
   QueueChannel channel = new QueueChannel();
   channel.send(new GenericMessage<String>("test1"));
   channel.send(new GenericMessage<String>("test2"));
   channel.send(new GenericMessage<String>("test3"));
   ChannelPurger purger =
       new ChannelPurger(
           new MessageSelector() {
             public boolean accept(Message<?> message) {
               return true;
             }
           },
           channel);
   List<Message<?>> purgedMessages = purger.purge();
   assertEquals(0, purgedMessages.size());
   assertNotNull(channel.receive(0));
   assertNotNull(channel.receive(0));
   assertNotNull(channel.receive(0));
 }
 @Test
 public void testPurgeAllWithoutSelector() {
   QueueChannel channel = new QueueChannel();
   channel.send(new GenericMessage<String>("test1"));
   channel.send(new GenericMessage<String>("test2"));
   channel.send(new GenericMessage<String>("test3"));
   ChannelPurger purger = new ChannelPurger(channel);
   List<Message<?>> purgedMessages = purger.purge();
   assertEquals(3, purgedMessages.size());
   assertNull(channel.receive(0));
 }
 @Test
 public void testPurgeSubsetWithSelector() {
   QueueChannel channel = new QueueChannel();
   channel.send(new GenericMessage<String>("test1"));
   channel.send(new GenericMessage<String>("test2"));
   channel.send(new GenericMessage<String>("test3"));
   ChannelPurger purger =
       new ChannelPurger(
           new MessageSelector() {
             public boolean accept(Message<?> message) {
               return (message.getPayload().equals("test2"));
             }
           },
           channel);
   List<Message<?>> purgedMessages = purger.purge();
   assertEquals(2, purgedMessages.size());
   Message<?> message = channel.receive(0);
   assertNotNull(message);
   assertEquals("test2", message.getPayload());
   assertNull(channel.receive(0));
 }