1 2 3 4 package net.nutch.util; 5 6 import junit.framework.TestCase; 7 8 9 public class TestStringUtil extends TestCase { 10 public TestStringUtil(String name) { 11 super(name); 12 } 13 14 public void testRightPad() { 15 String s= "my string"; 16 17 String 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 s= "my string"; 33 34 String 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 |