8 |
|
|
9 |
|
import junit.framework.*; |
10 |
|
import java.util.concurrent.*; |
11 |
+ |
import java.io.*; |
12 |
|
|
13 |
|
public class TimeUnitTest extends TestCase { |
14 |
|
static public boolean DEBUG = false; |
242 |
|
fail("Unexpected exception"); |
243 |
|
} |
244 |
|
} |
245 |
+ |
|
246 |
+ |
public void testSerialization() { |
247 |
+ |
TimeUnit q = TimeUnit.MILLISECONDS; |
248 |
+ |
|
249 |
+ |
try { |
250 |
+ |
ByteArrayOutputStream bout = new ByteArrayOutputStream(10000); |
251 |
+ |
ObjectOutputStream out = new ObjectOutputStream(new BufferedOutputStream(bout)); |
252 |
+ |
out.writeObject(q); |
253 |
+ |
out.close(); |
254 |
+ |
|
255 |
+ |
ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); |
256 |
+ |
ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(bin)); |
257 |
+ |
TimeUnit r = (TimeUnit)in.readObject(); |
258 |
+ |
|
259 |
+ |
assertEquals(q.toString(), r.toString()); |
260 |
+ |
} catch(Exception e){ |
261 |
+ |
e.printStackTrace(); |
262 |
+ |
fail("unexpected exception"); |
263 |
+ |
} |
264 |
+ |
} |
265 |
+ |
|
266 |
|
} |