1
2
3
4
5
6
7 package org.mule.transport.tcp.protocols;
8
9 import java.io.ByteArrayInputStream;
10
11 import org.junit.Test;
12
13 import static org.junit.Assert.assertEquals;
14
15 public class LengthProtocolTestCase extends DefaultProtocolTestCase
16 {
17
18 public LengthProtocolTestCase()
19 {
20 super(new LengthProtocol(), 1);
21 }
22
23 @Test
24 public void testFinalValue() throws Exception
25 {
26 byte[] result = (byte[]) getProtocol().read(new SlowInputStream());
27 assertEquals((byte) SlowInputStream.PAYLOAD, result[0]);
28 }
29
30
31
32 @Test
33 public void testGenerous() throws Exception
34 {
35 byte[] bytes = new byte[SlowInputStream.FULL_LENGTH];
36 for (int i = 0; i < SlowInputStream.FULL_LENGTH; ++i)
37 {
38 bytes[i] = (byte) SlowInputStream.CONTENTS[i];
39 }
40 ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
41 byte[] result = (byte[]) getProtocol().read(bis);
42 assertEquals((byte) SlowInputStream.PAYLOAD, result[0]);
43 }
44
45 }