1   /*
2    * Copyright 2004 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package com.ancientprogramming.fixedformat4j.annotation;
17  
18  import junit.framework.TestCase;
19  
20  /**
21   * @author Jacob von Eyben - http://www.ancientprogramming.com
22   * @since 1.0.0
23   */
24  public class TestAlign extends TestCase {
25  
26    public void testLeftPadding() {
27      assertEquals(" ", Align.RIGHT.apply(null, 1, ' '));
28      assertEquals(" ", Align.RIGHT.apply(" ", 1, ' '));
29      assertEquals("r", Align.RIGHT.apply("foobar", 1, ' '));
30      assertEquals("bar", Align.RIGHT.apply("foobar", 3, ' '));
31      assertEquals("foobar", Align.RIGHT.apply("foobar", 6, ' '));
32      assertEquals(" foobar", Align.RIGHT.apply("foobar", 7, ' '));
33      assertEquals("__foobar", Align.RIGHT.apply("foobar", 8, '_'));
34    }
35  
36    public void testLeftRemove() {
37      assertEquals("", Align.RIGHT.remove(null, ' '));
38      assertEquals("", Align.RIGHT.remove(" ", ' '));
39      assertEquals("foobar  ", Align.RIGHT.remove("foobar  ", ' '));
40      assertEquals("foobar", Align.RIGHT.remove("  foobar", ' '));
41    }
42  
43    public void testRightPadding() {
44      assertEquals(" ", Align.LEFT.apply(null, 1, ' '));
45      assertEquals(" ", Align.LEFT.apply(" ", 1, ' '));
46      assertEquals("f", Align.LEFT.apply("foobar", 1, ' '));
47      assertEquals("foo", Align.LEFT.apply("foobar", 3, ' '));
48      assertEquals("foobar", Align.LEFT.apply("foobar", 6, ' '));
49      assertEquals("foobar ", Align.LEFT.apply("foobar", 7, ' '));
50      assertEquals("foobar__", Align.LEFT.apply("foobar", 8, '_'));
51    }
52  
53    public void testRightRemove() {
54      assertEquals("", Align.LEFT.remove(null, ' '));
55      assertEquals("", Align.LEFT.remove(" ", ' '));
56      assertEquals("foobar", Align.LEFT.remove("foobar  ", ' '));
57      assertEquals("  foobar", Align.LEFT.remove("  foobar", ' '));
58    }
59  }