View Javadoc
1   /**
2    * Logback: the reliable, generic, fast and flexible logging framework.
3    * Copyright (C) 1999-2015, QOS.ch. All rights reserved.
4    *
5    * This program and the accompanying materials are dual-licensed under
6    * either the terms of the Eclipse Public License v1.0 as published by
7    * the Eclipse Foundation
8    *
9    *   or (per the licensee's choosing)
10   *
11   * under the terms of the GNU Lesser General Public License version 2.1
12   * as published by the Free Software Foundation.
13   */
14  package ch.qos.logback.core.pattern;
15  
16  import static org.junit.Assert.assertEquals;
17  
18  import org.junit.After;
19  import org.junit.AfterClass;
20  import org.junit.Before;
21  import org.junit.BeforeClass;
22  import org.junit.Test;
23  
24  public class SpacePadderTest {
25  
26      @BeforeClass
27      public static void setUpBeforeClass() throws Exception {
28      }
29  
30      @AfterClass
31      public static void tearDownAfterClass() throws Exception {
32      }
33  
34      @Before
35      public void setUp() throws Exception {
36      }
37  
38      @After
39      public void tearDown() throws Exception {
40      }
41  
42      @Test
43      public void smoke() {
44          {
45              StringBuilder buf = new StringBuilder();
46              String s = "a";
47              SpacePadder.leftPad(buf, s, 4);
48              assertEquals("   a", buf.toString());
49          }
50          {
51              StringBuilder buf = new StringBuilder();
52              String s = "a";
53              SpacePadder.rightPad(buf, s, 4);
54              assertEquals("a   ", buf.toString());
55          }
56      }
57  
58      @Test
59      public void nullString() {
60          String s = null;
61          {
62              StringBuilder buf = new StringBuilder();
63              SpacePadder.leftPad(buf, s, 2);
64              assertEquals("  ", buf.toString());
65          }
66          {
67              StringBuilder buf = new StringBuilder();
68              SpacePadder.rightPad(buf, s, 2);
69              assertEquals("  ", buf.toString());
70          }
71      }
72  
73      @Test
74      public void longString() {
75          {
76              StringBuilder buf = new StringBuilder();
77              String s = "abc";
78              SpacePadder.leftPad(buf, s, 2);
79              assertEquals(s, buf.toString());
80          }
81  
82          {
83              StringBuilder buf = new StringBuilder();
84              String s = "abc";
85              SpacePadder.rightPad(buf, s, 2);
86              assertEquals(s, buf.toString());
87          }
88      }
89  
90      @Test
91      public void lengthyPad() {
92          {
93              StringBuilder buf = new StringBuilder();
94              String s = "abc";
95              SpacePadder.leftPad(buf, s, 33);
96              assertEquals("                              abc", buf.toString());
97          }
98          {
99              StringBuilder buf = new StringBuilder();
100             String s = "abc";
101             SpacePadder.rightPad(buf, s, 33);
102             assertEquals("abc                              ", buf.toString());
103         }
104 
105     }
106 
107 }