Refactored the test code, instance variables should be local variables if possible, unused code are removed etc..
This commit is contained in:
parent
856ae14693
commit
9ebe83fdd0
@ -51,27 +51,25 @@ public class TestActivityPlanDaoJPA {
|
||||
|
||||
private User user;
|
||||
private Project project;
|
||||
private ProjectClass projectClass;
|
||||
private Role role;
|
||||
private ProjectSchedule projectSchedule;
|
||||
private ProjectSchedule projectSchedule;
|
||||
|
||||
@Before
|
||||
public void startTransaction()
|
||||
{
|
||||
user = new User();
|
||||
user = userDao.save(user);
|
||||
|
||||
role = new Student();
|
||||
|
||||
Role role = new Student();
|
||||
role.setUser(user);
|
||||
role = roleDao.save(role);
|
||||
|
||||
projectClass = new ProjectClass(ProjectClass.BACHELOR,"Bachelor","Bachelor degree thesis project");
|
||||
|
||||
ProjectClass projectClass = new ProjectClass(ProjectClass.BACHELOR, "Bachelor", "Bachelor degree thesis project");
|
||||
projectClass = projectClassDao.save(projectClass);
|
||||
|
||||
project = new Project();
|
||||
project.setTitle("SomeProject");
|
||||
project.setProjectClass(projectClass);
|
||||
project.addProjectParticipant((Student)role);
|
||||
project.addProjectParticipant((Student) role);
|
||||
project = projectDao.save(project);
|
||||
|
||||
projectSchedule = new ProjectSchedule();
|
||||
|
@ -56,15 +56,14 @@ public class TestBoardMessageDaoJPA {
|
||||
|
||||
@Autowired
|
||||
private ProjectDao projectDao;
|
||||
|
||||
private User user;
|
||||
private BoardMessage boardMessage;
|
||||
|
||||
private BoardMessage boardMessage;
|
||||
private MessageBoard messageBoard;
|
||||
|
||||
@Before
|
||||
public void startTransaction()
|
||||
{
|
||||
user = new User();
|
||||
User user = new User();
|
||||
user.setEmailAddress("test@dsv.su.se");
|
||||
user.setIdentifier(new Long(666));
|
||||
user.setFirstName("Test");
|
||||
|
@ -38,8 +38,6 @@ public class TestCheckListTemplateDao {
|
||||
|
||||
private CheckListTemplateDao target;
|
||||
|
||||
private User user1;
|
||||
|
||||
private User user2;
|
||||
|
||||
private CheckListTemplate template1;
|
||||
@ -50,22 +48,12 @@ public class TestCheckListTemplateDao {
|
||||
|
||||
private CheckListTemplate template3;
|
||||
|
||||
private ChecklistCategory category1;
|
||||
|
||||
private ChecklistCategory category2;
|
||||
|
||||
private ChecklistCategory category3;
|
||||
|
||||
private List<ChecklistCategory> allCategories;
|
||||
|
||||
private List<ChecklistCategory> categories3;
|
||||
|
||||
private List<ChecklistCategory> categories1;
|
||||
|
||||
@Before
|
||||
public void setup() throws Exception {
|
||||
target = checkListTemplateDao;
|
||||
user1 = new User();
|
||||
User user1 = new User();
|
||||
user1.setFirstName("User 1");
|
||||
user1 = userDao.save(user1);
|
||||
|
||||
@ -73,27 +61,24 @@ public class TestCheckListTemplateDao {
|
||||
user2.setFirstName("User 2");
|
||||
user2 = userDao.save(user2);
|
||||
|
||||
|
||||
category1 = new ChecklistCategory();
|
||||
|
||||
ChecklistCategory category1 = new ChecklistCategory();
|
||||
category1.setCategoryName("Category 1");
|
||||
category1 = categoryDao.save(category1);
|
||||
|
||||
category2 = new ChecklistCategory();
|
||||
|
||||
ChecklistCategory category2 = new ChecklistCategory();
|
||||
category2.setCategoryName("Category 2");
|
||||
category2 = categoryDao.save(category2);
|
||||
|
||||
category3 = new ChecklistCategory();
|
||||
ChecklistCategory category3 = new ChecklistCategory();
|
||||
category3.setCategoryName("Category 3");
|
||||
category3 = categoryDao.save(category3);
|
||||
|
||||
allCategories = new ArrayList<ChecklistCategory>();
|
||||
List<ChecklistCategory> allCategories = new ArrayList<ChecklistCategory>();
|
||||
allCategories.add(category1);
|
||||
allCategories.add(category2);
|
||||
allCategories.add(category3);
|
||||
|
||||
categories3 = new ArrayList<ChecklistCategory>();
|
||||
categories3.add(category3);
|
||||
|
||||
categories1 = new ArrayList<ChecklistCategory>();
|
||||
categories1.add(category1);
|
||||
|
||||
|
@ -52,48 +52,38 @@ public class TestCheckPlagiarismEventDaoJPA {
|
||||
|
||||
@Autowired
|
||||
private FileDescriptionDao fileDescriptionDao;
|
||||
|
||||
private Project presenterProject;
|
||||
private ProjectClass projectClass;
|
||||
|
||||
private User presenter;
|
||||
private Student presenterRole;
|
||||
|
||||
|
||||
private User presenterProjectSupervisor;
|
||||
private Employee presenterProjectSupervisorRole;
|
||||
|
||||
private FinalSeminar seminar;
|
||||
|
||||
private FileDescription fileDescription;
|
||||
private Student presenterRole;
|
||||
|
||||
private FileDescription fileDescription;
|
||||
|
||||
private CheckPlagiarismEvent checkPlagiarismEvent;
|
||||
|
||||
@Before
|
||||
public void startTransaction() {
|
||||
projectClass = new ProjectClass();
|
||||
ProjectClass projectClass = new ProjectClass();
|
||||
projectClass.setName("Master");
|
||||
projectClass.setCode(ProjectClass.MASTER);
|
||||
projectClass = projectClassDao.save(projectClass);
|
||||
|
||||
presenter = new User();
|
||||
|
||||
User presenter = new User();
|
||||
presenter.setFirstName("Presenter");
|
||||
presenter = userDao.save(presenter);
|
||||
|
||||
presenterProjectSupervisor = new User();
|
||||
|
||||
User presenterProjectSupervisor = new User();
|
||||
presenterProjectSupervisor.setFirstName("presenterProjectSupervisor");
|
||||
presenterProjectSupervisor = userDao.save(presenterProjectSupervisor);
|
||||
|
||||
presenterProjectSupervisorRole = roleDao.makeEmployee(presenterProjectSupervisor);
|
||||
|
||||
presenterProject = new Project();
|
||||
|
||||
Employee presenterProjectSupervisorRole = roleDao.makeEmployee(presenterProjectSupervisor);
|
||||
|
||||
Project presenterProject = new Project();
|
||||
presenterProject.setTitle("Presenter Project");
|
||||
presenterProject.setHeadSupervisor(presenterProjectSupervisorRole);
|
||||
presenterProject.setProjectClass(projectClass);
|
||||
presenterProject.addProjectParticipant(presenterRole);
|
||||
presenterProject = projectDao.save(presenterProject);
|
||||
|
||||
seminar = new FinalSeminar();
|
||||
|
||||
FinalSeminar seminar = new FinalSeminar();
|
||||
seminar.setStartDate(new Date());
|
||||
seminar.setEndDate(new Date());
|
||||
seminar.setProject(presenterProject);
|
||||
|
@ -52,12 +52,10 @@ public class TestCommentThreadDaoJPA {
|
||||
private UserDao userDao;
|
||||
|
||||
private Project project1;
|
||||
private Comment comment1, comment2, comment3;
|
||||
private SortedSet<Comment> comments = new TreeSet<Comment>();
|
||||
private SortedSet<Comment> comments = new TreeSet<Comment>();
|
||||
private CommentThread commentThread;
|
||||
private User user;
|
||||
|
||||
@Before
|
||||
|
||||
@Before
|
||||
public void startTransaction() {
|
||||
ProjectClass projectClass = new ProjectClass(ProjectClass.BACHELOR,"Bachelor","Bachelor degree thesis project");
|
||||
projectClass = projectClassDao.save(projectClass);
|
||||
@ -65,23 +63,23 @@ public class TestCommentThreadDaoJPA {
|
||||
project1.setProjectClass(projectClass);
|
||||
project1.setTitle("Project 1");
|
||||
project1 = projectDao.save(project1);
|
||||
|
||||
user = new User();
|
||||
|
||||
User user = new User();
|
||||
user.setFirstName("Pelle");
|
||||
user = userDao.save(user);
|
||||
|
||||
commentThread = new CommentThread(project1);
|
||||
commentThread = commentThreadDao.save(commentThread);
|
||||
|
||||
comment1 = new Comment(user,commentThread);
|
||||
|
||||
Comment comment1 = new Comment(user, commentThread);
|
||||
comment1 = commentDao.save(comment1);
|
||||
|
||||
|
||||
comment2 = new Comment(user,commentThread);
|
||||
|
||||
|
||||
Comment comment2 = new Comment(user, commentThread);
|
||||
comment2 = commentDao.save(comment2);
|
||||
|
||||
|
||||
comment3 = new Comment(user,commentThread);
|
||||
|
||||
|
||||
Comment comment3 = new Comment(user, commentThread);
|
||||
comment3 = commentDao.save(comment3);
|
||||
|
||||
comments.add(comment1);
|
||||
|
@ -41,46 +41,17 @@ public class TestEventTemplateDaoJPA {
|
||||
|
||||
private ProjectEventTemplate projectEventTemplate;
|
||||
private ProjectEventTemplate projectEventTemplateSysAdmin;
|
||||
|
||||
private User supervisorUser;
|
||||
private Employee supervisorRole;
|
||||
|
||||
private User sysAdminUser;
|
||||
private SysAdmin sysAdminRole;
|
||||
|
||||
private User employeeAndSysAdminUser;
|
||||
private SysAdmin employeeAndSysAdminUserSysAdminRole;
|
||||
private Employee employeeAndSysAdminUserEmpRole;
|
||||
|
||||
private ProjectEventTemplate pr1;
|
||||
|
||||
private ScheduleTemplate sysAdminTemplate;
|
||||
private ScheduleTemplate employeeTemplate;
|
||||
|
||||
@Before
|
||||
|
||||
private ProjectEventTemplate pr1;
|
||||
|
||||
@Before
|
||||
public void startTransaction() {
|
||||
supervisorUser = new User();
|
||||
User supervisorUser = new User();
|
||||
supervisorUser = userDao.save(supervisorUser);
|
||||
|
||||
supervisorRole = new Employee();
|
||||
supervisorRole.setUser(supervisorUser);
|
||||
supervisorRole = (Employee) roleDao.save(supervisorRole);
|
||||
|
||||
sysAdminUser = new User();
|
||||
User sysAdminUser = new User();
|
||||
sysAdminUser = userDao.save(sysAdminUser);
|
||||
|
||||
sysAdminRole = new SysAdmin();
|
||||
sysAdminRole.setUser(sysAdminUser);
|
||||
sysAdminRole = (SysAdmin) roleDao.save(sysAdminRole);
|
||||
|
||||
|
||||
sysAdminTemplate = new ScheduleTemplate();
|
||||
sysAdminTemplate.setCreator(sysAdminUser);
|
||||
sysAdminTemplate.setSysAdminTemplate(true);
|
||||
sysAdminTemplate.setTemplateName("Sysadmin template");
|
||||
sysAdminTemplate = scheduleTemplateDao.save(sysAdminTemplate);
|
||||
|
||||
employeeTemplate = new ScheduleTemplate();
|
||||
|
||||
ScheduleTemplate employeeTemplate = new ScheduleTemplate();
|
||||
employeeTemplate.setCreator(supervisorUser);
|
||||
employeeTemplate.setSysAdminTemplate(false);
|
||||
employeeTemplate.setTemplateName("Employee template");
|
||||
@ -99,15 +70,15 @@ public class TestEventTemplateDaoJPA {
|
||||
projectEventTemplateSysAdmin.setTemplateCreator(sysAdminUser);
|
||||
projectEventTemplateSysAdmin.setScheduleTemplate(employeeTemplate);
|
||||
projectEventTemplateSysAdmin = (ProjectEventTemplate) projectEventTemplateDao.save(projectEventTemplateSysAdmin);
|
||||
|
||||
employeeAndSysAdminUser = new User();
|
||||
|
||||
User employeeAndSysAdminUser = new User();
|
||||
employeeAndSysAdminUser = userDao.save(employeeAndSysAdminUser);
|
||||
|
||||
employeeAndSysAdminUserSysAdminRole = new SysAdmin();
|
||||
|
||||
SysAdmin employeeAndSysAdminUserSysAdminRole = new SysAdmin();
|
||||
employeeAndSysAdminUserSysAdminRole.setUser(employeeAndSysAdminUser);
|
||||
employeeAndSysAdminUserSysAdminRole = (SysAdmin) roleDao.save(employeeAndSysAdminUserSysAdminRole);
|
||||
|
||||
employeeAndSysAdminUserEmpRole = new Employee();
|
||||
|
||||
Employee employeeAndSysAdminUserEmpRole = new Employee();
|
||||
employeeAndSysAdminUserEmpRole.setUser(employeeAndSysAdminUser);
|
||||
employeeAndSysAdminUserEmpRole = (Employee) roleDao.save(employeeAndSysAdminUserEmpRole);
|
||||
|
||||
|
@ -40,8 +40,6 @@ public class TestAuthorDao {
|
||||
|
||||
private User student1;
|
||||
|
||||
private Student author1;
|
||||
|
||||
private User studentNoAuthor;
|
||||
|
||||
private ProjectClass bachelor;
|
||||
@ -54,15 +52,9 @@ public class TestAuthorDao {
|
||||
studentNoAuthor = new User();
|
||||
studentNoAuthor.setFirstName("Student No Author");
|
||||
studentNoAuthor = userDao.save(studentNoAuthor);
|
||||
|
||||
|
||||
|
||||
target = authorDao;
|
||||
|
||||
|
||||
author1 = new Student();
|
||||
author1.setUser(student1);
|
||||
author1 = authorDao.save(author1);
|
||||
|
||||
|
||||
bachelor = new ProjectClass(ProjectClass.BACHELOR, "Bachelor", "Bachelor degree");
|
||||
ProjectClassSettings projectClassSettings = bachelor.getProjectClassSettings();
|
||||
projectClassSettings.setMinAuthors(2);
|
||||
|
@ -61,9 +61,6 @@ public class TestSupervisorDao {
|
||||
@Autowired
|
||||
private ProjectClassDao projectClassDao;
|
||||
|
||||
@Autowired
|
||||
private ApplicationPeriodDao applicationPeriodDao;
|
||||
|
||||
@Autowired
|
||||
private LanguageDao languageDao;
|
||||
|
||||
@ -73,9 +70,6 @@ public class TestSupervisorDao {
|
||||
@Autowired
|
||||
private MatchDao matchDao;
|
||||
|
||||
@Autowired
|
||||
private AuthorDao authorDao;
|
||||
|
||||
@Autowired
|
||||
private ProjectIdeaDao projectIdeaDao;
|
||||
|
||||
|
@ -39,28 +39,22 @@ public class TestProjectIdea {
|
||||
|
||||
@Autowired
|
||||
private UserDao userDao;
|
||||
|
||||
@Autowired
|
||||
private ProjectScheduleDao projectScheduleDao;
|
||||
@Autowired
|
||||
private ProjectScheduleEventDao projectScheduleEventDao;
|
||||
|
||||
@Autowired
|
||||
private ProjectDao projectDao;
|
||||
|
||||
@Autowired
|
||||
private ProjectClassDao projectClassDao;
|
||||
@Autowired
|
||||
private ProjectScheduleFacade projectScheduleFacade;
|
||||
|
||||
@Autowired
|
||||
private RoleDao roleDao;
|
||||
|
||||
@Autowired
|
||||
private ProjectIdeaDao projectIdeaDao;
|
||||
|
||||
@Autowired
|
||||
private ApplicationPeriodDao applicationPeriodDao;
|
||||
|
||||
@Autowired
|
||||
private KeywordDao keywordDao;
|
||||
|
||||
@Autowired
|
||||
private KeywordTypeDao keywordTypeDao;
|
||||
|
||||
@ -103,9 +97,6 @@ public class TestProjectIdea {
|
||||
other = new KeywordType("other");
|
||||
other = keywordTypeDao.save(other);
|
||||
|
||||
KeywordType unit = new KeywordType("unit");
|
||||
unit = keywordTypeDao.save(unit);
|
||||
|
||||
target = new ProjectIdea();
|
||||
Set<ProjectClass> projectClassSet = new HashSet<ProjectClass>();
|
||||
projectClassSet.add(projectClass);
|
||||
@ -115,7 +106,6 @@ public class TestProjectIdea {
|
||||
target.setApplicationPeriod(applicationPeriod);
|
||||
key1 = new Keyword("key 1", standard);
|
||||
key2 = new Keyword("key 2", other);
|
||||
Keyword key3 = new Keyword("key 3", unit);
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user