CommandBuffer { public CMD consumeCommand() { if (getBufferedCommandsCount() > 0 && nextConsumable != head) { CMD command = buffer[nextConsumable]; nextConsumable = (nextConsumable + 1) % buffer.length; return command; } else { return null; } } CommandBuffer(int capacity); int getBufferedCommandsCount(); int getUnconsumedCommandsCount(); void addCommand(CMD command); CMD consumeCommand(); void purgeTillCommand(int commandIdExclusive); boolean rewindToCommand(long commandId); long getNextCommandId(); void clear();  }
@Test public void consumeCommand() throws Exception { CommandBuffer buffer = new CommandBuffer(2); buffer.addCommand(createCmd(1)); assertEquals(1, buffer.consumeCommand().getId()); assertNull(buffer.consumeCommand()); buffer.addCommand(createCmd(2)); buffer.addCommand(createCmd(3)); assertEquals(2, buffer.consumeCommand().getId()); assertEquals(3, buffer.consumeCommand().getId()); assertNull(buffer.consumeCommand()); }