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