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

Update application.properties - IP #25

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
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
2 changes: 1 addition & 1 deletion src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ spring.datasource.password=${DATABASE_PASSWD:password}
#drop n create table again, good for testing, comment this in production
spring.jpa.hibernate.ddl-auto=${DATABASE_UPDATE:create}
#spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults = false
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQL9Dialect
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQL9Dialect
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package br.ce.wcaquino.taskbackend.controller;
import static org.junit.Assert.assertEquals;

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 naoDeveSalvarTarefaSemDescricao() {
Task todo = new Task();
todo.setDueDate(LocalDate.now());
try {
controller.save(todo);
} catch (ValidationException e) {
Assert.assertEquals("Fill the task description", e.getMessage());
}
}

@Test
public void naoDeveSalvarTarefaSemData() {
Task todo = new Task();
todo.setTask("Descricao");
try {
controller.save(todo);
} catch (ValidationException e) {
Assert.assertEquals("Fill the due date", e.getMessage());
}

}

@Test
public void naoDeveSalvarTarefaComDataPassada() {
Task todo = new Task();
todo.setTask("Descricao");
todo.setDueDate(LocalDate.of(2022,10,01));
try {
controller.save(todo);
} catch (ValidationException e) {
Assert.assertEquals("Due date must not be in past", e.getMessage());
}

}

@Test
public void deveSalvarTarefaComSucesso() throws ValidationException {
Task todo = new Task();
todo.setTask("Descricao");
todo.setDueDate(LocalDate.now());
controller.save(todo);

Mockito.verify(taskRepo).save(todo);



}

}
26 changes: 26 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,26 @@
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 deveRetornarTrueParaDatasPassadas() {
LocalDate date = LocalDate.of(2022, 01, 01);
Assert.assertFalse(DateUtils.isEqualOrFutureDate(date));
}

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