1
2
3
4
5
6
7
8
9
10 package ch.qos.logback.core.rolling.helper;
11
12 import static org.junit.Assert.*;
13
14 import java.util.Calendar;
15
16 import org.junit.Test;
17
18
19 import ch.qos.logback.core.Context;
20 import ch.qos.logback.core.ContextBase;
21
22
23
24
25
26 public class FileNamePatternTest {
27
28 Context context = new ContextBase();
29
30 @Test
31 public void testSmoke() {
32
33 FileNamePattern pp = new FileNamePattern("t", context);
34 assertEquals("t", pp.convertInt(3));
35
36
37 pp = new FileNamePattern("foo", context);
38 assertEquals("foo", pp.convertInt(3));
39
40
41
42
43
44
45 pp = new FileNamePattern("%i foo", context);
46
47 assertEquals("3 foo", pp.convertInt(3));
48
49 pp = new FileNamePattern("foo%i.xixo", context);
50 assertEquals("foo3.xixo", pp.convertInt(3));
51
52 pp = new FileNamePattern("foo%i.log", context);
53 assertEquals("foo3.log", pp.convertInt(3));
54
55 pp = new FileNamePattern("foo.%i.log", context);
56 assertEquals("foo.3.log", pp.convertInt(3));
57
58 pp = new FileNamePattern("%i.foo\\%", context);
59 assertEquals("3.foo%", pp.convertInt(3));
60
61 pp = new FileNamePattern("\\%foo", context);
62 assertEquals("%foo", pp.convertInt(3));
63 }
64
65 @Test
66
67 public void testFlowingI() {
68
69
70 {
71 FileNamePattern pp = new FileNamePattern("foo%i{}bar%i", context);
72 assertEquals("foo3bar3", pp.convertInt(3));
73 }
74 {
75 FileNamePattern pp = new FileNamePattern("foo%i{}bar%i", context);
76 assertEquals("foo3bar3", pp.convertInt(3));
77 }
78 }
79
80 @Test
81 public void testDate() {
82 Calendar cal = Calendar.getInstance();
83 cal.set(2003, 4, 20, 17, 55);
84
85 FileNamePattern pp = new FileNamePattern("foo%d{yyyy.MM.dd}", context);
86
87 assertEquals("foo2003.05.20", pp.convertDate(cal.getTime()));
88
89 pp = new FileNamePattern("foo%d{yyyy.MM.dd HH:mm}", context);
90 assertEquals("foo2003.05.20 17:55", pp.convertDate(cal.getTime()));
91
92 pp = new FileNamePattern("%d{yyyy.MM.dd HH:mm} foo", context);
93 assertEquals("2003.05.20 17:55 foo", pp.convertDate(cal.getTime()));
94
95 }
96
97 @Test
98 public void testWithBackslash() {
99 FileNamePattern pp = new FileNamePattern("c:\\foo\\bar.%i", context);
100 assertEquals("c:\\foo\\bar.3", pp.convertInt(3));
101 }
102
103
104 }