@@ -299,7 +299,7 @@ public void testRetain()
299
299
assertEquals ("c" , ob .get ("c" ).textValue ());
300
300
}
301
301
302
- public void testValidWith () throws Exception
302
+ public void testValidWithObject () throws Exception
303
303
{
304
304
ObjectNode root = MAPPER .createObjectNode ();
305
305
assertEquals ("{}" , MAPPER .writeValueAsString (root ));
@@ -317,27 +317,52 @@ public void testValidWithArray() throws Exception
317
317
assertEquals ("{\" arr\" :[]}" , MAPPER .writeValueAsString (root ));
318
318
}
319
319
320
- public void testInvalidWith () throws Exception
320
+ public void testInvalidWithObject () throws Exception
321
321
{
322
322
JsonNode root = MAPPER .createArrayNode ();
323
323
try { // should not work for non-ObjectNode nodes:
324
- root .with ( " prop" );
324
+ root .withObject ( "/ prop" );
325
325
fail ("Expected exception" );
326
326
} catch (UnsupportedOperationException e ) {
327
- verifyException (e , "not of type `ObjectNode`" );
327
+ verifyException (e , "Cannot replace context node (of type" );
328
+ verifyException (e , "ArrayNode" );
328
329
}
329
330
// also: should fail of we already have non-object property
330
331
ObjectNode root2 = MAPPER .createObjectNode ();
331
332
root2 .put ("prop" , 13 );
332
333
try { // should not work for non-ObjectNode nodes:
333
- root2 .with ( " prop" );
334
+ root2 .withObject ( "/ prop" );
334
335
fail ("Expected exception" );
335
336
} catch (UnsupportedOperationException e ) {
336
- verifyException (e , "has value that is not" );
337
+ verifyException (e , "Cannot replace `JsonNode` of type " );
338
+ verifyException (e , "IntNode" );
337
339
}
338
340
}
339
341
340
342
public void testInvalidWithArray () throws Exception
343
+ {
344
+ JsonNode root = MAPPER .createArrayNode ();
345
+ try { // should not work for non-ObjectNode nodes:
346
+ root .withArray ("/prop" );
347
+ fail ("Expected exception" );
348
+ } catch (UnsupportedOperationException e ) {
349
+ verifyException (e , "Cannot replace context node (of type" );
350
+ verifyException (e , "ArrayNode" );
351
+ }
352
+ // also: should fail of we already have non-Array property
353
+ ObjectNode root2 = MAPPER .createObjectNode ();
354
+ root2 .put ("prop" , 13 );
355
+ try { // should not work for non-ObjectNode nodes:
356
+ root2 .withArray ("/prop" );
357
+ fail ("Expected exception" );
358
+ } catch (UnsupportedOperationException e ) {
359
+ verifyException (e , "Cannot replace `JsonNode` of type " );
360
+ verifyException (e , "IntNode" );
361
+ }
362
+ }
363
+
364
+ // Test for pre-2.14 behavior for "simple property"
365
+ public void testInvalidWithArrayLegacy () throws Exception
341
366
{
342
367
JsonNode root = MAPPER .createArrayNode ();
343
368
try { // should not work for non-ObjectNode nodes:
@@ -356,7 +381,7 @@ public void testInvalidWithArray() throws Exception
356
381
verifyException (e , "has value that is not" );
357
382
}
358
383
}
359
-
384
+
360
385
public void testSetAll () throws Exception
361
386
{
362
387
ObjectNode root = MAPPER .createObjectNode ();
0 commit comments