|
@@ -3,7 +3,6 @@ |
3 |
3 |
|
|
4 |
4 |
|
import junit.framework.*; |
5 |
5 |
|
|
6 |
|
- |
import org.litesoft.core.annotations.*; |
7 |
6 |
|
import org.litesoft.core.util.*; |
8 |
7 |
|
|
9 |
8 |
|
public class IntegerCodecTest extends TestCase |
|
@@ -33,7 +32,7 @@ |
33 |
32 |
|
checkNegatives( zCodec ); |
34 |
33 |
|
|
35 |
34 |
|
checkNonNegatives( zCodec ); |
36 |
|
- |
checkBadChar( zCodec ); |
|
35 |
+ |
checkBadStrings( zCodec ); |
37 |
36 |
|
} |
38 |
37 |
|
|
39 |
38 |
|
public void test_NonNegative() |
|
@@ -44,7 +43,7 @@ |
44 |
43 |
|
checkRT( zCodec, null ); |
45 |
44 |
|
|
46 |
45 |
|
checkNonNegatives( zCodec ); |
47 |
|
- |
checkBadChar( zCodec ); |
|
46 |
+ |
checkBadStrings( zCodec ); |
48 |
47 |
|
} |
49 |
48 |
|
|
50 |
49 |
|
public void test_SignedPrimitive() |
|
@@ -55,7 +54,7 @@ |
55 |
54 |
|
checkNegatives( zCodec ); |
56 |
55 |
|
|
57 |
56 |
|
checkNonNegatives( zCodec ); |
58 |
|
- |
checkBadChar( zCodec ); |
|
57 |
+ |
checkBadStrings( zCodec ); |
59 |
58 |
|
} |
60 |
59 |
|
|
61 |
60 |
|
public void test_NonNegativePrimitive() |
|
@@ -64,10 +63,10 @@ |
64 |
63 |
|
Codec<Integer> zCodec = new PrimitiveAdapter( IntegerCodec.NonNegativePrimitive.INSTANCE ); |
65 |
64 |
|
|
66 |
65 |
|
checkNonNegatives( zCodec ); |
67 |
|
- |
checkBadChar( zCodec ); |
|
66 |
+ |
checkBadStrings( zCodec ); |
68 |
67 |
|
} |
69 |
68 |
|
|
70 |
|
- |
private void checkBadChar( Codec<Integer> pCodec ) |
|
69 |
+ |
private void checkBadStrings( Codec<Integer> pCodec ) |
71 |
70 |
|
{ |
72 |
71 |
|
try |
73 |
72 |
|
{ |
|
@@ -78,6 +77,16 @@ |
78 |
77 |
|
{ |
79 |
78 |
|
// OK |
80 |
79 |
|
} |
|
80 |
+ |
String zEncoded = pCodec.encode( 1 ); |
|
81 |
+ |
try |
|
82 |
+ |
{ |
|
83 |
+ |
pCodec.decode( zEncoded + AbstractCodec.NULL_AS_STRING ); |
|
84 |
+ |
fail( "Extra Char OK?" ); |
|
85 |
+ |
} |
|
86 |
+ |
catch ( IllegalArgumentException expected ) |
|
87 |
+ |
{ |
|
88 |
+ |
// OK |
|
89 |
+ |
} |
81 |
90 |
|
} |
82 |
91 |
|
|
83 |
92 |
|
private void checkNegatives( Codec<Integer> pCodec ) |
|
@@ -126,8 +135,8 @@ |
126 |
135 |
|
private void checkRT( Codec<Integer> pCodec, Integer pValue ) |
127 |
136 |
|
{ |
128 |
137 |
|
String encoded = pCodec.encode( pValue ); |
129 |
|
- |
Integer rtInteger = pCodec.decode( encoded ); |
130 |
|
- |
assertEquals( "RT " + pCodec.getClass().getSimpleName() + " (" + encoded + ") ", pValue, rtInteger ); |
|
138 |
+ |
Integer rtValue = pCodec.decode( encoded ); |
|
139 |
+ |
assertEquals( "RT " + pCodec.getClass().getSimpleName() + " (" + encoded + ") ", pValue, rtValue ); |
131 |
140 |
|
System.out.println( "RT " + pCodec.getClass().getSimpleName() + " " + pValue + ": " + encoded ); |
132 |
141 |
|
} |
133 |
142 |
|
|
|
@@ -141,14 +150,15 @@ |
141 |
150 |
|
} |
142 |
151 |
|
|
143 |
152 |
|
@Override |
144 |
|
- |
public String encode( @Nullable Integer pValue ) |
|
153 |
+ |
protected String encodeNonNull( Integer pValue ) |
145 |
154 |
|
{ |
146 |
155 |
|
return mPrimitive.encode( pValue ); |
147 |
156 |
|
} |
148 |
157 |
|
|
149 |
|
- |
@Override public Integer decode( @NotNull CharSource pValue ) |
|
158 |
+ |
@Override |
|
159 |
+ |
protected Integer decodeNonNull( CharSource pCharSource ) |
150 |
160 |
|
{ |
151 |
|
- |
return mPrimitive.decode( pValue ); |
|
161 |
+ |
return mPrimitive.decode( pCharSource ); |
152 |
162 |
|
} |
153 |
163 |
|
} |
154 |
164 |
|
} |