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 EnforceHandlerTest extends TestCase { 33 Pipeline pipeline; 34 35 public void testOwnAnEnforcedHandler () { 36 PipelineComponent enforced = AllHandler.ACCEPT(); 37 EnforceHandler enforceHandler = (EnforceHandler)EnforceHandler.ENFORCE(enforced); 38 pipeline.putFront(enforceHandler); 39 40 assertTrue(true); 41 assertSame(enforced, enforceHandler.getEnforcedComponents()[0]); 42 assertSame("enforced pipeline should be the same of the enforcing one", enforceHandler.getPipeline(), enforced.getPipeline()); 43 } 44 45 public void testThrowExceptionWhenEnforcedDoesNotHandle () throws PipelineException, IllegalInputCharacterException { 46 PipelineComponent enforceHandler = EnforceHandler.ENFORCE(new MockHandler()); 47 pipeline.putFront(enforceHandler); 48 try { 49 enforceHandler.handle('x'); 50 fail ("Enforce handler should have thrown an exception"); 51 } catch (IllegalInputCharacterException illEx) {} 52 53 } 54 55 public void testDontRemoveItselfOnException () throws PipelineException, IllegalInputCharacterException { 56 PipelineComponent enforceHandler = EnforceHandler.ENFORCE(new MockHandler()); 57 pipeline.putFront(enforceHandler); 58 try { 59 pipeline.handle('x'); 60 fail ("Enforce handler should have thrown an exception"); 61 } catch (IllegalInputCharacterException illEx) {} 62 63 assertSame(pipeline.removeFront(), enforceHandler); 64 } 65 66 public void testRemoveItselfAfterEnforcing () throws PipelineException, IllegalInputCharacterException { 67 PipelineComponent enforceHandler = EnforceHandler.ENFORCE(AllHandler.ACCEPT()); 68 pipeline.putFront(enforceHandler); 69 pipeline.handle('\"'); 70 pipeline.thePieceIsDone(); 71 assertNotSame(pipeline.removeFront(), enforceHandler); 72 assertEquals(1, pipeline.getProducts().size()); 73 assertEquals("\"", pipeline.getProducts().get(0)); 74 } 75 76 public void testEnforceOneBetweenMany () throws PipelineException, IllegalInputCharacterException { 77 PipelineComponent pass = SeparatorHandler.ACCEPT(); 78 PipelineComponent accept = AllHandler.ACCEPT(); 79 EnforceHandler enforceHandler = (EnforceHandler)EnforceHandler.ENFORCE(new PipelineComponent [] {pass, accept}); 80 pipeline.putFront(enforceHandler); 81 82 pipeline.handle('\"'); 83 pipeline.thePieceIsDone(); 84 85 assertNotSame(pipeline.removeFront(), enforceHandler); 86 assertEquals(1, pipeline.getProducts().size()); 87 assertEquals("\"", pipeline.getProducts().get(0)); 88 } 89 90 protected void setUp() throws Exception { 91 pipeline = new Pipeline(); 92 } 93 94 } 95 | Popular Tags |