content: package com.codesoom.demo.application;
  
  import com.codesoom.demo.TaskNotFoundException;
  import com.codesoom.demo.models.Task;
  import org.junit.jupiter.api.BeforeEach;
  import org.junit.jupiter.api.Test;
  
  import java.util.List;
  
  import static org.assertj.core.api.Assertions.assertThat;
  import static org.assertj.core.api.Assertions.assertThatThrownBy;
  
  class TaskServiceTest {
      // 1. list -> getTasks
      // 2. detail -> getTask (with ID)
      // 3. create -> createTask (with source)
      // 4. update -> updateTask (with ID, source)
      // 5. delete -> deleteTask (with ID)
  
      private static final String TASK_TITLE = "test";
      private static final String UPDATE_POSTFIX = "!!!";
  
      private TaskService taskService;
  
      @BeforeEach
      void setUp() {
          // subject
  
          taskService = new TaskService();
  
          // fixtures
  
          Task task = new Task();
          task.setTitle(TASK_TITLE);
  
          taskService.createTask(task);
      }
  
      @Test
      void getTasks() {
          List<Task> tasks = taskService.getTasks();
  
          assertThat(tasks).hasSize(1);
  
          Task task = tasks.get(0);
          assertThat(task.getTitle()).isEqualTo(TASK_TITLE);
      }
  
      @Test
      void getTaskWithValidId() {
          Task task = taskService.getTask(1L);
          assertThat(task.getTitle()).isEqualTo(TASK_TITLE);
      }
  
      @Test
      void getTaskWithInvalidId() {
          assertThatThrownBy(() -> taskService.getTask(100L))
                  .isInstanceOf(TaskNotFoundException.class);
      }
  
      @Test
      void createTask() {
          int oldSize = taskService.getTasks().size();
  
          Task task = new Task();
          task.setTitle(TASK_TITLE);
  
          taskService.createTask(task);
  
          int newSize = taskService.getTasks().size();
  
          assertThat(newSize - oldSize).isEqualTo(1);
      }
  
      @Test
      void updateTask() {
          Task source = new Task();
          source.setTitle(TASK_TITLE + UPDATE_POSTFIX);
          taskService.updateTask(1L, source);
  
          Task task = taskService.getTask(1L);
          assertThat(task.getTitle()).isEqualTo(TASK_TITLE + UPDATE_POSTFIX);
      }
  
      @Test
      void deleteTask() {
          int oldSize = taskService.getTasks().size();
  
          taskService.deleteTask(1L);
  
          int newSize = taskService.getTasks().size();
  
          assertThat(oldSize - newSize).isEqualTo(1);
      }
  }
  