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.jupiter.api.Assertions;
17  import org.junit.jupiter.api.Test;
18  
19  import java.util.Arrays;
20  import java.util.List;
21  
22  public class CyclicBufferTest {
23  
24      void assertSize(CyclicBuffer<String> cb, int size) {
25          Assertions.assertEquals(size, cb.length());
26      }
27  
28      @Test
29      public void smoke() {
30          CyclicBuffer<String> cb = new CyclicBuffer<String>(2);
31          assertSize(cb, 0);
32          cb.add("zero");
33          assertSize(cb, 1);
34          cb.add("one");
35          assertSize(cb, 2);
36          cb.add("two");
37          assertSize(cb, 2);
38          Assertions.assertEquals("one", cb.get());
39          assertSize(cb, 1);
40          Assertions.assertEquals("two", cb.get());
41          assertSize(cb, 0);
42      }
43  
44      @Test
45      public void cloning() {
46          CyclicBuffer<String> cb = new CyclicBuffer<String>(2);
47          cb.add("zero");
48          cb.add("one");
49  
50          CyclicBuffer<String> clone = new CyclicBuffer<String>(cb);
51          assertSize(clone, 2);
52          cb.clear();
53          assertSize(cb, 0);
54  
55          List<String> witness = Arrays.asList("zero", "one");
56          Assertions.assertEquals(witness, clone.asList());
57  
58      }
59  }