Skip to content

Commit 1d8f79a

Browse files
committed
Fixed a time-dependent test.
1 parent 3b83147 commit 1d8f79a

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

tmc-plugin/test/unit/src/fi/helsinki/cs/tmc/data/serialization/CourseListParserTest.java

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,20 @@
66
import fi.helsinki.cs.tmc.data.CourseListUtils;
77
import fi.helsinki.cs.tmc.data.Exercise;
88
import fi.helsinki.cs.tmc.data.ExerciseListUtils;
9+
import java.util.Date;
910
import java.util.GregorianCalendar;
1011
import java.util.List;
1112
import org.junit.Before;
1213

1314
public class CourseListParserTest {
14-
15+
1516
private CourseListParser parser;
16-
17+
1718
@Before
1819
public void setUp() {
1920
parser = new CourseListParser();
2021
}
21-
22+
2223
@Test
2324
public void itShouldParseJsonCourseLists() {
2425
String exercisesJson =
@@ -33,30 +34,33 @@ public void itShouldParseJsonCourseLists() {
3334
"checksum: \"123abc\"" +
3435
"}]";
3536
String json = "{api_version: 1, courses: [{\"name\": \"TheCourse\",\"exercises\": " + exercisesJson + "}]}";
36-
37+
3738
List<Course> result = parser.parseFromJson(json);
38-
39+
3940
Course course = CourseListUtils.getCourseByName(result, "TheCourse");
4041
assertEquals("TheCourse", course.getName());
41-
42+
4243
Exercise exercise = ExerciseListUtils.getExerciseByName(course.getExercises(), "TheExercise");
43-
44+
4445
assertEquals("TheCourse", exercise.getCourseName());
45-
46+
4647
GregorianCalendar cal = new GregorianCalendar();
4748
cal.setTime(exercise.getDeadline());
4849
assertEquals(2015, cal.get(GregorianCalendar.YEAR));
4950
assertEquals(1, cal.get(GregorianCalendar.HOUR_OF_DAY));
5051
assertEquals(30, cal.get(GregorianCalendar.MINUTE));
51-
52+
5253
assertEquals("http://example.com/courses/123/exercises/1.zip", exercise.getDownloadUrl());
5354
assertEquals("http://example.com/courses/123/exercises/1/submissions", exercise.getReturnUrl());
5455
assertTrue(exercise.isAttempted());
5556
assertFalse(exercise.isCompleted());
57+
58+
exercise.setDeadline(new Date(new Date().getTime() + 60 * 60 * 1000));
5659
assertTrue(exercise.isReturnable());
60+
5761
assertEquals("123abc", exercise.getChecksum());
5862
}
59-
63+
6064
@Test
6165
public void itShouldParseAnEmptyJsonArrayAsAnEmptyCourseList() {
6266
List<Course> empty = parser.parseFromJson("{api_version: 1, courses: []}");
@@ -67,12 +71,12 @@ public void itShouldParseAnEmptyJsonArrayAsAnEmptyCourseList() {
6771
public void itShouldThrowAnNullPointerExceptionIfTheInputIsEmpty() throws Exception {
6872
parser.parseFromJson(null);
6973
}
70-
74+
7175
@Test(expected = IllegalArgumentException.class)
7276
public void itShouldThrowAnIllegalArgumentExceptionIfTheInputIsEmpty() throws Exception {
7377
parser.parseFromJson(" ");
7478
}
75-
79+
7680
@Test
7781
public void itShouldParseANullDeadlineAsNull() {
7882
String exercisesJson =
@@ -86,9 +90,9 @@ public void itShouldParseANullDeadlineAsNull() {
8690
"returnable: true" +
8791
"}]";
8892
String json = "{api_version: 1, courses: [{\"name\": \"TheCourse\",\"exercises\": " + exercisesJson + "}]}";
89-
93+
9094
List<Course> result = parser.parseFromJson(json);
91-
95+
9296
assertNull(result.get(0).getExercises().get(0).getDeadline());
9397
}
9498
}

0 commit comments

Comments
 (0)