1 16 package org.apache.commons.collections; 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.collection.AbstractTestCollection; 25 26 33 public class TestBoundedFifoBuffer extends AbstractTestCollection { 34 35 public TestBoundedFifoBuffer(String n) { 36 super(n); 37 } 38 39 public static Test suite() { 40 return BulkTest.makeSuite(TestBoundedFifoBuffer.class); 41 } 42 43 49 public void verify() { 50 super.verify(); 51 Iterator iterator1 = collection.iterator(); 52 Iterator iterator2 = confirmed.iterator(); 53 while (iterator2.hasNext()) { 54 assertTrue(iterator1.hasNext()); 55 Object o1 = iterator1.next(); 56 Object o2 = iterator2.next(); 57 assertEquals(o1, o2); 58 } 59 } 60 61 66 public boolean isNullSupported() { 67 return false; 68 } 69 70 74 public boolean isFailFastSupported() { 75 return false; 76 } 77 78 84 public Collection makeConfirmedCollection() { 85 return new ArrayList (); 86 } 87 88 93 public Collection makeConfirmedFullCollection() { 94 Collection c = makeConfirmedCollection(); 95 c.addAll(java.util.Arrays.asList(getFullElements())); 96 return c; 97 } 98 99 104 public Collection makeCollection() { 105 return new BoundedFifoBuffer(100); 106 } 107 108 112 public void testBoundedFifoBufferRemove() { 113 resetFull(); 114 int size = confirmed.size(); 115 for (int i = 0; i < size; i++) { 116 Object o1 = ((BoundedFifoBuffer)collection).remove(); 117 Object o2 = ((ArrayList )confirmed).remove(0); 118 assertEquals("Removed objects should be equal", o1, o2); 119 verify(); 120 } 121 122 try { 123 ((BoundedFifoBuffer)collection).remove(); 124 fail("Empty buffer should raise Underflow."); 125 } catch (BufferUnderflowException e) { 126 } 128 } 129 130 133 public void testConstructorException1() { 134 try { 135 new BoundedFifoBuffer(0); 136 } catch (IllegalArgumentException ex) { 137 return; 138 } 139 fail(); 140 } 141 142 145 public void testConstructorException2() { 146 try { 147 new BoundedFifoBuffer(-20); 148 } catch (IllegalArgumentException ex) { 149 return; 150 } 151 fail(); 152 } 153 154 157 public void testConstructorException3() { 158 try { 159 new BoundedFifoBuffer(null); 160 } catch (NullPointerException ex) { 161 return; 162 } 163 fail(); 164 } 165 } 166 | Popular Tags |