package io.tasklist.api;

import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.tasklist.Swagger2SpringBoot;
import io.tasklist.model.Task;
import io.tasklist.repository.TaskRepository;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.boot.test.WebIntegrationTest;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.web.client.RestTemplate;

import java.io.IOException;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.notNullValue;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.IsEqual.equalTo;

@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(Swagger2SpringBoot.class)
@WebIntegrationTest
public class TasksApiControllerWebIntegrationTest {

    private static String URL = "http://localhost:8080/tasks";

    @Autowired
    TaskRepository taskRepository;

    @Test
    public void testTasksGet() throws IOException {
        RestTemplate restTemplate = new RestTemplate();
        ResponseEntity response = restTemplate.getForEntity(URL, String.class);

        assertThat(response.getStatusCode(), equalTo(HttpStatus.OK));

        ObjectMapper objectMapper = new ObjectMapper();
        JsonNode responseJson = objectMapper.readTree((String) response.getBody());

        assertThat(responseJson.isMissingNode(), is(false));
        assertThat(responseJson.toString(), equalTo("[]"));
    }

    @Test
    public void testTasksPost() {
        RestTemplate restTemplate = new RestTemplate();

        HttpEntity<Task> request = new HttpEntity<>(new Task(null, "task-name"));
        Task createdTask = restTemplate.postForObject(URL, request, Task.class);

        assertThat(createdTask, notNullValue());
        assertThat(createdTask.getId(), notNullValue());
        assertThat(createdTask.getName(), is("task-name"));
    }

    @Test
    public void testTasksIdDelete() {
        Task task = taskRepository.saveAndFlush(new Task());
        String entityUrl = URL + "/" + task.getId();
        RestTemplate restTemplate = new RestTemplate();

        restTemplate.delete(entityUrl);

        assertThat(taskRepository.count(), is(0L)); 
    }

}

@@ -235,16 +235,65 @@
 sitory;%0A
+import org.junit.After;%0Aimport org.junit.Before;%0A
 import o
@@ -817,16 +817,64 @@
 ception;
+%0Aimport java.util.Arrays;%0Aimport java.util.List;
 %0A%0Aimport
@@ -1362,65 +1362,797 @@
     
-@Test%0A    public void testTasksGet() throws IOException %7B
+private Task testTask;%0A    private int testTasksCount = 3;%0A%0A    @Before%0A    public void setup() %7B%0A        testTask = taskRepository.saveAndFlush(new Task(%22task1-id%22, %22task1-name%22));%0A        taskRepository.saveAndFlush(new Task());%0A        taskRepository.saveAndFlush(new Task());%0A    %7D%0A%0A    @After%0A    public void tearDown() %7B%0A        taskRepository.deleteAll();%0A    %7D%0A%0A    @Test%0A    public void testTasksGet() throws IOException %7B%0A        RestTemplate restTemplate = new RestTemplate();%0A        Task%5B%5D response = restTemplate.getForObject(URL, Task%5B%5D.class);%0A%0A        List%3CTask%3E allTasks = Arrays.asList(response);%0A%0A        assertThat(allTasks.size(), is(testTasksCount));%0A    %7D%0A%0A    @Test%0A    public void testTasksGet_statusCode() throws IOException %7B%0A        taskRepository.deleteAll();
 %0A   
@@ -3115,69 +3115,8 @@
 ) %7B%0A
-        Task task = taskRepository.saveAndFlush(new Task());%0A
     
@@ -3151,16 +3151,20 @@
  %22/%22 + t
+estT
 ask.getI
@@ -3285,16 +3285,22 @@
 ertThat(
+(int) 
 taskRepo
@@ -3322,14 +3322,29 @@
  is(
-0L
+testTasksCount - 1
 ));
- 
 %0A   

Refactor the test for the TasksController GET all endpoint.