1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.dbunit.dataset.common.handlers;
23
24 import junit.framework.TestCase;
25
26
27
28
29
30
31 public class EnforceHandlerTest extends TestCase {
32 Pipeline pipeline;
33
34 public void testOwnAnEnforcedHandler () {
35 PipelineComponent enforced = AllHandler.ACCEPT();
36 EnforceHandler enforceHandler = (EnforceHandler)EnforceHandler.ENFORCE(enforced);
37 pipeline.putFront(enforceHandler);
38
39 assertTrue(true);
40 assertSame(enforced, enforceHandler.getEnforcedComponents()[0]);
41 assertSame("enforced pipeline should be the same of the enforcing one", enforceHandler.getPipeline(), enforced.getPipeline());
42 }
43
44 public void testThrowExceptionWhenEnforcedDoesNotHandle () throws PipelineException, IllegalInputCharacterException {
45 PipelineComponent enforceHandler = EnforceHandler.ENFORCE(new MockHandler());
46 pipeline.putFront(enforceHandler);
47 try {
48 enforceHandler.handle('x');
49 fail ("Enforce handler should have thrown an exception");
50 } catch (IllegalInputCharacterException illEx) {}
51
52 }
53
54 public void testDontRemoveItselfOnException () throws PipelineException, IllegalInputCharacterException {
55 PipelineComponent enforceHandler = EnforceHandler.ENFORCE(new MockHandler());
56 pipeline.putFront(enforceHandler);
57 try {
58 pipeline.handle('x');
59 fail ("Enforce handler should have thrown an exception");
60 } catch (IllegalInputCharacterException illEx) {}
61
62 assertSame(pipeline.removeFront(), enforceHandler);
63 }
64
65 public void testRemoveItselfAfterEnforcing () throws PipelineException, IllegalInputCharacterException {
66 PipelineComponent enforceHandler = EnforceHandler.ENFORCE(AllHandler.ACCEPT());
67 pipeline.putFront(enforceHandler);
68 pipeline.handle('\"');
69 pipeline.thePieceIsDone();
70 assertNotSame(pipeline.removeFront(), enforceHandler);
71 assertEquals(1, pipeline.getProducts().size());
72 assertEquals("\"", pipeline.getProducts().get(0));
73 }
74
75 public void testEnforceOneBetweenMany () throws PipelineException, IllegalInputCharacterException {
76 PipelineComponent pass = SeparatorHandler.ACCEPT();
77 PipelineComponent accept = AllHandler.ACCEPT();
78 EnforceHandler enforceHandler = (EnforceHandler)EnforceHandler.ENFORCE(new PipelineComponent [] {pass, accept});
79 pipeline.putFront(enforceHandler);
80
81 pipeline.handle('\"');
82 pipeline.thePieceIsDone();
83
84 assertNotSame(pipeline.removeFront(), enforceHandler);
85 assertEquals(1, pipeline.getProducts().size());
86 assertEquals("\"", pipeline.getProducts().get(0));
87 }
88
89 protected void setUp() throws Exception {
90 pipeline = new Pipeline();
91 }
92
93 }