Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public int newTask(Task task) {
@Query
@Description("Lists all tasks")
public List<Task> listAll() { //TODO[#2]: Implement the listAll() method to list all tasks.
return taskBaseDAO.getAllTasks();
throw new UnsupportedOperationException("Not implemented yet");
}

@Query
Expand Down
88 changes: 2 additions & 86 deletions src/test/java/br/com/pedr0limpio/resources/TaskResourceTest.java
Original file line number Diff line number Diff line change
@@ -1,88 +1,4 @@
package br.com.pedr0limpio.resources;

import br.com.pedr0limpio.enums.Priority;
import br.com.pedr0limpio.enums.Tag;
import br.com.pedr0limpio.models.Task;
import br.com.pedr0limpio.services.TaskBaseDAO;
import io.quarkus.test.junit.QuarkusTest;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

import java.util.Arrays;
import java.util.Date;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.*;

@QuarkusTest
public class TaskResourceTest {

@Mock
private TaskBaseDAO taskBaseDAO;

@InjectMocks
private TaskResource taskResource;

@BeforeEach
public void setUp() {
MockitoAnnotations.openMocks(this);
when(taskBaseDAO.writeTask(any(Task.class))).thenReturn(1);
when(taskBaseDAO.getById(1)).thenReturn(new Task());
}

@Test
public void testNewTask() {
Task newTask = new Task();
newTask.setDescription("create a new task");
newTask.setPriority(Priority.Medium);
newTask.setTagList(Arrays.asList(Tag.Work, Tag.Fun));
newTask.setCreation(new Date());
newTask.setConclusion(null);
when(taskBaseDAO.writeTask(any(Task.class))).thenReturn(1);
taskResource.newTask(newTask);
verify(taskBaseDAO).writeTask(any(Task.class));
}

@Test
public void testGetById() {
Task mockTask = new Task();
mockTask.setDescription("create a new task");
mockTask.setPriority(Priority.Medium);
mockTask.setTagList(Arrays.asList(Tag.Work, Tag.Fun));
mockTask.setCreation(new Date());
mockTask.setConclusion(null);
when(taskBaseDAO.getById(1)).thenReturn(mockTask);
Task task = taskResource.searchById(1);
assertEquals("create a new task", task.getDescription());
assertEquals(Priority.Medium, task.getPriority());
assertEquals(Arrays.asList(Tag.Work, Tag.Fun), task.getTagList());
verify(taskBaseDAO).getById(1);
}

@Test
public void testGetById_NotFound() {
when(taskBaseDAO.getById(999)).thenReturn(null);
Task task = taskResource.searchById(999);
assertEquals(null, task);
verify(taskBaseDAO).getById(999);
}

@Test
public void testGetById_DaoThrowsException() {
when(taskBaseDAO.getById(2)).thenThrow(new RuntimeException("DB error"));
try {
taskResource.searchById(2);
} catch (RuntimeException e) {
assertEquals("Error fetching task by id", e.getMessage());
verify(taskBaseDAO).getById(2);
return;
}
throw new AssertionError("Expected RuntimeException was not thrown");
}
}

//TODO[#6]: Make all the missing tests. Try starting here using TDD technique.
//TODO[#7]: Check whether it will be necessary to create tests for the service classes, if so, create the class(es)
//TODO[#6]: Make all the missing tests. Try starting here using TDD technique.
//TODO[#7]: Check whether it will be necessary to create tests for the service classes, if so, create the class(es)