@@ -56,11 +56,11 @@ public class ClientTest {
5656 @ SuppressWarnings ("unused" )
5757 private static class IRLObject {
5858 public String str ;
59- public boolean bTrue ;
59+ public boolean bool ;
6060
6161 public IRLObject () {
6262 this .str = "string" ;
63- this .bTrue = true ;
63+ this .bool = true ;
6464 }
6565 }
6666
@@ -161,7 +161,7 @@ public void noArgsConstructorReturnsClientToLocalMachine() {
161161 public void basicSetGetShouldSucceed () {
162162
163163 // naive set with a path
164- client .set ("null" , null , Path .ROOT_PATH );
164+ client .set ("null" , null , Path .ROOT_PATH );
165165 assertNull (client .get ("null" , String .class , Path .ROOT_PATH ));
166166
167167 // real scalar value and no path
@@ -229,10 +229,39 @@ public void getMultiplePathsShouldSucceed() {
229229 IRLObject obj = new IRLObject ();
230230 client .set ( "obj" , obj );
231231 Object expected = g .fromJson (g .toJson (obj ), Object .class );
232- assertTrue (expected .equals (client .get ( "obj" , Object .class , Path .of ("bTrue " ), Path .of ("str" ))));
232+ assertTrue (expected .equals (client .get ( "obj" , Object .class , Path .of ("bool " ), Path .of ("str" ))));
233233
234234 }
235235
236+ @ Test
237+ public void toggle () {
238+
239+ IRLObject obj = new IRLObject ();
240+ client .set ( "obj" , obj );
241+
242+ Path pbool = Path .of (".bool" );
243+ // check initial value
244+ assertTrue (client .get ("obj" , Boolean .class , pbool ));
245+
246+ // true -> false
247+ client .toggle ("obj" , pbool );
248+ assertFalse (client .get ("obj" , Boolean .class , pbool ));
249+
250+ // false -> true
251+ client .toggle ("obj" , pbool );
252+ assertTrue (client .get ("obj" , Boolean .class , pbool ));
253+
254+ // ignore non-boolean field
255+ Path pstr = Path .of (".str" );
256+ try {
257+ client .toggle ("obj" , pstr );
258+ fail ("Path not a bool" );
259+ } catch (JedisDataException jde ) {
260+ assertTrue (jde .getMessage ().contains ("not a bool" ));
261+ }
262+ assertEquals ("string" , client .get ("obj" , String .class , pstr ));
263+ }
264+
236265 @ Test (expected = JedisDataException .class )
237266 public void getException () {
238267 client .set ( "test" , "foo" , Path .ROOT_PATH );
0 commit comments