1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.log4j.pattern;
19
20 import junit.framework.TestCase;
21
22
23
24
25
26
27
28
29 public class FormattingInfoTest extends TestCase {
30
31
32
33
34
35 public FormattingInfoTest(final String name) {
36 super(name);
37 }
38
39
40
41
42
43 public void testGetDefault() {
44 FormattingInfo field = FormattingInfo.getDefault();
45 assertNotNull(field);
46 assertEquals(0, field.getMinLength());
47 assertEquals(Integer.MAX_VALUE, field.getMaxLength());
48 assertEquals(false, field.isLeftAligned());
49 }
50
51
52
53
54
55 public void testConstructor() {
56 FormattingInfo field = new FormattingInfo(true, 3, 6);
57 assertNotNull(field);
58 assertEquals(3, field.getMinLength());
59 assertEquals(6, field.getMaxLength());
60 assertEquals(true, field.isLeftAligned());
61 }
62
63
64
65
66 public void testTruncate() {
67 StringBuffer buf = new StringBuffer("foobar");
68 FormattingInfo field = new FormattingInfo(true, 0, 3);
69 field.format(2, buf);
70 assertEquals("fobar", buf.toString());
71 }
72
73
74
75
76 public void testPadLeft() {
77 StringBuffer buf = new StringBuffer("foobar");
78 FormattingInfo field = new FormattingInfo(false, 5, 10);
79 field.format(2, buf);
80 assertEquals("fo obar", buf.toString());
81 }
82
83
84
85
86 public void testPadRight() {
87 StringBuffer buf = new StringBuffer("foobar");
88 FormattingInfo field = new FormattingInfo(true, 5, 10);
89 field.format(2, buf);
90 assertEquals("foobar ", buf.toString());
91 }
92
93 }