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 22 import junit.framework.Test; 23 24 import org.apache.commons.collections.BufferUnderflowException; 25 import org.apache.commons.collections.BulkTest; 26 import org.apache.commons.collections.collection.AbstractTestCollection; 27 28 35 public class TestBoundedFifoBuffer extends AbstractTestCollection { 36 37 public TestBoundedFifoBuffer(String n) { 38 super(n); 39 } 40 41 public static Test suite() { 42 return BulkTest.makeSuite(TestBoundedFifoBuffer.class); 43 } 44 45 51 public void verify() { 52 super.verify(); 53 Iterator iterator1 = collection.iterator(); 54 Iterator iterator2 = confirmed.iterator(); 55 while (iterator2.hasNext()) { 56 assertTrue(iterator1.hasNext()); 57 Object o1 = iterator1.next(); 58 Object o2 = iterator2.next(); 59 assertEquals(o1, o2); 60 } 61 } 62 63 68 public boolean isNullSupported() { 69 return false; 70 } 71 72 76 public boolean isFailFastSupported() { 77 return false; 78 } 79 80 86 public Collection makeConfirmedCollection() { 87 return new ArrayList (); 88 } 89 90 95 public Collection makeConfirmedFullCollection() { 96 Collection c = makeConfirmedCollection(); 97 c.addAll(java.util.Arrays.asList(getFullElements())); 98 return c; 99 } 100 101 106 public Collection makeCollection() { 107 return new BoundedFifoBuffer(100); 108 } 109 110 114 public void testBoundedFifoBufferRemove() { 115 resetFull(); 116 int size = confirmed.size(); 117 for (int i = 0; i < size; i++) { 118 Object o1 = ((BoundedFifoBuffer)collection).remove(); 119 Object o2 = ((ArrayList )confirmed).remove(0); 120 assertEquals("Removed objects should be equal", o1, o2); 121 verify(); 122 } 123 124 try { 125 ((BoundedFifoBuffer)collection).remove(); 126 fail("Empty buffer should raise Underflow."); 127 } catch (BufferUnderflowException e) { 128 } 130 } 131 132 135 public void testConstructorException1() { 136 try { 137 new BoundedFifoBuffer(0); 138 } catch (IllegalArgumentException ex) { 139 return; 140 } 141 fail(); 142 } 143 144 147 public void testConstructorException2() { 148 try { 149 new BoundedFifoBuffer(-20); 150 } catch (IllegalArgumentException ex) { 151 return; 152 } 153 fail(); 154 } 155 156 159 public void testConstructorException3() { 160 try { 161 new BoundedFifoBuffer(null); 162 } catch (NullPointerException ex) { 163 return; 164 } 165 fail(); 166 } 167 168 public String getCompatibilityVersion() { 169 return "3.1"; 170 } 171 172 179 } 180 | Popular Tags |