@@ -27,11 +27,6 @@ public class ReflectionTest extends TestCase {
2727 public static class Person extends ReflectionDBObject {
2828
2929 public Person (){
30-
31- }
32-
33- Person ( String name ){
34- _name = name ;
3530 }
3631
3732 public String getName (){
@@ -55,16 +50,17 @@ public ReflectionTest()
5550 @ Test
5651 public void test1 ()
5752 throws MongoException {
58- DBCollection c = _db .getCollection ( "persen .test1" );
53+ DBCollection c = _db .getCollection ( "person .test1" );
5954 c .drop ();
6055 c .setObjectClass ( Person .class );
6156
62- Person p = new Person ( "eliot" );
57+ Person p = new Person ();
58+ p .setName ( "eliot" );
6359 c .save ( p );
6460
6561 DBObject out = c .findOne ();
6662 assertEquals ( "eliot" , out .get ( "Name" ) );
67- assertTrue ( out instanceof Person , "didn't come out as Person" );
63+ assertEquals ( Person . class , out . getClass () );
6864 }
6965
7066 public static class Outer extends ReflectionDBObject {
@@ -105,12 +101,54 @@ public void test2()
105101
106102 DBObject out = c .findOne ();
107103 assertEquals ( "eliot" , out .get ( "Name" ) );
108- assertTrue ( out instanceof Outer , "didn't come out as Person" );
104+ assertEquals ( Outer . class , out . getClass ());
109105 o = (Outer )out ;
110106 assertEquals ( "eliot" , o .getName () );
111107 assertEquals ( 17 , o .getInner ().getNumber () );
112108 }
113109
110+ static class Process extends ReflectionDBObject {
111+
112+ public Process () {}
113+
114+ public String getName () {
115+ return name ;
116+ }
117+
118+ public void setName (String name ) {
119+ this .name = name ;
120+ }
121+
122+ public int getStatus () {
123+ return status ;
124+ }
125+
126+ public void setStatus (int status ) {
127+ this .status = status ;
128+ }
129+
130+ String name ;
131+ int status ;
132+ }
133+
134+ @ Test
135+ public void testFindAndModify () {
136+ DBCollection c = _db .getCollection ( "findAndModify" );
137+ c .drop ();
138+ c .setObjectClass ( Process .class );
139+
140+ Process p = new Process ();
141+ p .setName ("test" );
142+ p .setStatus (0 );
143+ c .save (p , WriteConcern .SAFE );
144+
145+ DBObject obj = c .findAndModify (new BasicDBObject (), new BasicDBObject ("$set" , new BasicDBObject ("status" , 1 )));
146+ assertEquals (Process .class , obj .getClass ());
147+ Process pModified = (Process ) obj ;
148+ assertEquals (0 , pModified .getStatus ());
149+ assertEquals ("test" , pModified .getName ());
150+ }
151+
114152 final DB _db ;
115153
116154 public static void main ( String args [] )
0 commit comments