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 public class ChainedIoHandlerTest {
33 @Test
34 public void testChainedCommand() throws Exception {
35 IoHandlerChain chain = new IoHandlerChain();
36 StringBuilder buf = new StringBuilder();
37 chain.addLast("A", new TestCommand(buf, 'A'));
38 chain.addLast("B", new TestCommand(buf, 'B'));
39 chain.addLast("C", new TestCommand(buf, 'C'));
40
41 new ChainedIoHandler(chain).messageReceived(new DummySession(), null);
42
43 assertEquals("ABC", buf.toString());
44 }
45
46 private class TestCommand implements IoHandlerCommand {
47 private final StringBuilder buf;
48
49 private final char ch;
50
51 public TestCommand(StringBuilder buf, char ch) {
52 this.buf = buf;
53 this.ch = ch;
54 }
55
56 public void execute(NextCommand next, IoSession session, Object message) throws Exception {
57 buf.append(ch);
58 next.execute(session, message);
59 }
60 }
61 }