@@ -914,10 +914,10 @@ public void testUpdate5(){
914914 c .drop ();
915915
916916 c .insert ( new BasicDBObject ( "x" , 5 ) );
917- assertEquals ( Integer .class , c .findOne ().get ("x" ).getClass () );
918- assertEquals (5 , c .findOne ().get ("x" ) );
917+ assertEquals (Integer .class , c .findOne ().get ("x" ).getClass ());
918+ assertEquals (5 , c .findOne ().get ("x" ));
919919
920- c .update ( new BasicDBObject () , new BasicDBObject ( "$set" , new BasicDBObject ( "x" , 5.6D ) ) );
920+ c .update (new BasicDBObject (), new BasicDBObject ("$set" , new BasicDBObject ("x" , 5.6D )) );
921921 assertEquals ( Double .class , c .findOne ().get ("x" ).getClass () );
922922 assertEquals ( 5.6 , c .findOne ().get ("x" ) );
923923
@@ -931,8 +931,8 @@ public void testIn(){
931931
932932 c .insert ( new BasicDBObject ( "x" , 1 ) );
933933 c .insert ( new BasicDBObject ( "x" , 2 ) );
934- c .insert ( new BasicDBObject ( "x" , 3 ) );
935- c .insert ( new BasicDBObject ( "x" , 4 ) );
934+ c .insert (new BasicDBObject ("x" , 3 ) );
935+ c .insert (new BasicDBObject ("x" , 4 ) );
936936
937937 List <DBObject > a = c .find ( new BasicDBObject ( "x" , new BasicDBObject ( "$in" , new Integer []{ 2 , 3 } ) ) ).toArray ();
938938 assertEquals ( 2 , a .size () );
@@ -950,7 +950,7 @@ public void testWriteResultWithGetLastErrorWithDifferentConcerns(){
950950
951951 CommandResult cr = res .getLastError ( WriteConcern .FSYNC_SAFE );
952952 assertEquals ( 1 , cr .getInt ( "n" ) );
953- assertTrue ( cr .containsField ( "fsyncFiles" ) || cr .containsField ( "waited" ));
953+ assertTrue (cr .containsField ("fsyncFiles" ) || cr .containsField ("waited" ));
954954
955955 CommandResult cr2 = res .getLastError ( WriteConcern .FSYNC_SAFE );
956956 assertTrue ( cr == cr2 );
@@ -984,11 +984,11 @@ public void testWriteResultMethodLevelWriteConcern(){
984984 c .insert ( new BasicDBObject ( "_id" , 1 ) );
985985 WriteResult res = c .update ( new BasicDBObject ( "_id" , 1 ) , new BasicDBObject ( "$inc" , new BasicDBObject ( "x" , 1 ) ) );
986986 assertEquals ( 1 , res .getN () );
987- assertTrue ( res .isLazy () );
987+ assertTrue (res .isLazy ());
988988
989989 res = c .update ( new BasicDBObject ( "_id" , 1 ) , new BasicDBObject ( "$inc" , new BasicDBObject ( "x" , 1 ) ) , false , false , WriteConcern .SAFE );
990990 assertEquals ( 1 , res .getN () );
991- assertFalse ( res .isLazy () );
991+ assertFalse (res .isLazy ());
992992 }
993993
994994 @ Test
@@ -1101,33 +1101,50 @@ public void testBadKey(){
11011101
11021102 try {
11031103 c .insert (new BasicDBObject ("a.b" , 1 ));
1104- assertTrue (false , "Bad key was accepted" );
1105- } catch (Exception e ) {}
1104+ fail ("Bad key was accepted" );
1105+ } catch (IllegalArgumentException e ) {}
1106+
11061107 try {
11071108 Map <String , Integer > data = new HashMap <String , Integer >();
11081109 data .put ("a.b" , 1 );
11091110 c .insert (new BasicDBObject ("data" , data ));
1110- assertTrue (false , "Bad key was accepted" );
1111- } catch (Exception e ) {}
1111+ fail ("Bad key was accepted" );
1112+ } catch (IllegalArgumentException e ) {}
1113+
11121114 try {
11131115 c .insert (new BasicDBObject ("$a" , 1 ));
1114- assertTrue ( false , "Bad key was accepted" );
1115- } catch (Exception e ) {}
1116+ fail ( "Bad key was accepted" );
1117+ } catch (IllegalArgumentException e ) {}
11161118
11171119 try {
11181120 c .save (new BasicDBObject ("a.b" , 1 ));
1119- assertTrue (false , "Bad key was accepted" );
1120- } catch (Exception e ) {}
1121+ fail ("Bad key was accepted" );
1122+ } catch (IllegalArgumentException e ) {}
1123+
11211124 try {
11221125 c .save (new BasicDBObject ("$a" , 1 ));
1123- assertTrue (false , "Bad key was accepted" );
1124- } catch (Exception e ) {}
1126+ fail ("Bad key was accepted" );
1127+ } catch (IllegalArgumentException e ) {}
1128+
1129+ try {
1130+ final BasicDBList list = new BasicDBList ();
1131+ list .add (new BasicDBObject ("$a" , 1 ));
1132+ c .save (new BasicDBObject ("a" , list ));
1133+ fail ("Bad key was accepted" );
1134+ } catch (IllegalArgumentException e ) {}
1135+
1136+ // try {
1137+ // c.save(new BasicDBObject("a", Arrays.asList(new BasicDBObject("$a", 1))));
1138+ // fail("Bad key was accepted");
1139+ // } catch (IllegalArgumentException e) {}
11251140
11261141 c .insert (new BasicDBObject ("a" , 1 ));
11271142 try {
11281143 c .update (new BasicDBObject ("a" , 1 ), new BasicDBObject ("a.b" , 1 ));
1129- assertTrue (false , "Bad key was accepted" );
1130- } catch (Exception e ) {}
1144+ fail ("Bad key was accepted" );
1145+ } catch (IllegalArgumentException e ) {}
1146+
1147+ // this should work because it's a query
11311148 c .update (new BasicDBObject ("a" , 1 ), new BasicDBObject ("$set" , new BasicDBObject ("a.b" , 1 )));
11321149 }
11331150
0 commit comments