KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > nutch > util > TestStringUtil


1 /* Copyright (c) 2003 The Nutch Organization. All rights reserved. */
2 /* Use subject to the conditions in http://www.nutch.org/LICENSE.txt. */
3
4 package net.nutch.util;
5
6 import junit.framework.TestCase;
7
8 /** Unit tests for StringUtil methods. */
9 public class TestStringUtil extends TestCase {
10   public TestStringUtil(String JavaDoc name) {
11     super(name);
12   }
13
14   public void testRightPad() {
15     String JavaDoc s= "my string";
16
17     String JavaDoc ps= StringUtil.rightPad(s, 0);
18     assertTrue(s.equals(ps));
19
20     ps= StringUtil.rightPad(s, 9);
21     assertTrue(s.equals(ps));
22
23     ps= StringUtil.rightPad(s, 10);
24     assertTrue( (s+" ").equals(ps) );
25
26     ps= StringUtil.rightPad(s, 15);
27     assertTrue( (s+" ").equals(ps) );
28
29   }
30
31   public void testLeftPad() {
32     String JavaDoc s= "my string";
33
34     String JavaDoc ps= StringUtil.leftPad(s, 0);
35     assertTrue(s.equals(ps));
36
37     ps= StringUtil.leftPad(s, 9);
38     assertTrue(s.equals(ps));
39
40     ps= StringUtil.leftPad(s, 10);
41     assertTrue( (" "+s).equals(ps) );
42
43     ps= StringUtil.leftPad(s, 15);
44     assertTrue( (" "+s).equals(ps) );
45
46   }
47
48 }
49
Popular Tags