001/**
002 * Logback: the reliable, generic, fast and flexible logging framework.
003 * Copyright (C) 1999-2015, QOS.ch. All rights reserved.
004 *
005 * This program and the accompanying materials are dual-licensed under
006 * either the terms of the Eclipse Public License v1.0 as published by
007 * the Eclipse Foundation
008 *
009 *   or (per the licensee's choosing)
010 *
011 * under the terms of the GNU Lesser General Public License version 2.1
012 * as published by the Free Software Foundation.
013 */
014package ch.qos.logback.core.pattern;
015
016import static org.junit.Assert.assertEquals;
017
018import org.junit.After;
019import org.junit.AfterClass;
020import org.junit.Before;
021import org.junit.BeforeClass;
022import org.junit.Test;
023
024public class SpacePadderTest {
025
026    @BeforeClass
027    public static void setUpBeforeClass() throws Exception {
028    }
029
030    @AfterClass
031    public static void tearDownAfterClass() throws Exception {
032    }
033
034    @Before
035    public void setUp() throws Exception {
036    }
037
038    @After
039    public void tearDown() throws Exception {
040    }
041
042    @Test
043    public void smoke() {
044        {
045            StringBuilder buf = new StringBuilder();
046            String s = "a";
047            SpacePadder.leftPad(buf, s, 4);
048            assertEquals("   a", buf.toString());
049        }
050        {
051            StringBuilder buf = new StringBuilder();
052            String s = "a";
053            SpacePadder.rightPad(buf, s, 4);
054            assertEquals("a   ", buf.toString());
055        }
056    }
057
058    @Test
059    public void nullString() {
060        String s = null;
061        {
062            StringBuilder buf = new StringBuilder();
063            SpacePadder.leftPad(buf, s, 2);
064            assertEquals("  ", buf.toString());
065        }
066        {
067            StringBuilder buf = new StringBuilder();
068            SpacePadder.rightPad(buf, s, 2);
069            assertEquals("  ", buf.toString());
070        }
071    }
072
073    @Test
074    public void longString() {
075        {
076            StringBuilder buf = new StringBuilder();
077            String s = "abc";
078            SpacePadder.leftPad(buf, s, 2);
079            assertEquals(s, buf.toString());
080        }
081
082        {
083            StringBuilder buf = new StringBuilder();
084            String s = "abc";
085            SpacePadder.rightPad(buf, s, 2);
086            assertEquals(s, buf.toString());
087        }
088    }
089
090    @Test
091    public void lengthyPad() {
092        {
093            StringBuilder buf = new StringBuilder();
094            String s = "abc";
095            SpacePadder.leftPad(buf, s, 33);
096            assertEquals("                              abc", buf.toString());
097        }
098        {
099            StringBuilder buf = new StringBuilder();
100            String s = "abc";
101            SpacePadder.rightPad(buf, s, 33);
102            assertEquals("abc                              ", buf.toString());
103        }
104
105    }
106
107}