### Question:
AmqpTransferTagGenerator { public byte[] getNextTag() { byte[] tagBytes = null; if (tagPool != null) { tagBytes = tagPool.pollFirst(); } if (tagBytes == null) { long tag = nextTagId++; int size = encodingSize(tag); tagBytes = new byte[size]; for (int i = 0; i < size; ++i) { tagBytes[size - 1 - i] = (byte) (tag >>> (i * 8)); } } return tagBytes; } AmqpTransferTagGenerator();  AmqpTransferTagGenerator(boolean pool); byte[] getNextTag(); void returnTag(byte[] data); int getMaxPoolSize(); void setMaxPoolSize(int maxPoolSize); boolean isPooling(); static final int DEFAULT_TAG_POOL_SIZE; }### Answer:
@Test public void testNewTagsOnSuccessiveCheckouts() { AmqpTransferTagGenerator tagGen = new AmqpTransferTagGenerator(true); byte[] tag1 = tagGen.getNextTag(); byte[] tag2 = tagGen.getNextTag(); byte[] tag3 = tagGen.getNextTag(); assertNotSame(tag1, tag2); assertNotSame(tag1, tag3); assertNotSame(tag3, tag2); assertFalse(Arrays.equals(tag1, tag2)); assertFalse(Arrays.equals(tag1, tag3)); assertFalse(Arrays.equals(tag3, tag2)); }
@Test public void testTagArrayGrowsWithTagValue() { AmqpTransferTagGenerator tagGen = new AmqpTransferTagGenerator(false); for (int i = 0; i < 512; ++i) { byte[] tag = tagGen.getNextTag(); if (i < 256) { assertEquals(1, tag.length); } else { assertEquals(2, tag.length); } } }
@Test public void testTagValueMatchesParsedArray() throws IOException { AmqpTransferTagGenerator tagGen = new AmqpTransferTagGenerator(false); for (int i = 0; i < Short.MAX_VALUE; ++i) { byte[] tag = tagGen.getNextTag(); ByteArrayInputStream bais = new ByteArrayInputStream(tag); DataInputStream dis = new DataInputStream(bais); if (i < 256) { assertEquals(1, tag.length); assertEquals((byte) i, dis.readByte()); } else { assertEquals(2, tag.length); assertEquals(i, dis.readShort()); } } }
@Test public void testTagGenerationWorksWithIdRollover() throws Exception { AmqpTransferTagGenerator tagGen = new AmqpTransferTagGenerator(false); Field urisField = tagGen.getClass().getDeclaredField("nextTagId"); urisField.setAccessible(true); urisField.set(tagGen, Long.MAX_VALUE + 1); { byte[] tag = tagGen.getNextTag(); ByteArrayInputStream bais = new ByteArrayInputStream(tag); DataInputStream dis = new DataInputStream(bais); assertEquals(8, tag.length); assertEquals(Long.MAX_VALUE + 1, dis.readLong()); } { byte[] tag = tagGen.getNextTag(); ByteArrayInputStream bais = new ByteArrayInputStream(tag); DataInputStream dis = new DataInputStream(bais); assertEquals(8, tag.length); assertEquals(Long.MAX_VALUE + 2, dis.readLong()); } }