32
32
* @author dougqh
33
33
*/
34
34
public class TagMapEntryTest {
35
+ @ Test
36
+ public void isNumericPrimitive () {
37
+ assertFalse (TagMap .Entry ._isNumericPrimitive (TagMap .Entry .ANY ));
38
+ assertFalse (TagMap .Entry ._isNumericPrimitive (TagMap .Entry .BOOLEAN ));
39
+ assertFalse (TagMap .Entry ._isNumericPrimitive (TagMap .Entry .CHAR ));
40
+ assertFalse (TagMap .Entry ._isNumericPrimitive (TagMap .Entry .OBJECT ));
41
+
42
+ assertTrue (TagMap .Entry ._isNumericPrimitive (TagMap .Entry .BYTE ));
43
+ assertTrue (TagMap .Entry ._isNumericPrimitive (TagMap .Entry .SHORT ));
44
+ assertTrue (TagMap .Entry ._isNumericPrimitive (TagMap .Entry .INT ));
45
+ assertTrue (TagMap .Entry ._isNumericPrimitive (TagMap .Entry .LONG ));
46
+ assertTrue (TagMap .Entry ._isNumericPrimitive (TagMap .Entry .FLOAT ));
47
+ assertTrue (TagMap .Entry ._isNumericPrimitive (TagMap .Entry .DOUBLE ));
48
+ }
49
+
35
50
@ Test
36
51
public void objectEntry () {
37
52
test (
@@ -42,7 +57,8 @@ public void objectEntry() {
42
57
checkKey ("foo" , entry ),
43
58
checkValue ("bar" , entry ),
44
59
checkEquals ("bar" , entry ::stringValue ),
45
- checkTrue (entry ::isObject )));
60
+ checkTrue (entry ::isObject ),
61
+ checkFalse (entry ::isNumber )));
46
62
}
47
63
48
64
@ Test
@@ -55,6 +71,7 @@ public void anyEntry_object() {
55
71
checkKey ("foo" , entry ),
56
72
checkValue ("bar" , entry ),
57
73
checkTrue (entry ::isObject ),
74
+ checkFalse (entry ::isNumber ),
58
75
checkKey ("foo" , entry ),
59
76
checkValue ("bar" , entry )));
60
77
}
@@ -70,6 +87,7 @@ public void booleanEntry(boolean value) {
70
87
checkKey ("foo" , entry ),
71
88
checkValue (value , entry ),
72
89
checkFalse (entry ::isNumericPrimitive ),
90
+ checkFalse (entry ::isNumber ),
73
91
checkType (TagMap .Entry .BOOLEAN , entry )));
74
92
}
75
93
@@ -84,6 +102,7 @@ public void booleanEntry_boxed(boolean value) {
84
102
checkKey ("foo" , entry ),
85
103
checkValue (value , entry ),
86
104
checkFalse (entry ::isNumericPrimitive ),
105
+ checkFalse (entry ::isNumber ),
87
106
checkType (TagMap .Entry .BOOLEAN , entry )));
88
107
}
89
108
@@ -98,6 +117,7 @@ public void anyEntry_boolean(boolean value) {
98
117
checkKey ("foo" , entry ),
99
118
checkValue (value , entry ),
100
119
checkFalse (entry ::isNumericPrimitive ),
120
+ checkFalse (entry ::isNumber ),
101
121
checkType (TagMap .Entry .BOOLEAN , entry ),
102
122
checkValue (value , entry )));
103
123
}
@@ -112,7 +132,8 @@ public void intEntry(int value) {
112
132
multiCheck (
113
133
checkKey ("foo" , entry ),
114
134
checkValue (value , entry ),
115
- checkTrue (entry ::isNumericPrimitive ),
135
+ checkIsNumericPrimitive (entry ),
136
+ checkInstanceOf (Number .class , entry ),
116
137
checkType (TagMap .Entry .INT , entry )));
117
138
}
118
139
@@ -126,7 +147,8 @@ public void intEntry_boxed(int value) {
126
147
multiCheck (
127
148
checkKey ("foo" , entry ),
128
149
checkValue (value , entry ),
129
- checkTrue (entry ::isNumericPrimitive ),
150
+ checkIsNumericPrimitive (entry ),
151
+ checkInstanceOf (Number .class , entry ),
130
152
checkType (TagMap .Entry .INT , entry )));
131
153
}
132
154
@@ -140,7 +162,8 @@ public void anyEntry_int(int value) {
140
162
multiCheck (
141
163
checkKey ("foo" , entry ),
142
164
checkValue (value , entry ),
143
- checkTrue (entry ::isNumericPrimitive ),
165
+ checkIsNumericPrimitive (entry ),
166
+ checkInstanceOf (Number .class , entry ),
144
167
checkType (TagMap .Entry .INT , entry ),
145
168
checkValue (value , entry )));
146
169
}
@@ -199,7 +222,7 @@ public void longEntry_boxed(long value) {
199
222
multiCheck (
200
223
checkKey ("foo" , entry ),
201
224
checkValue (value , entry ),
202
- checkTrue (entry :: isNumericPrimitive ),
225
+ checkIsNumericPrimitive (entry ),
203
226
checkType (TagMap .Entry .LONG , entry )));
204
227
}
205
228
@@ -228,7 +251,7 @@ public void anyEntry_long(long value) {
228
251
multiCheck (
229
252
checkKey ("foo" , entry ),
230
253
checkValue (value , entry ),
231
- checkTrue (entry :: isNumericPrimitive ),
254
+ checkIsNumericPrimitive (entry ),
232
255
checkTrue (() -> entry .is (TagMap .Entry .LONG )),
233
256
checkValue (value , entry )));
234
257
}
@@ -257,7 +280,7 @@ public void floatEntry_boxed(float value) {
257
280
multiCheck (
258
281
checkKey ("foo" , entry ),
259
282
checkValue (value , entry ),
260
- checkTrue (entry :: isNumericPrimitive ),
283
+ checkIsNumericPrimitive (entry ),
261
284
checkType (TagMap .Entry .FLOAT , entry )));
262
285
}
263
286
@@ -286,7 +309,7 @@ public void doubleEntry(double value) {
286
309
multiCheck (
287
310
checkKey ("foo" , entry ),
288
311
checkValue (value , entry ),
289
- checkTrue (entry :: isNumericPrimitive ),
312
+ checkIsNumericPrimitive (entry ),
290
313
checkType (TagMap .Entry .DOUBLE , entry )));
291
314
}
292
315
@@ -417,6 +440,20 @@ static final Check checkKey(String expected, TagMap.Entry entry) {
417
440
return multiCheck (checkEquals (expected , entry ::tag ), checkEquals (expected , entry ::getKey ));
418
441
}
419
442
443
+ static final Check checkIsNumericPrimitive (TagMap .Entry entry ) {
444
+ return multiCheck (
445
+ checkTrue (entry ::isNumericPrimitive ),
446
+ checkTrue (entry ::isNumber ),
447
+ checkInstanceOf (Number .class , entry ));
448
+ }
449
+
450
+ static final Check checkIsBigNumber (TagMap .Entry entry ) {
451
+ return multiCheck (
452
+ checkFalse (entry ::isNumericPrimitive ),
453
+ checkTrue (entry ::isNumber ),
454
+ checkInstanceOf (Number .class , entry ));
455
+ }
456
+
420
457
static final Check checkValue (Object expected , TagMap .Entry entry ) {
421
458
return multiCheck (
422
459
checkEquals (expected , entry ::objectValue ),
@@ -468,6 +505,16 @@ static final Check checkValue(double expected, TagMap.Entry entry) {
468
505
checkEquals (Double .toString (expected ), entry ::stringValue ));
469
506
}
470
507
508
+ public static Check checkNumber (Number number , TagMap .Entry entry ) {
509
+ return multiCheck (
510
+ checkEquals (number , entry ::objectValue ),
511
+ checkEquals (number .intValue (), entry ::intValue ),
512
+ checkEquals (number .longValue (), entry ::longValue ),
513
+ checkEquals (number .floatValue (), entry ::floatValue ),
514
+ checkEquals (number .doubleValue (), entry ::doubleValue ),
515
+ checkEquals (number .toString (), entry ::stringValue ));
516
+ }
517
+
471
518
static final Check checkValue (float expected , TagMap .Entry entry ) {
472
519
return multiCheck (
473
520
checkEquals (expected , entry ::floatValue ),
@@ -479,6 +526,13 @@ static final Check checkValue(float expected, TagMap.Entry entry) {
479
526
checkEquals (Float .toString (expected ), entry ::stringValue ));
480
527
}
481
528
529
+ static final Check checkInstanceOf (Class <?> klass , TagMap .Entry entry ) {
530
+ return () ->
531
+ assertTrue (
532
+ klass .isAssignableFrom (entry .objectValue ().getClass ()),
533
+ "instanceof " + klass .getSimpleName ());
534
+ }
535
+
482
536
static final Check checkType (byte entryType , TagMap .Entry entry ) {
483
537
return () -> assertTrue (entry .is (entryType ), "type is " + entryType );
484
538
}
@@ -496,23 +550,23 @@ static final Check checkTrue(Supplier<Boolean> actual) {
496
550
}
497
551
498
552
static final Check checkEquals (float expected , Supplier <Float > actual ) {
499
- return () -> assertEquals (expected , actual .get (), actual .toString ());
553
+ return () -> assertEquals (expected , actual .get (). floatValue () , actual .toString ());
500
554
}
501
555
502
556
static final Check checkEquals (int expected , Supplier <Integer > actual ) {
503
- return () -> assertEquals (expected , actual .get (), actual .toString ());
557
+ return () -> assertEquals (expected , actual .get (). intValue () , actual .toString ());
504
558
}
505
559
506
560
static final Check checkEquals (double expected , Supplier <Double > actual ) {
507
- return () -> assertEquals (expected , actual .get (), actual .toString ());
561
+ return () -> assertEquals (expected , actual .get (). doubleValue () , actual .toString ());
508
562
}
509
563
510
564
static final Check checkEquals (long expected , Supplier <Long > actual ) {
511
- return () -> assertEquals (expected , actual .get (), actual .toString ());
565
+ return () -> assertEquals (expected , actual .get (). longValue () , actual .toString ());
512
566
}
513
567
514
568
static final Check checkEquals (boolean expected , Supplier <Boolean > actual ) {
515
- return () -> assertEquals (expected , actual .get (), actual .toString ());
569
+ return () -> assertEquals (expected , actual .get (). booleanValue () , actual .toString ());
516
570
}
517
571
518
572
static final Check checkEquals (Object expected , Supplier <Object > actual ) {
0 commit comments