PacketHandlerPipeline { public PacketHandler getHandler(byte[] packet) { synchronized (this.handlers) { for (PacketHandler protocolHandler : this.handlers) { if (protocolHandler.canHandle(packet)) { return protocolHandler; } } return null; } } PacketHandlerPipeline(); boolean addHandler(PacketHandler handler); boolean removeHandler(PacketHandler handler); int count(); boolean contains(PacketHandler handler); PacketHandler getHandler(byte[] packet);  }
@Test public void testGetHandler() { PacketHandlerPipeline pipeline = new PacketHandlerPipeline(); String msg = "low"; byte[] msgData = msg.getBytes(); pipeline.addHandler(hpHandler); pipeline.addHandler(lpHandler); pipeline.addHandler(mpHandler); PacketHandler handler = pipeline.getHandler(msgData); Assert.assertEquals(lpHandler, handler); }