0
|
1 package org.msgpack.unpacker;
|
|
2
|
|
3 import static org.junit.Assert.assertNull;
|
|
4
|
|
5 import java.io.IOException;
|
|
6 import java.nio.ByteBuffer;
|
|
7 import java.util.List;
|
|
8 import java.util.Map;
|
|
9 import java.util.Collection;
|
|
10 import java.util.Date;
|
|
11 import java.math.BigInteger;
|
|
12 import java.math.BigDecimal;
|
|
13
|
|
14 import org.msgpack.MessagePack;
|
|
15 import org.msgpack.packer.BufferPacker;
|
|
16 import org.msgpack.template.Templates;
|
|
17 import org.msgpack.unpacker.Unpacker;
|
|
18
|
|
19 import org.junit.Test;
|
|
20
|
|
21 public class TestReadTemplate {
|
|
22 public static enum MyEnum {
|
|
23 A, B, C;
|
|
24 }
|
|
25
|
|
26 @Test
|
|
27 public void testReadTemplateNull() throws IOException {
|
|
28 Byte tbyte = u().read(Templates.TByte);
|
|
29 assertNull(tbyte);
|
|
30
|
|
31 Short tshort = u().read(Templates.TShort);
|
|
32 assertNull(tshort);
|
|
33
|
|
34 Integer tinteger = u().read(Templates.TInteger);
|
|
35 assertNull(tinteger);
|
|
36
|
|
37 Long tlong = u().read(Templates.TLong);
|
|
38 assertNull(tlong);
|
|
39
|
|
40 Character tcharacter = u().read(Templates.TCharacter);
|
|
41 assertNull(tcharacter);
|
|
42
|
|
43 BigInteger tbiginteger = u().read(Templates.TBigInteger);
|
|
44 assertNull(tbiginteger);
|
|
45
|
|
46 BigDecimal tbigdecimail = u().read(Templates.TBigDecimal);
|
|
47 assertNull(tbigdecimail);
|
|
48
|
|
49 Float tfloat = u().read(Templates.TFloat);
|
|
50 assertNull(tfloat);
|
|
51
|
|
52 Double tdouble = u().read(Templates.TDouble);
|
|
53 assertNull(tdouble);
|
|
54
|
|
55 Boolean tboolean = u().read(Templates.TBoolean);
|
|
56 assertNull(tboolean);
|
|
57
|
|
58 String tstring = u().read(Templates.TString);
|
|
59 assertNull(tstring);
|
|
60
|
|
61 byte[] tbytearray = u().read(Templates.TByteArray);
|
|
62 assertNull(tbytearray);
|
|
63
|
|
64 ByteBuffer tbytebuffer = u().read(Templates.TByteBuffer);
|
|
65 assertNull(tbytebuffer);
|
|
66
|
|
67 Date tdate = u().read(Templates.TDate);
|
|
68 assertNull(tdate);
|
|
69
|
|
70 List<String> tlist = u().read(Templates.tList(Templates.TString));
|
|
71 assertNull(tlist);
|
|
72
|
|
73 Map<String, Integer> tmap = u().read(
|
|
74 Templates.tMap(Templates.TString, Templates.TInteger));
|
|
75 assertNull(tmap);
|
|
76
|
|
77 Collection<Long> tcollection = u().read(
|
|
78 Templates.tCollection(Templates.TLong));
|
|
79 assertNull(tcollection);
|
|
80
|
|
81 MyEnum tordinalenum = u().read(Templates.tOrdinalEnum(MyEnum.class));
|
|
82 assertNull(tordinalenum);
|
|
83 }
|
|
84
|
|
85 // return unpacker that can read a nil
|
|
86 private Unpacker u() throws IOException {
|
|
87 MessagePack msgpack = new MessagePack();
|
|
88 BufferPacker pk = msgpack.createBufferPacker();
|
|
89 pk.writeNil();
|
|
90 Unpacker u = msgpack.createBufferUnpacker(pk.toByteArray());
|
|
91 return u;
|
|
92 }
|
|
93 }
|