1
2
3
4
5
6
7
8
9
10
11
12
13
14 package ch.qos.logback.classic.pattern;
15
16 import org.junit.jupiter.api.Test;
17
18 import static org.junit.jupiter.api.Assertions.assertEquals;
19
20 public class TargetLengthBasedClassNameAbbreviatorTest {
21
22 @Test
23 public void testShortName() {
24 {
25 TargetLengthBasedClassNameAbbreviator abbreviator = new TargetLengthBasedClassNameAbbreviator(100);
26 String name = "hello";
27 assertEquals(name, abbreviator.abbreviate(name));
28 }
29 {
30 TargetLengthBasedClassNameAbbreviator abbreviator = new TargetLengthBasedClassNameAbbreviator(100);
31 String name = "hello.world";
32 assertEquals(name, abbreviator.abbreviate(name));
33 }
34 }
35
36 @Test
37 public void testNoDot() {
38 TargetLengthBasedClassNameAbbreviator abbreviator = new TargetLengthBasedClassNameAbbreviator(1);
39 String name = "hello";
40 assertEquals(name, abbreviator.abbreviate(name));
41 }
42
43 @Test
44 public void testOneDot() {
45 {
46 TargetLengthBasedClassNameAbbreviator abbreviator = new TargetLengthBasedClassNameAbbreviator(1);
47 String name = "hello.world";
48 assertEquals("h.world", abbreviator.abbreviate(name));
49 }
50
51 {
52 TargetLengthBasedClassNameAbbreviator abbreviator = new TargetLengthBasedClassNameAbbreviator(1);
53 String name = "h.world";
54 assertEquals("h.world", abbreviator.abbreviate(name));
55 }
56
57 {
58 TargetLengthBasedClassNameAbbreviator abbreviator = new TargetLengthBasedClassNameAbbreviator(1);
59 String name = ".world";
60 assertEquals(".world", abbreviator.abbreviate(name));
61 }
62 }
63
64 @Test
65 public void testTwoDot() {
66 {
67 TargetLengthBasedClassNameAbbreviator abbreviator = new TargetLengthBasedClassNameAbbreviator(1);
68 String name = "com.logback.Foobar";
69 assertEquals("c.l.Foobar", abbreviator.abbreviate(name));
70 }
71
72 {
73 TargetLengthBasedClassNameAbbreviator abbreviator = new TargetLengthBasedClassNameAbbreviator(1);
74 String name = "c.logback.Foobar";
75 assertEquals("c.l.Foobar", abbreviator.abbreviate(name));
76 }
77
78 {
79 TargetLengthBasedClassNameAbbreviator abbreviator = new TargetLengthBasedClassNameAbbreviator(1);
80 String name = "c..Foobar";
81 assertEquals("c..Foobar", abbreviator.abbreviate(name));
82 }
83 {
84 TargetLengthBasedClassNameAbbreviator abbreviator = new TargetLengthBasedClassNameAbbreviator(1);
85 String name = "..Foobar";
86 assertEquals("..Foobar", abbreviator.abbreviate(name));
87 }
88 }
89
90 @Test
91 public void test3Dot() {
92 {
93 TargetLengthBasedClassNameAbbreviator abbreviator = new TargetLengthBasedClassNameAbbreviator(1);
94 String name = "com.logback.xyz.Foobar";
95 assertEquals("c.l.x.Foobar", abbreviator.abbreviate(name));
96 }
97 {
98 TargetLengthBasedClassNameAbbreviator abbreviator = new TargetLengthBasedClassNameAbbreviator(13);
99 String name = "com.logback.xyz.Foobar";
100 assertEquals("c.l.x.Foobar", abbreviator.abbreviate(name));
101 }
102 {
103 TargetLengthBasedClassNameAbbreviator abbreviator = new TargetLengthBasedClassNameAbbreviator(14);
104 String name = "com.logback.xyz.Foobar";
105 assertEquals("c.l.xyz.Foobar", abbreviator.abbreviate(name));
106 }
107
108 {
109 TargetLengthBasedClassNameAbbreviator abbreviator = new TargetLengthBasedClassNameAbbreviator(15);
110 String name = "com.logback.alligator.Foobar";
111 assertEquals("c.l.a.Foobar", abbreviator.abbreviate(name));
112 }
113 }
114
115 @Test
116 public void testXDot() {
117 {
118 TargetLengthBasedClassNameAbbreviator abbreviator = new TargetLengthBasedClassNameAbbreviator(21);
119 String name = "com.logback.wombat.alligator.Foobar";
120 assertEquals("c.l.w.a.Foobar", abbreviator.abbreviate(name));
121 }
122
123 {
124 TargetLengthBasedClassNameAbbreviator abbreviator = new TargetLengthBasedClassNameAbbreviator(22);
125 String name = "com.logback.wombat.alligator.Foobar";
126 assertEquals("c.l.w.alligator.Foobar", abbreviator.abbreviate(name));
127 }
128
129 {
130 TargetLengthBasedClassNameAbbreviator abbreviator = new TargetLengthBasedClassNameAbbreviator(1);
131 String name = "com.logback.wombat.alligator.tomato.Foobar";
132 assertEquals("c.l.w.a.t.Foobar", abbreviator.abbreviate(name));
133 }
134
135 {
136 TargetLengthBasedClassNameAbbreviator abbreviator = new TargetLengthBasedClassNameAbbreviator(21);
137 String name = "com.logback.wombat.alligator.tomato.Foobar";
138 assertEquals("c.l.w.a.tomato.Foobar", abbreviator.abbreviate(name));
139 }
140
141 {
142 TargetLengthBasedClassNameAbbreviator abbreviator = new TargetLengthBasedClassNameAbbreviator(29);
143 String name = "com.logback.wombat.alligator.tomato.Foobar";
144 assertEquals("c.l.w.alligator.tomato.Foobar", abbreviator.abbreviate(name));
145 }
146 }
147 }