1
2
3
4
5
6
7
8
9
10
11 package org.eclipse.jgit.util;
12
13 import static org.junit.Assert.assertEquals;
14 import static org.junit.Assert.assertTrue;
15
16 import org.eclipse.jgit.junit.MockSystemReader;
17 import org.eclipse.jgit.lib.PersonIdent;
18 import org.eclipse.jgit.util.GitDateFormatter.Format;
19 import org.junit.After;
20 import org.junit.Before;
21 import org.junit.Test;
22
23 public class GitDateFormatterTest {
24
25 private MockSystemReader mockSystemReader;
26
27 private PersonIdent ident;
28
29 @Before
30 public void setUp() {
31 mockSystemReader = new MockSystemReader() {
32 @Override
33 public long getCurrentTime() {
34 return 1318125997291L;
35 }
36 };
37 SystemReader.setInstance(mockSystemReader);
38 ident = RawParseUtils
39 .parsePersonIdent("A U Thor <author@example.com> 1316560165 -0400");
40 }
41
42 @After
43 public void tearDown() {
44 SystemReader.setInstance(null);
45 }
46
47 @Test
48 public void DEFAULT() {
49 assertEquals("Tue Sep 20 19:09:25 2011 -0400", new GitDateFormatter(
50 Format.DEFAULT).formatDate(ident));
51 }
52
53 @Test
54 public void RELATIVE() {
55 assertEquals("3 weeks ago",
56 new GitDateFormatter(Format.RELATIVE).formatDate(ident));
57 }
58
59 @Test
60 public void LOCAL() {
61 assertEquals("Tue Sep 20 19:39:25 2011", new GitDateFormatter(
62 Format.LOCAL).formatDate(ident));
63 }
64
65 @Test
66 public void ISO() {
67 assertEquals("2011-09-20 19:09:25 -0400", new GitDateFormatter(
68 Format.ISO).formatDate(ident));
69 }
70
71 @Test
72 public void RFC() {
73 assertEquals("Tue, 20 Sep 2011 19:09:25 -0400", new GitDateFormatter(
74 Format.RFC).formatDate(ident));
75 }
76
77 @Test
78 public void SHORT() {
79 assertEquals("2011-09-20",
80 new GitDateFormatter(Format.SHORT).formatDate(ident));
81 }
82
83 @Test
84 public void RAW() {
85 assertEquals("1316560165 -0400",
86 new GitDateFormatter(Format.RAW).formatDate(ident));
87 }
88
89 @Test
90 public void LOCALE() {
91 String date = new GitDateFormatter(Format.LOCALE).formatDate(ident);
92 assertTrue("Sep 20, 2011 7:09:25 PM -0400".equals(date)
93 || "Sep 20, 2011, 7:09:25 PM -0400".equals(date));
94 }
95
96 @Test
97 public void LOCALELOCAL() {
98 String date = new GitDateFormatter(Format.LOCALELOCAL)
99 .formatDate(ident);
100 assertTrue("Sep 20, 2011 7:39:25 PM".equals(date)
101 || "Sep 20, 2011, 7:39:25 PM".equals(date));
102 }
103 }