### Question:
CircularBuffer { @SuppressWarnings("unchecked") public CircularBuffer(Class<T> clazz, int capacity) { if (capacity <= 0) { throw new IllegalArgumentException("CircularBuffer capacity should be greater than 0"); } this.buffer = (T[]) Array.newInstance(clazz, capacity); this.capacity = capacity; } @SuppressWarnings("unchecked")  CircularBuffer(Class<T> clazz, int capacity); synchronized void write(T element); synchronized T take(); synchronized T peek(); int size(); boolean isEmpty(); boolean isFull(); synchronized void reset();  }### Answer:
@Test public void testCircularBuffer() { final int capacity = 3; CircularBuffer<String> buffer = new CircularBuffer<>(String.class, capacity); assertTrue(buffer.isEmpty()); assertFalse(buffer.isFull()); buffer.write("A"); assertFalse(buffer.isEmpty()); assertFalse(buffer.isFull()); buffer.write("B"); assertFalse(buffer.isEmpty()); assertFalse(buffer.isFull()); buffer.write("C"); assertFalse(buffer.isEmpty()); assertTrue(buffer.isFull()); assertEquals("A", buffer.take()); assertFalse(buffer.isEmpty()); assertFalse(buffer.isFull()); assertEquals("B", buffer.take()); assertFalse(buffer.isEmpty()); assertFalse(buffer.isFull()); assertEquals("C", buffer.take()); assertTrue(buffer.isEmpty()); assertFalse(buffer.isFull()); buffer.write("1"); assertFalse(buffer.isEmpty()); assertFalse(buffer.isFull()); buffer.write("2"); assertFalse(buffer.isEmpty()); assertFalse(buffer.isFull()); buffer.write("3"); assertFalse(buffer.isEmpty()); assertTrue(buffer.isFull()); buffer.write("4"); assertFalse(buffer.isEmpty()); assertTrue(buffer.isFull()); assertEquals("2", buffer.take()); assertFalse(buffer.isEmpty()); assertFalse(buffer.isFull()); assertEquals("3", buffer.take()); assertFalse(buffer.isEmpty()); assertFalse(buffer.isFull()); assertEquals("4", buffer.take()); assertTrue(buffer.isEmpty()); assertFalse(buffer.isFull()); buffer.write("a"); assertFalse(buffer.isEmpty()); assertFalse(buffer.isFull()); buffer.write("b"); assertFalse(buffer.isEmpty()); assertFalse(buffer.isFull()); buffer.write("c"); assertFalse(buffer.isEmpty()); assertTrue(buffer.isFull()); buffer.write("d"); assertFalse(buffer.isEmpty()); assertTrue(buffer.isFull()); buffer.write("e"); assertFalse(buffer.isEmpty()); assertTrue(buffer.isFull()); buffer.write("f"); assertFalse(buffer.isEmpty()); assertTrue(buffer.isFull()); buffer.write("g"); assertFalse(buffer.isEmpty()); assertTrue(buffer.isFull()); assertEquals("e", buffer.take()); assertFalse(buffer.isEmpty()); assertFalse(buffer.isFull()); assertEquals("f", buffer.take()); assertFalse(buffer.isEmpty()); assertFalse(buffer.isFull()); assertEquals("g", buffer.take()); assertTrue(buffer.isEmpty()); assertFalse(buffer.isFull()); }