1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.commons.logging.simple;
19
20 import java.text.DateFormat;
21 import java.text.SimpleDateFormat;
22 import java.util.Date;
23
24 import org.apache.commons.logging.PathableClassLoader;
25 import org.apache.commons.logging.PathableTestSuite;
26
27 import junit.framework.Test;
28
29
30
31
32 public class DateTimeCustomConfigTestCase extends CustomConfigTestCase {
33
34
35
36
37
38
39
40
41
42
43
44
45
46 public static Test suite() throws Exception {
47 final Class thisClass = DateTimeCustomConfigTestCase.class;
48
49 final PathableClassLoader loader = new PathableClassLoader(null);
50 loader.useExplicitLoader("junit.", Test.class.getClassLoader());
51 loader.addLogicalLib("testclasses");
52 loader.addLogicalLib("commons-logging");
53
54 final Class testClass = loader.loadClass(thisClass.getName());
55 return new PathableTestSuite(testClass, loader);
56 }
57
58
59 @Override
60 protected void checkDecoratedDateTime() {
61 assertEquals("Expected date format to be set", "dd.mm.yyyy",
62 ((DecoratedSimpleLog) log).getDateTimeFormat());
63
64 final Date now = new Date();
65 final DateFormat formatter = ((DecoratedSimpleLog) log).getDateTimeFormatter();
66 final SimpleDateFormat sampleFormatter = new SimpleDateFormat("dd.mm.yyyy");
67 assertEquals("Date should be formatters to pattern dd.mm.yyyy",
68 sampleFormatter.format(now), formatter.format(now));
69 }
70
71
72 @Override
73 protected void checkShowDateTime() {
74 assertTrue(((DecoratedSimpleLog) log).getShowDateTime());
75 }
76
77
78
79
80
81
82 @Override
83 public void setProperties() {
84 super.setProperties();
85
86 System.setProperty(
87 "org.apache.commons.logging.simplelog.dateTimeFormat",
88 "dd.mm.yyyy");
89 System.setProperty(
90 "org.apache.commons.logging.simplelog.showdatetime",
91 "true");
92 }
93
94
95
96
97 @Override
98 public void setUp() throws Exception {
99 super.setUp();
100 }
101
102 }