1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.mina.codec.delimited;
21
22 import static org.junit.Assert.assertEquals;
23
24 import java.nio.ByteBuffer;
25 import java.util.LinkedList;
26 import java.util.List;
27
28 import org.junit.Test;
29
30
31
32
33
34
35 public abstract class DelimitTest<T> {
36
37 public abstract List<T> getObjects();
38
39 protected abstract ByteBuffer delimitWithOriginal() throws Exception;
40
41 public abstract SizePrefixedEncoder<T> getSerializer() throws Exception;
42
43 final protected ByteBuffer delimitWithMina() throws Exception {
44 SizePrefixedEncoder<T> pe = getSerializer();
45
46 List<ByteBuffer> buffers = new LinkedList<ByteBuffer>();
47 for (T p : getObjects()) {
48 buffers.add(pe.encode(p, null));
49 }
50
51 int size = 0;
52 for (ByteBuffer b : buffers) {
53 size += b.remaining();
54 }
55
56 ByteBuffer buffer = ByteBuffer.allocate(size);
57 for (ByteBuffer b : buffers) {
58 buffer.put(b);
59 }
60 buffer.flip();
61 return buffer;
62 }
63
64 @Test
65 public void testDelimit() throws Exception {
66 assertEquals(delimitWithOriginal(), delimitWithMina());
67 }
68
69 }