1 package dst.ass1.jpa.tests;
3 import static org.hamcrest.core.IsCollectionContaining.hasItems;
4 import static org.junit.Assert.assertNotNull;
5 import static org.junit.Assert.assertThat;
6 import static org.junit.Assert.assertTrue;
8 import java.util.Collection;
10 import java.util.GregorianCalendar;
12 import org.junit.Before;
13 import org.junit.Test;
15 import dst.ass1.jpa.dao.ICourseDAO;
16 import dst.ass1.jpa.model.ICourse;
18 public class Ass1_2_3b_01Test extends Ass1_TestBase {
20 private ICourseDAO dao;
23 public void setUp() throws Exception {
24 dao = daoFactory.createCourseDAO();
28 public void testFindNonCancelledCoursesBetweenStartAndFinish() {
29 Collection<ICourse> courses = dao.findNonCancelledCoursesBetweenStartAndEnd(null, null);
31 assertThat(map(courses, e -> e.getId()), hasItems(
38 public void testFindEventsForStatusFinishedBetweenStartAndFinish2() {
39 Date start = createDate(2017, 1, 1, 1, 1);
40 Collection<ICourse> courses = dao.findNonCancelledCoursesBetweenStartAndEnd(start, null);
41 Collection<Long> courseIds = map(courses, ICourse::getId);
42 assertThat(courseIds, hasItems(testData.course1Id, testData.course2Id));
44 assertThat(map(courses, e -> e.getId()), hasItems(
51 public void testFindEventsForStatusFinishedBetweenStartAndFinish3() {
52 Date start = dao.findById(testData.course1Id).getStart();
53 Collection<ICourse> courses = dao.findNonCancelledCoursesBetweenStartAndEnd(start, null);
55 assertThat(map(courses, e -> e.getId()), hasItems(
61 public void testFindEventsForStatusFinishedBetweenStartAndFinish4() {
62 Date end = dao.findById(testData.course2Id).getEnd();
63 Collection<ICourse> courses = dao.findNonCancelledCoursesBetweenStartAndEnd(null, end);
65 assertThat(map(courses, e -> e.getId()), hasItems(
71 public void testFindEventsForStatusFinishedBetweenStartAndFinish5() {
72 Date start = dao.findById(testData.course1Id).getEnd();
73 Date end = dao.findById(testData.course2Id).getEnd();
74 Collection<ICourse> courses = dao.findNonCancelledCoursesBetweenStartAndEnd(start, end);
76 assertNotNull(courses);
77 assertTrue(courses.isEmpty());
80 private Date createDate(int year, int month, int day, int hours, int minutes) {
81 return new GregorianCalendar(year, month, day, hours, minutes).getTime();