Search in sources :

Example 1 with ObjectQueue

use of com.squareup.tape.ObjectQueue in project java by wavefrontHQ.

the class TapeDeckTest method testTape.

private void testTape(ObjectQueue<List<String>> tape) {
    final AtomicInteger addCalls = new AtomicInteger(0);
    final AtomicInteger removeCalls = new AtomicInteger(0);
    ObjectQueue.Listener<List<String>> listener = new ObjectQueue.Listener<List<String>>() {

        @Override
        public void onAdd(ObjectQueue<List<String>> objectQueue, List<String> strings) {
            addCalls.incrementAndGet();
        }

        @Override
        public void onRemove(ObjectQueue<List<String>> objectQueue) {
            removeCalls.incrementAndGet();
        }
    };
    tape.setListener(listener);
    assertThat(tape).isNotNull();
    tape.add(ImmutableList.of("test"));
    assertThat(tape.size()).isEqualTo(1);
    assertThat(tape.peek()).containsExactly("test");
    assertThat(addCalls.get()).isEqualTo(1);
    assertThat(removeCalls.get()).isEqualTo(0);
    tape.remove();
    assertThat(addCalls.get()).isEqualTo(1);
    assertThat(removeCalls.get()).isEqualTo(1);
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ObjectQueue(com.squareup.tape.ObjectQueue) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)1 ObjectQueue (com.squareup.tape.ObjectQueue)1 List (java.util.List)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1