69 |
|
* |
70 |
|
* </ol> |
71 |
|
* |
72 |
< |
* <p> <b>Other notes</b> |
72 |
> |
* <p><b>Other notes</b> |
73 |
|
* <ul> |
74 |
|
* |
75 |
|
* <li> Usually, there is one testcase method per JSR166 method |
1202 |
|
} |
1203 |
|
} |
1204 |
|
|
1205 |
< |
@SuppressWarnings("unchecked") |
1206 |
< |
<T> T serialClone(T o) { |
1205 |
> |
void assertSerialEquals(Object x, Object y) { |
1206 |
> |
assertTrue(Arrays.equals(serialBytes(x), serialBytes(y))); |
1207 |
> |
} |
1208 |
> |
|
1209 |
> |
void assertNotSerialEquals(Object x, Object y) { |
1210 |
> |
assertFalse(Arrays.equals(serialBytes(x), serialBytes(y))); |
1211 |
> |
} |
1212 |
> |
|
1213 |
> |
byte[] serialBytes(Object o) { |
1214 |
|
try { |
1215 |
|
ByteArrayOutputStream bos = new ByteArrayOutputStream(); |
1216 |
|
ObjectOutputStream oos = new ObjectOutputStream(bos); |
1217 |
|
oos.writeObject(o); |
1218 |
|
oos.flush(); |
1219 |
|
oos.close(); |
1220 |
+ |
return bos.toByteArray(); |
1221 |
+ |
} catch (Throwable t) { |
1222 |
+ |
threadUnexpectedException(t); |
1223 |
+ |
return new byte[0]; |
1224 |
+ |
} |
1225 |
+ |
} |
1226 |
+ |
|
1227 |
+ |
@SuppressWarnings("unchecked") |
1228 |
+ |
<T> T serialClone(T o) { |
1229 |
+ |
try { |
1230 |
|
ObjectInputStream ois = new ObjectInputStream |
1231 |
< |
(new ByteArrayInputStream(bos.toByteArray())); |
1231 |
> |
(new ByteArrayInputStream(serialBytes(o))); |
1232 |
|
T clone = (T) ois.readObject(); |
1233 |
|
assertSame(o.getClass(), clone.getClass()); |
1234 |
|
return clone; |