View Javadoc
1   /**
2    * Logback: the reliable, generic, fast and flexible logging framework.
3    * Copyright (C) 1999-2015, QOS.ch. All rights reserved.
4    *
5    * This program and the accompanying materials are dual-licensed under
6    * either the terms of the Eclipse Public License v1.0 as published by
7    * the Eclipse Foundation
8    *
9    *   or (per the licensee's choosing)
10   *
11   * under the terms of the GNU Lesser General Public License version 2.1
12   * as published by the Free Software Foundation.
13   */
14  package ch.qos.logback.core.helpers;
15  
16  import org.junit.Test;
17  
18  import java.util.Arrays;
19  import java.util.List;
20  
21  import static org.junit.Assert.assertEquals;
22  
23  public class CyclicBufferTest {
24  
25      void assertSize(CyclicBuffer<String> cb, int size) {
26          assertEquals(size, cb.length());
27      }
28  
29      @Test
30      public void smoke() {
31          CyclicBuffer<String> cb = new CyclicBuffer<String>(2);
32          assertSize(cb, 0);
33          cb.add("zero");
34          assertSize(cb, 1);
35          cb.add("one");
36          assertSize(cb, 2);
37          cb.add("two");
38          assertSize(cb, 2);
39          assertEquals("one", cb.get());
40          assertSize(cb, 1);
41          assertEquals("two", cb.get());
42          assertSize(cb, 0);
43      }
44  
45      @Test
46      public void cloning() {
47          CyclicBuffer<String> cb = new CyclicBuffer<String>(2);
48          cb.add("zero");
49          cb.add("one");
50  
51          CyclicBuffer<String> clone = new CyclicBuffer<String>(cb);
52          assertSize(clone, 2);
53          cb.clear();
54          assertSize(cb, 0);
55  
56          List<String> witness = Arrays.asList("zero", "one");
57          assertEquals(witness, clone.asList());
58  
59      }
60  }