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
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@
<scope>provided</scope>
</dependency>

<dependency>
<groupId>commons-httpclient</groupId>
<artifactId>commons-httpclient</artifactId>
<version>3.1</version>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
Expand Down Expand Up @@ -69,6 +74,7 @@
<version>0.8.3</version>
<executions>
<execution>
<id>jacoco-initialize</id>
<goals>
<goal>prepare-agent</goal>
</goals>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
package br.ce.wcaquino.taskbackend.controller;

import java.time.LocalDate;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;

import br.ce.wcaquino.taskbackend.model.Task;
import br.ce.wcaquino.taskbackend.repo.TaskRepo;
import br.ce.wcaquino.taskbackend.utils.ValidationException;

public class TaskControllerTest {

@Mock
private TaskRepo taskRepo;


@InjectMocks
private TaskController controller;

@Before
public void setup() {
MockitoAnnotations.initMocks(this);
}

@Test
public void naoDeveSalvarTarefasSemDescricao() {
Task todo = new Task();
//todo.setTask("Descricao");
todo.setDueDate(LocalDate.now());

try {
controller.save(todo);
} catch (ValidationException e) {
Assert.assertEquals("Fill the task description", e.getMessage());
}
}

@Test
public void naoDeveSalvarTarefasSemData() {
Task todo = new Task();
todo.setTask("Descricao");
//todo.setDueDate(LocalDate.now());

try {
controller.save(todo);
} catch (ValidationException e) {
Assert.assertEquals("Fill the due date", e.getMessage());
}

}

@Test
public void naoDeveSalvarTarefascomDataPassada() {
Task todo = new Task();
todo.setTask("Descricao");
todo.setDueDate(LocalDate.of(2010,01,01));

try {
controller.save(todo);
} catch (ValidationException e) {
Assert.assertEquals("Due date must not be in past", e.getMessage());
}

}
@Test
public void deveSalvarTarefasComSucesso() throws ValidationException {
Task todo = new Task();
todo.setTask("Descricao");
todo.setDueDate(LocalDate.now());
controller.save(todo);
Mockito.verify(taskRepo).save(todo);

}

}
32 changes: 32 additions & 0 deletions src/test/java/br/ce/wcaquino/taskbackend/utils/DateUtilsTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package br.ce.wcaquino.taskbackend.utils;

import java.time.LocalDate;

import org.junit.Assert;
import org.junit.Test;

public class DateUtilsTest {


@Test
public void deveRetornarTrueParaDatasFuturas() {
LocalDate date = LocalDate.of(2030, 01, 01);
Assert.assertTrue(DateUtils.isEqualOrFutureDate(date));

}

@Test
public void deveRetornarFalseParaDatasPassadas() {
LocalDate date = LocalDate.of(2010, 01, 01);
Assert.assertFalse(DateUtils.isEqualOrFutureDate(date));

}

@Test
public void deveRetornarTrueParaDatasAtual() {
LocalDate date = LocalDate.now();
Assert.assertTrue(DateUtils.isEqualOrFutureDate(date));

}

}