@Test
  @ExpectedDatabase("toDoData.xml")
  public void addTodoWhenTitleAndDescriptionAreTooLong() throws Exception {
    String title = TodoTestUtil.createStringWithLength(Todo.MAX_LENGTH_TITLE + 1);
    String description = TodoTestUtil.createStringWithLength(Todo.MAX_LENGTH_DESCRIPTION + 1);
    TodoDTO added = TodoTestUtil.createDTO(null, description, title);

    mockMvc
        .perform(
            post("/api/todo")
                .contentType(IntegrationTestUtil.APPLICATION_JSON_UTF8)
                .body(IntegrationTestUtil.convertObjectToJsonBytes(added)))
        .andExpect(status().isBadRequest())
        .andExpect(content().mimeType(IntegrationTestUtil.APPLICATION_JSON_UTF8))
        .andExpect(content().string(startsWith("{\"fieldErrors\":[")))
        .andExpect(
            content()
                .string(
                    allOf(
                        containsString(
                            "{\"path\":\"description\",\"message\":\"The maximum length of the description is 500 characters.\"}"),
                        containsString(
                            "{\"path\":\"title\",\"message\":\"The maximum length of the title is 100 characters.\"}"))))
        .andExpect(content().string(endsWith("]}")));
  }
  @Test
  @ExpectedDatabase("toDoData.xml")
  public void updateTodoWhenTodoIsNotFound() throws Exception {
    TodoDTO updated = TodoTestUtil.createDTO(3L, "description", "title");

    mockMvc
        .perform(
            put("/api/todo/{id}", 3L)
                .contentType(IntegrationTestUtil.APPLICATION_JSON_UTF8)
                .body(IntegrationTestUtil.convertObjectToJsonBytes(updated)))
        .andExpect(status().isNotFound());
  }
 @Test
 @ExpectedDatabase("toDoData.xml")
 public void addEmptyTodo() throws Exception {
   TodoDTO added = TodoTestUtil.createDTO(null, "", "");
   mockMvc
       .perform(
           post("/api/todo")
               .contentType(IntegrationTestUtil.APPLICATION_JSON_UTF8)
               .body(IntegrationTestUtil.convertObjectToJsonBytes(added)))
       .andExpect(status().isBadRequest())
       .andExpect(content().mimeType(IntegrationTestUtil.APPLICATION_JSON_UTF8))
       .andExpect(
           content()
               .string(
                   "{\"fieldErrors\":[{\"path\":\"title\",\"message\":\"The title cannot be empty.\"}]}"));
 }
 @Test
 @ExpectedDatabase(
     value = "toDoData-add-expected.xml",
     assertionMode = DatabaseAssertionMode.NON_STRICT)
 public void add() throws Exception {
   TodoDTO added = TodoTestUtil.createDTO(null, "description", "title");
   mockMvc
       .perform(
           post("/api/todo")
               .contentType(IntegrationTestUtil.APPLICATION_JSON_UTF8)
               .body(IntegrationTestUtil.convertObjectToJsonBytes(added)))
       .andExpect(status().isOk())
       .andExpect(content().mimeType(IntegrationTestUtil.APPLICATION_JSON_UTF8))
       .andExpect(
           content().string("{\"id\":3,\"description\":\"description\",\"title\":\"title\"}"));
 }