1 16 package org.apache.commons.collections.buffer; 17 18 import java.util.ArrayList ; 19 import java.util.Collection ; 20 import java.util.Iterator ; 21 import java.util.List ; 22 23 import junit.framework.Test; 24 25 import org.apache.commons.collections.Buffer; 26 import org.apache.commons.collections.BufferUnderflowException; 27 import org.apache.commons.collections.BulkTest; 28 import org.apache.commons.collections.collection.AbstractTestCollection; 29 30 37 public class TestCircularFifoBuffer extends AbstractTestCollection { 38 39 public TestCircularFifoBuffer(String n) { 40 super(n); 41 } 42 43 public static Test suite() { 44 return BulkTest.makeSuite(TestCircularFifoBuffer.class); 45 } 46 47 53 public void verify() { 54 super.verify(); 55 Iterator iterator1 = collection.iterator(); 56 Iterator iterator2 = confirmed.iterator(); 57 while (iterator2.hasNext()) { 58 assertTrue(iterator1.hasNext()); 59 Object o1 = iterator1.next(); 60 Object o2 = iterator2.next(); 61 assertEquals(o1, o2); 62 } 63 } 64 65 70 public boolean isNullSupported() { 71 return false; 72 } 73 74 78 public boolean isFailFastSupported() { 79 return false; 80 } 81 82 88 public Collection makeConfirmedCollection() { 89 return new ArrayList (); 90 } 91 92 97 public Collection makeConfirmedFullCollection() { 98 Collection c = makeConfirmedCollection(); 99 c.addAll(java.util.Arrays.asList(getFullElements())); 100 return c; 101 } 102 103 108 public Collection makeCollection() { 109 return new CircularFifoBuffer(100); 110 } 111 112 116 public void testCircularFifoBufferCircular() { 117 List list = new ArrayList (); 118 list.add("A"); 119 list.add("B"); 120 list.add("C"); 121 Buffer buf = new CircularFifoBuffer(list); 122 123 assertEquals(true, buf.contains("A")); 124 assertEquals(true, buf.contains("B")); 125 assertEquals(true, buf.contains("C")); 126 127 buf.add("D"); 128 129 assertEquals(false, buf.contains("A")); 130 assertEquals(true, buf.contains("B")); 131 assertEquals(true, buf.contains("C")); 132 assertEquals(true, buf.contains("D")); 133 134 assertEquals("B", buf.get()); 135 assertEquals("B", buf.remove()); 136 assertEquals("C", buf.remove()); 137 assertEquals("D", buf.remove()); 138 } 139 140 143 public void testCircularFifoBufferRemove() { 144 resetFull(); 145 int size = confirmed.size(); 146 for (int i = 0; i < size; i++) { 147 Object o1 = ((CircularFifoBuffer) collection).remove(); 148 Object o2 = ((ArrayList ) confirmed).remove(0); 149 assertEquals("Removed objects should be equal", o1, o2); 150 verify(); 151 } 152 153 try { 154 ((CircularFifoBuffer) collection).remove(); 155 fail("Empty buffer should raise Underflow."); 156 } catch (BufferUnderflowException e) { 157 } 159 } 160 161 164 public void testConstructorException1() { 165 try { 166 new CircularFifoBuffer(0); 167 } catch (IllegalArgumentException ex) { 168 return; 169 } 170 fail(); 171 } 172 173 176 public void testConstructorException2() { 177 try { 178 new CircularFifoBuffer(-20); 179 } catch (IllegalArgumentException ex) { 180 return; 181 } 182 fail(); 183 } 184 185 188 public void testConstructorException3() { 189 try { 190 new CircularFifoBuffer(null); 191 } catch (NullPointerException ex) { 192 return; 193 } 194 fail(); 195 } 196 197 public String getCompatibilityVersion() { 198 return "3.1"; 199 } 200 201 208 } 209 | Popular Tags |