title: Unit test for Spring DTO that has a Collection for a Field in Hibernate/Spring Boot
body: <p>I'm using Hibernate and the JPA with Spring Boot. </p>
  
  <p>I have a DTO which would collect information from a Contact, which, is envisioned to come from a form from the client side which would could potentially have multiple phones sent:</p>
  
  <pre><code>public class ContactDTO {
  
     private BigInteger userId;
     private String contactName;
     private Map&lt;String, BigInteger&gt; phones;
  
     // getters and setters
  }
  </code></pre>
  
  <p>I'm imagining the data will be sent in a JSON object in this format:</p>
  
  <p><code>{phones:[{"mobile":"2325552932"}, {"landline":"2235553329"}, ...]</code></p>
  
  <p>And I have a controller with a POST method designed to handle that:</p>
  
  <pre><code>@PostMapping(path = "/newContact")
    public String createNewContact(@ModelAttribute ContactDTO newContact) {
      if (newContact.getPhones() !=null) {
        // method that persists phone data
      }
     // .. use a CRUDRepository object to persist the data to MySQL DB
      return "savedContact";
    }
  </code></pre>
  
  <p>I guess my questions are twofold: </p>
  
  <ol>
  <li>will my controller be able to automatically map the JSON object in that format?</li>
  <li>How would I test that?</li>
  </ol>
  
  <p>I'm using the Spring Boot test, and they look something like this :</p>
  
  <pre><code>@RunWith(SpringRunner.class)
  @SpringBootTest
  @AutoConfigureMockMvc
  public class AdditiveControllerShould {
  
    @Autowired
    private AdditiveController additiveController;
  
    @Autowired
    private MockMvc mockMvc;
  
   @Test
    public void saveAnEntryWhenPOSTOnlyUserIdAndContactName() throws Exception {
      mockMvc.perform(post("/newContact")
              .param("userId", "12345")
              .param("contactName", "John Smith"))
             // how to run test for the Map&lt;String, BigInteger&gt; ???
              .andExpect(status().isOk())
              .andExpect(content().string(containsString("savedContact")));
    }
  }
  </code></pre>