001/** 002 * Logback: the reliable, generic, fast and flexible logging framework. 003 * Copyright (C) 1999-2015, QOS.ch. All rights reserved. 004 * 005 * This program and the accompanying materials are dual-licensed under 006 * either the terms of the Eclipse Public License v1.0 as published by 007 * the Eclipse Foundation 008 * 009 * or (per the licensee's choosing) 010 * 011 * under the terms of the GNU Lesser General Public License version 2.1 012 * as published by the Free Software Foundation. 013 */ 014package ch.qos.logback.core.helpers; 015 016import org.junit.Test; 017 018import java.util.Arrays; 019import java.util.List; 020 021import static org.junit.Assert.assertEquals; 022 023public class CyclicBufferTest { 024 025 void assertSize(CyclicBuffer<String> cb, int size) { 026 assertEquals(size, cb.length()); 027 } 028 029 @Test 030 public void smoke() { 031 CyclicBuffer<String> cb = new CyclicBuffer<String>(2); 032 assertSize(cb, 0); 033 cb.add("zero"); 034 assertSize(cb, 1); 035 cb.add("one"); 036 assertSize(cb, 2); 037 cb.add("two"); 038 assertSize(cb, 2); 039 assertEquals("one", cb.get()); 040 assertSize(cb, 1); 041 assertEquals("two", cb.get()); 042 assertSize(cb, 0); 043 } 044 045 @Test 046 public void cloning() { 047 CyclicBuffer<String> cb = new CyclicBuffer<String>(2); 048 cb.add("zero"); 049 cb.add("one"); 050 051 CyclicBuffer<String> clone = new CyclicBuffer<String>(cb); 052 assertSize(clone, 2); 053 cb.clear(); 054 assertSize(cb, 0); 055 056 List<String> witness = Arrays.asList("zero", "one"); 057 assertEquals(witness, clone.asList()); 058 059 } 060}