Date dt = new Date( 2009 , 01 , 23 , 10 , 53 , 42 );
BSONObject o = new BasicBSONObject( "date" , dt );
BSONDecoder d = new BasicBSONDecoder();
BSONEncoder e = new BasicBSONEncoder();
BSONCallback cb = new BasicBSONCallback();
OutputBuffer buf = new BasicOutputBuffer();
e.set( buf );
e.putObject( o );
e.done();
d.decode( new ByteArrayInputStream( buf.toByteArray() ), cb );
Object result = cb.get();
assertTrue( result instanceof BSONObject );
BSONObject bson = (BSONObject) result;
assertNotNull( bson.get( "date" ) );
assertTrue( bson.get( "date" ) instanceof java.util.Date );
BSON.addDecodingHook( Date.class, tf );
d.decode( new ByteArrayInputStream( buf.toByteArray() ), cb );
bson = (BSONObject) cb.get();
assertNotNull( bson.get( "date" ) );
assertTrue( bson.get( "date" ) instanceof TestDate );
assertEquals( bson.get( "date" ), td );