1 21 22 package org.dbunit.dataset.csv.handlers; 23 24 import junit.framework.TestCase; 25 import org.dbunit.dataset.csv.IllegalInputCharacterException; 26 27 32 public class PipelineTest extends TestCase { 33 Pipeline line; 34 35 public void testRemovingTheLastHandlerThrowsException () { 36 try { 37 line.removeFront(); 38 line.removeFront(); 39 fail ("Removing from an ampty pipeline should throw an exception"); 40 } catch (PipelineException e) {} 41 } 42 43 public void testAnHandlerCanBeAddedInFront () throws PipelineException { 44 PipelineComponent handler = SeparatorHandler.ACCEPT(); 45 line.putFront(handler); 46 assertSame(handler, line.removeFront()); 47 assertSame(line, handler.getPipeline()); 48 } 49 50 public void testTheFrontHandlerIsThereAfterAddingAndRemovingAnother () throws PipelineException { 51 PipelineComponent handler = SeparatorHandler.ACCEPT(); 52 PipelineComponent handler2 = SeparatorHandler.ACCEPT(); 53 line.putFront(handler); 54 line.putFront(handler2); 55 assertSame(handler2, line.removeFront()); 56 assertSame(handler, line.removeFront()); 57 } 58 59 public void testEachHandlerIsCalled () throws IllegalInputCharacterException, PipelineException { 60 MockHandler component = new MockHandler(); 61 MockHandler component2 = new MockHandler(); 62 component.setExpectedHandleCalls(1); 63 component2.setExpectedHandleCalls(1); 64 line.putFront(component); 65 line.putFront(component2); 66 67 try { 69 line.handle('x'); 70 fail("Exception expected"); 71 } catch (IllegalInputCharacterException seen) {} 72 73 component.verify(); 74 component2.verify(); 75 } 76 77 public void testWhenAPieceIsDoneIsAddedToProducts () throws IllegalInputCharacterException, PipelineException { 78 PipelineComponent c = AllHandler.ACCEPT(); 79 line.putFront(c); 80 line.handle('x'); 81 line.thePieceIsDone(); 82 assertEquals(1, line.getProducts().size()); 83 assertEquals("x", line.getProducts().get(0)); 84 } 85 86 public void testWhetAPieceIsDoneANewOneIsCreated () throws IllegalInputCharacterException, PipelineException { 87 PipelineComponent c = AllHandler.ACCEPT(); 88 line.putFront(c); 89 line.handle('x'); 90 line.thePieceIsDone(); 91 assertEquals("", line.getCurrentProduct().toString()); 92 } 93 94 95 protected void setUp() throws Exception { 96 line = new Pipeline(); 97 } 98 } 99 | Popular Tags |