1
2
3
4
5
6
7
8
9
10 package org.eclipse.jgit.util;
11
12 import static org.junit.Assert.fail;
13
14 import java.text.ParseException;
15 import java.util.Calendar;
16 import java.util.GregorianCalendar;
17
18 import org.eclipse.jgit.junit.MockSystemReader;
19 import org.junit.After;
20 import org.junit.Before;
21 import org.junit.experimental.theories.DataPoints;
22 import org.junit.experimental.theories.Theories;
23 import org.junit.experimental.theories.Theory;
24 import org.junit.runner.RunWith;
25
26
27
28
29 @RunWith(Theories.class)
30 public class GitDateParserBadlyFormattedTest {
31 private String dateStr;
32
33 @Before
34 public void setUp() {
35 MockSystemReader mockSystemReader = new MockSystemReader();
36 SystemReader.setInstance(mockSystemReader);
37 }
38
39 @After
40 public void tearDown() {
41 SystemReader.setInstance(null);
42 }
43
44 public GitDateParserBadlyFormattedTest(String dateStr) {
45 this.dateStr = dateStr;
46 }
47
48 @DataPoints
49 public static String[] getDataPoints() {
50 return new String[] { "", "1970", "3000.3000.3000", "3 yesterday ago",
51 "now yesterday ago", "yesterdays", "3.day. 2.week.ago",
52 "day ago", "Gra Feb 21 15:35:00 2007 +0100",
53 "Sun Feb 21 15:35:00 2007 +0100",
54 "Wed Feb 21 15:35:00 Grand +0100" };
55 }
56
57 @Theory
58 public void badlyFormattedWithExplicitRef() {
59 Calendar ref = new GregorianCalendar(SystemReader.getInstance()
60 .getTimeZone(), SystemReader.getInstance().getLocale());
61 try {
62 GitDateParser.parse(dateStr, ref, SystemReader.getInstance()
63 .getLocale());
64 fail("The expected ParseException while parsing '" + dateStr
65 + "' did not occur.");
66 } catch (ParseException e) {
67
68 }
69 }
70
71 @Theory
72 public void badlyFormattedWithoutRef() {
73 try {
74 GitDateParser.parse(dateStr, null, SystemReader.getInstance()
75 .getLocale());
76 fail("The expected ParseException while parsing '" + dateStr
77 + "' did not occur.");
78 } catch (ParseException e) {
79
80 }
81 }
82 }