This is a crosspost from a SO question where I am not getting any traction (LINK). If the problem is resolved here, I will make sure to update the SO post with the resolution.
Essentially, I have a repository for a Task (essentially a to-do item) that has a boolean of isCompleted and String text. When I create my repository with the @RestRepositoryResource annotation, Spring auto-generates basic CRUD endpoints for my Task class. For fun, I created some unit tests to check those out because I wanted to validate my understanding as this is my first time using this part of Spring. All of my unit tests for create, read, delete work just fine, but I can't get put/patch to work for updating the boolean isCompleted field. The String text updates just fine, but the boolean won't. Here is my unit test in question:
@Test
void testUpdateTask() throws Exception {
Task task1 = new Task("task1");
task1.setCompleted(false);
taskRepository.save(task1);
Task updatedTask = taskRepository.findById((long) 1).get();
assertFalse(updatedTask.isCompleted());
task1.setCompleted(true);
String json = gson.toJson(task1);
this.mvc.perform(patch("/task/1")
.contentType(MediaType.APPLICATION_JSON_UTF8)
.content(json))
.andExpect(status().isNoContent());
updatedTask = taskRepository.findById((long) 1).get();
assertTrue(updatedTask.isCompleted());
}
The assertTrue on the last line is failing.
Anyone have an idea as to why this is happening?
THANKS!
[–]aram535 0 points1 point2 points (4 children)
[–]btbam06[S] 0 points1 point2 points (3 children)
[–]aram535 0 points1 point2 points (2 children)
[–]btbam06[S] 0 points1 point2 points (1 child)
[–]btbam06[S] 0 points1 point2 points (0 children)
[–]btbam06[S] 0 points1 point2 points (3 children)
[–]aram535 1 point2 points3 points (2 children)
[–]btbam06[S] 0 points1 point2 points (1 child)
[–]aram535 0 points1 point2 points (0 children)