Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Teste unitários da aplicação #29

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
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));

}

}