5
5
6
6
public class NumberBeanTest extends CBORTestBase
7
7
{
8
- static class IntsWrapper {
9
- public int [][] values ;
8
+ static class IntBean {
9
+ public int value ;
10
10
11
- protected IntsWrapper ( ) { }
12
- public IntsWrapper ( int [][] v ) { values = v ; }
11
+ public IntBean ( int v ) { value = v ; }
12
+ protected IntBean ( ) { }
13
13
}
14
14
15
- static class LongsWrapper {
16
- public long [][] values ;
15
+ static class LongBean {
16
+ public long value ;
17
17
18
- protected LongsWrapper () { }
19
- public LongsWrapper (long [][] v ) { values = v ; }
20
- }
21
-
22
- static class DoublesWrapper {
23
- public double [][] values ;
24
-
25
- protected DoublesWrapper () { }
26
- public DoublesWrapper (double [][] v ) { values = v ; }
18
+ public LongBean (long v ) { value = v ; }
19
+ protected LongBean () { }
27
20
}
28
21
29
22
/*
@@ -34,43 +27,33 @@ protected DoublesWrapper() { }
34
27
35
28
private final ObjectMapper MAPPER = cborMapper ();
36
29
37
- public void testIntArrayRoundTrip () throws Exception
30
+ public void testIntRoundTrip () throws Exception
38
31
{
39
- int [][] inputArray = new int [][]{ { - 5 , 3 } };
40
- byte [] cbor = MAPPER . writeValueAsBytes ( new IntsWrapper ( inputArray ));
41
- IntsWrapper result = MAPPER . readValue ( cbor , IntsWrapper . class );
42
- assertNotNull ( result );
43
- assertNotNull ( result . values );
44
- assertEquals ( 1 , result . values . length );
45
- assertEquals ( 2 , result . values [ 0 ]. length );
46
- assertEquals (inputArray [ 0 ][ 0 ] , result .values [ 0 ][ 0 ] );
47
- assertEquals ( inputArray [ 0 ][ 1 ], result . values [ 0 ][ 1 ]);
32
+ for ( int i : new int [] { 0 , 1 , - 1 ,
33
+ 99 , - 120 ,
34
+ 5500 , - 9000 ,
35
+ Integer . MIN_VALUE , Integer . MAX_VALUE }) {
36
+ IntBean input = new IntBean ( i );
37
+ byte [] b = MAPPER . writeValueAsBytes ( input );
38
+ IntBean result = MAPPER . readValue ( b , IntBean . class );
39
+ assertEquals (input . value , result .value );
40
+ }
48
41
}
49
42
50
- public void testLongArrayRoundTrip () throws Exception
51
- {
52
- long [][] inputArray = new long [][]{ { 3L + Integer .MAX_VALUE , -3L + Integer .MIN_VALUE } };
53
- byte [] cbor = MAPPER .writeValueAsBytes (new LongsWrapper (inputArray ));
54
- LongsWrapper result = MAPPER .readValue (cbor , LongsWrapper .class );
55
- assertNotNull (result );
56
- assertNotNull (result .values );
57
- assertEquals (1 , result .values .length );
58
- assertEquals (2 , result .values [0 ].length );
59
- assertEquals (inputArray [0 ][0 ], result .values [0 ][0 ]);
60
- assertEquals (inputArray [0 ][1 ], result .values [0 ][1 ]);
61
- }
62
-
63
- // for [dataformats-binary#31]
64
- public void testDoubleArrayRoundTrip () throws Exception
43
+ public void testLongRoundTrip () throws Exception
65
44
{
66
- double [][] inputArray = new double [][]{ { 0.25 , -1.5 } };
67
- byte [] cbor = MAPPER .writeValueAsBytes (new DoublesWrapper (inputArray ));
68
- DoublesWrapper result = MAPPER .readValue (cbor , DoublesWrapper .class );
69
- assertNotNull (result );
70
- assertNotNull (result .values );
71
- assertEquals (1 , result .values .length );
72
- assertEquals (2 , result .values [0 ].length );
73
- assertEquals (inputArray [0 ][0 ], result .values [0 ][0 ]);
74
- assertEquals (inputArray [0 ][1 ], result .values [0 ][1 ]);
45
+ for (long v : new long [] { 0 , 1 , -1 ,
46
+ 100L , -200L ,
47
+ 5000L , -3600L ,
48
+ Integer .MIN_VALUE , Integer .MAX_VALUE ,
49
+ 1L + Integer .MAX_VALUE , -1L + Integer .MIN_VALUE ,
50
+ 2330462449L , // from [dataformats-binary#30]
51
+ Long .MIN_VALUE , Long .MAX_VALUE
52
+ }) {
53
+ LongBean input = new LongBean (v );
54
+ byte [] b = MAPPER .writeValueAsBytes (input );
55
+ LongBean result = MAPPER .readValue (b , LongBean .class );
56
+ assertEquals (input .value , result .value );
57
+ }
75
58
}
76
59
}
0 commit comments