package com.fasterxml.jackson.failing;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.fasterxml.jackson.databind.BaseMapTest;
import com.fasterxml.jackson.databind.ObjectMapper;

public class MapMerge1625Test extends BaseMapTest
{

    // for [databind#1625]: should be possible to prevent deep merge
    public void testMapMergeForcedShallow() throws Exception
    {
        ObjectMapper mapper = new ObjectMapper();
        // prevent merging of "untyped" values
        mapper.configOverride(Object.class)
            .setMergeable(Boolean.FALSE);
        Map<String,Object> variables = new HashMap<>();
        List<String> list = new ArrayList<>();
        list.add("a");
        variables.put("list", list);
        mapper.readerForUpdating(variables).readValue(aposToQuotes("{'list':['b']}"));
        // should overwrite, not append
        List<?> l = (List<?>) variables.get("list");
        if (l.size() != 1 || !"b".equals(list.get(0))) {
            fail("Should overwrite contents, end up with entry for 'b', got: "+l);
        }
    }
}

@@ -54,192 +54,51 @@
 til.
-ArrayList;%0Aimport java.util.HashMap;%0Aimport java.util.List;%0Aimport java.util.Map;%0A%0Aimport com.fasterxml.jackson.databind.BaseMapTest;%0Aimport com.fasterxml.jackson.databind.ObjectMapper
+*;%0A%0Aimport com.fasterxml.jackson.databind.*
 ;%0A%0Ap
@@ -152,241 +152,313 @@
 t%0A%7B%0A
-%0A
     
-// for %5Bdatabind#1625%5D: should be possible to prevent deep merge%0A    public void testMapMergeForcedShallow() throws Exception%0A    %7B%0A        ObjectMapper mapper = new ObjectMapper();%0A        // prevent merging of %22untyped%22 values
+final ObjectMapper MAPPER = newObjectMapper();%0A%0A    public void testDefaultDeepMapMerge() throws Exception%0A    %7B%0A        // First: deep merge should be enabled by default%0A%0A        /*%0A//        mapper.configOverride(Map.class)%0A        mapper.configOverride(List.class)%0A            .setMergeable(false);
 %0A   
@@ -498,36 +498,32 @@
 .class)%0A        
-    
 .setMergeable(Bo
@@ -524,32 +524,40 @@
 ble(
-Boolean.FALSE);%0A        
+false);%0A        */%0A%0A        Hash
 Map%3C
@@ -571,25 +571,21 @@
 Object%3E 
-variables
+input
  = new H
@@ -608,27 +608,25 @@
     
-List%3CString%3E 
+input.put(%22
 list
- =
+%22,
  new
@@ -642,42 +642,39 @@
 t%3C%3E(
-);%0A        list.add
+Arrays.asList
 (%22a%22)
+))
 ;%0A
+%0A
         
 vari
@@ -673,80 +673,77 @@
     
-variables.put(%22list%22, list);%0A        mapper.readerForUpdating(variables)
+Map%3C?,?%3E resultMap = MAPPER.readerForUpdating(input)%0A                
 .rea
@@ -786,47 +786,8 @@
 ));%0A
-        // should overwrite, not append
 %0A   
@@ -799,17 +799,26 @@
 List%3C?%3E 
-l
+resultList
  = (List
@@ -826,17 +826,17 @@
 ?%3E) 
-variables
+resultMap
 .get
@@ -849,156 +849,621 @@
 %22);%0A
- 
+%0A
        
-if (l.size() != 1 %7C%7C !%22b%22.equals(list.get(0))) %7B%0A            fail(%22Should overwrite contents, end up with entry for 'b', got: %22+l
+ assertEquals(Arrays.asList(%22a%22, %22b%22), resultList);%0A    %7D%0A%0A    public void testGloballyDisabledDeepMapMerge() throws Exception%0A    %7B%0A        ObjectMapper mapper = newObjectMapper();%0A        // disable merging, globally; does not affect main level%0A        mapper.setDefaultMergeable(false);%0A%0A        HashMap%3CString,Object%3E input = new HashMap%3C%3E();%0A        input.put(%22list%22, new ArrayList%3C%3E(Arrays.asList(%22a%22)));%0A%0A        Map%3C?,?%3E resultMap = mapper.readerForUpdating(input)%0A                .readValue(aposToQuotes(%22%7B'list':%5B'b'%5D%7D%22));%0A%0A        List%3C?%3E resultList = (List%3C?%3E) resultMap.get(%22list%22
 );%0A
+%0A
         
 %7D%0A  
@@ -1458,17 +1458,61 @@
         
-%7D
+assertEquals(Arrays.asList(%22b%22), resultList);
 %0A    %7D%0A%7D

add a failing test to work on #1625