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