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