1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.mina.handler.chain;
21
22 import org.apache.mina.core.session.DummySession;
23 import org.apache.mina.core.session.IoSession;
24 import org.junit.Test;
25 import static org.junit.Assert.assertEquals;
26
27
28
29
30
31
32
33 public class ChainedIoHandlerTest {
34 @Test
35 public void testChainedCommand() throws Exception {
36 IoHandlerChain chain = new IoHandlerChain();
37 StringBuilder buf = new StringBuilder();
38 chain.addLast("A", new TestCommand(buf, 'A'));
39 chain.addLast("B", new TestCommand(buf, 'B'));
40 chain.addLast("C", new TestCommand(buf, 'C'));
41
42 new ChainedIoHandler(chain).messageReceived(new DummySession(), null);
43
44 assertEquals("ABC", buf.toString());
45 }
46
47 private class TestCommand implements IoHandlerCommand {
48 private final StringBuilder buf;
49
50 private final char ch;
51
52 private TestCommand(StringBuilder buf, char ch) {
53 this.buf = buf;
54 this.ch = ch;
55 }
56
57 public void execute(NextCommand next, IoSession session, Object message)
58 throws Exception {
59 buf.append(ch);
60 next.execute(session, message);
61 }
62 }
63 }