-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Partial implementation for #1556, still need to consider what to do w…
…ith arrays
- Loading branch information
1 parent
2efcf08
commit 8f8904a
Showing
5 changed files
with
169 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
src/test/java/com/fasterxml/jackson/databind/convert/UpdateValueTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
package com.fasterxml.jackson.databind.convert; | ||
|
||
import java.util.*; | ||
|
||
import com.fasterxml.jackson.databind.*; | ||
|
||
/** | ||
* Tests for {@link ObjectMapper#updateValue}. | ||
* | ||
* @since 2.9 | ||
*/ | ||
public class UpdateValueTest extends BaseMapTest | ||
{ | ||
/* | ||
/******************************************************** | ||
/* Test methods; simple containers | ||
/******************************************************** | ||
*/ | ||
|
||
private final ObjectMapper MAPPER = new ObjectMapper(); | ||
|
||
public void testMapUpdate() throws Exception | ||
{ | ||
Map<String,Object> base = new LinkedHashMap<>(); | ||
base.put("a", 345); | ||
Map<String,Object> overrides = new LinkedHashMap<>(); | ||
overrides.put("xyz", Boolean.TRUE); | ||
overrides.put("foo", "bar"); | ||
|
||
Map<String,Object> ob = MAPPER.updateValue(base, overrides); | ||
// first: should return first argument | ||
assertSame(base, ob); | ||
assertEquals(3, ob.size()); | ||
assertEquals(Integer.valueOf(345), ob.get("a")); | ||
assertEquals("bar", ob.get("foo")); | ||
assertEquals(Boolean.TRUE, ob.get("xyz")); | ||
} | ||
|
||
public void testListUpdate() throws Exception | ||
{ | ||
List<Object> base = new ArrayList<>(); | ||
base.add(123456); | ||
base.add(Boolean.FALSE); | ||
Object[] overrides = new Object[] { Boolean.TRUE, "zoink!" }; | ||
|
||
List<Object> ob = MAPPER.updateValue(base, overrides); | ||
// first: should return first argument | ||
assertSame(base, ob); | ||
assertEquals(4, ob.size()); | ||
assertEquals(Integer.valueOf(123456), ob.get(0)); | ||
assertEquals(Boolean.FALSE, ob.get(1)); | ||
assertEquals(overrides[0], ob.get(2)); | ||
assertEquals(overrides[1], ob.get(3)); | ||
} | ||
|
||
// What are expected array semantics? | ||
/* | ||
public void testArrayUpdate() throws Exception | ||
{ | ||
// Since Arrays are immutable, not sure what "right answer" ought to be | ||
Object[] base = new Object[] { Boolean.FALSE, Integer.valueOf(3) }; | ||
Object[] overrides = new Object[] { Boolean.TRUE, "zoink!" }; | ||
Object[] ob = MAPPER.updateValue(base, overrides); | ||
} | ||
*/ | ||
|
||
/* | ||
/******************************************************** | ||
/* Test methods; POJOs | ||
/******************************************************** | ||
*/ | ||
|
||
public void testPOJO() throws Exception | ||
{ | ||
Point base = new Point(42, 28); | ||
Map<String,Object> overrides = new LinkedHashMap<>(); | ||
overrides.put("y", 1234); | ||
Point result = MAPPER.updateValue(base, overrides); | ||
assertSame(base, result); | ||
assertEquals(42, result.x); | ||
assertEquals(1234, result.y); | ||
} | ||
|
||
/* | ||
/******************************************************** | ||
/* Test methods; other | ||
/******************************************************** | ||
*/ | ||
|
||
public void testMisc() throws Exception | ||
{ | ||
// if either is `null`, should return first arg | ||
assertNull(MAPPER.updateValue(null, "foo")); | ||
List<String> input = new ArrayList<>(); | ||
assertSame(input, MAPPER.updateValue(input, null)); | ||
} | ||
|
||
} |