1
2
3
4
5
6
7
8
9
10
11
12
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 }