Skip to content
Snippets Groups Projects
Commit 7ac6edc5 authored by santerhs's avatar santerhs
Browse files

add tests for project

parent cdc66971
Branches create-project
No related tags found
No related merge requests found
......@@ -11,6 +11,12 @@ public class Project {
name = _name;
}
public Project(int _id, String _name, Team _team) {
id = _id;
name = _name;
team = _team;
}
public Project(){}
public int getId() {
......@@ -36,4 +42,10 @@ public class Project {
public void setTeam(Team team) {
this.team = team;
}
public boolean validate() throws Exception {
if (this.getName() == null || this.getName().equals("")) throw new Exception("Name must be defined for new project");
if (this.getTeam() == null || this.getTeam().getId() == 0) throw new Exception("Team must be defined for new project");
return true;
}
}
package Model;
import org.junit.jupiter.api.Test;
import java.util.Date;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class ProjectTest {
private Team team = new Team(1, "Markman and the boys");
private Project fullProject = new Project(1, "SuperBugTracker", team);
private Project noTeamProject = new Project(1, "SuperBugTracker", null);
private Project noNameProject = new Project(1, null, team);
@Test
public void validateWorkingProject() {
try {
assertTrue (fullProject.validate());
} catch (Exception e) {
e.printStackTrace();
}
}
@Test
public void validateProjectWithMissingTeam() {
Exception exception = assertThrows(Exception.class, () -> {
noTeamProject.validate();
});
String expectedMessage = "Team must be defined for new project";
String actualMessage = exception.getMessage();
assertTrue(actualMessage.contains(expectedMessage));
}
@Test
public void validateProjectWithMissingName() {
Exception exception = assertThrows(Exception.class, () -> {
noNameProject.validate();
});
String expectedMessage = "Name must be defined for new project";
String actualMessage = exception.getMessage();
assertTrue(actualMessage.contains(expectedMessage));
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment