1 16 package org.apache.commons.collections.buffer; 17 18 import java.util.Collection ; 19 20 import junit.framework.Test; 21 import junit.framework.TestSuite; 22 23 import org.apache.commons.collections.ArrayStack; 24 import org.apache.commons.collections.Buffer; 25 import org.apache.commons.collections.BufferUnderflowException; 26 import org.apache.commons.collections.Predicate; 27 import org.apache.commons.collections.collection.TestPredicatedCollection; 28 29 38 public class TestPredicatedBuffer extends TestPredicatedCollection { 39 40 public TestPredicatedBuffer(String testName) { 41 super(testName); 42 } 43 44 public static Test suite() { 45 return new TestSuite(TestPredicatedBuffer.class); 46 } 47 48 public static void main(String args[]) { 49 String [] testCaseName = { TestPredicatedBuffer.class.getName()}; 50 junit.textui.TestRunner.main(testCaseName); 51 } 52 53 55 protected Buffer decorateBuffer(Buffer buffer, Predicate predicate) { 56 return PredicatedBuffer.decorate(buffer, predicate); 57 } 58 59 public Collection makeCollection() { 60 return decorateBuffer(new ArrayStack(), truePredicate); 61 } 62 63 public Collection makeConfirmedCollection() { 64 return new ArrayStack(); 65 } 66 67 public Collection makeConfirmedFullCollection() { 68 ArrayStack list = new ArrayStack(); 69 list.addAll(java.util.Arrays.asList(getFullElements())); 70 return list; 71 } 72 73 75 public Buffer makeTestBuffer() { 76 return decorateBuffer(new ArrayStack(), testPredicate); 77 } 78 79 public void testGet() { 80 Buffer buffer = makeTestBuffer(); 81 try { 82 Object o = buffer.get(); 83 fail("Expecting BufferUnderflowException"); 84 } catch (BufferUnderflowException ex) { 85 } 87 buffer.add("one"); 88 buffer.add("two"); 89 buffer.add("three"); 90 assertEquals("Buffer get", buffer.get(), "three"); 91 } 92 93 public void testRemove() { 94 Buffer buffer = makeTestBuffer(); 95 buffer.add("one"); 96 assertEquals("Buffer get", buffer.remove(), "one"); 97 try { 98 buffer.remove(); 99 fail("Expecting BufferUnderflowException"); 100 } catch (BufferUnderflowException ex) { 101 } 103 } 104 105 public String getCompatibilityVersion() { 106 return "3.1"; 107 } 108 109 116 } 117 | Popular Tags |