package com.levelup.java.string;

import static org.hamcrest.CoreMatchers.endsWith;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;

import org.apache.commons.lang3.StringUtils;
import org.junit.Test;

import com.google.common.base.Strings;

/**
 * This java example will demonstrate right padding a string
 * of size 10 with spaces and 0
 * 
 * @author Justin Musgrove
 * @see <a href='http://www.leveluplunch.com/java/'></a>
 * 
 */
public class RightPadString {

	@Test
	public void right_pad_string_with_zeros_java () {

		String rightPaddedString = String.format("%-10s", "levelup").replace(' ', '0');

		assertEquals(10, rightPaddedString.length());
		assertThat(rightPaddedString, endsWith("0"));
	}
	
	@Test
	public void right_pad_string_with_spaces_java () {

		String rightPaddedString = String.format("%-10s", "levelup").replace(' ', ' ');

		assertEquals(10, rightPaddedString.length());
		assertThat(rightPaddedString, endsWith(" "));
	}

	@Test
	public void right_pad_string_with_zeros_guava () {
		
		String rightPaddedString = Strings.padEnd("levelup", 10, '0');
		
		assertEquals(10, rightPaddedString.length());
		assertThat(rightPaddedString, endsWith("0"));
	}

	@Test
	public void right_pad_string_with_spaces_guava () {

		String rightPaddedString = Strings.padEnd("levelup", 10, ' ');
		
		assertEquals(10, rightPaddedString.length());
		assertThat(rightPaddedString, endsWith(" "));
	}
	
	@Test
	public void right_pad_string_with_zeros_apache_commons () {
		String rightPaddedString = StringUtils.rightPad("levelup", 10, "0");
		
		assertEquals(10, rightPaddedString.length());
		assertThat(rightPaddedString, endsWith("0"));
	}

	@Test
	public void right_pad_string_with_spaces_apache_commons () {
		String rightPaddedString = StringUtils.rightPad("levelup", 10, " ");
		
		assertEquals(10, rightPaddedString.length());
		assertThat(rightPaddedString, endsWith(" "));
	}

	
	
}

@@ -457,10 +457,52 @@
 ava/
-'%3E
+examples/right-pad-string/'%3ERight pad string
 %3C/a%3E
@@ -679,24 +679,73 @@
 ' ', '0');%0A%0A
+%09%09assertEquals(%22levelup000%22, rightPaddedString);%0A
 %09%09assertEqua
@@ -971,25 +971,76 @@
 (' ', ' ');%0A
+%09%09%0A%09%09assertEquals(%22levelup   %22, rightPaddedString);
 %0A
-
 %09%09assertEqua
@@ -1253,24 +1253,73 @@
 0, '0');%0A%09%09%0A
+%09%09assertEquals(%22levelup000%22, rightPaddedString);%0A
 %09%09assertEqua
@@ -1527,32 +1527,81 @@
 %22, 10, ' ');%0A%09%09%0A
+%09%09assertEquals(%22levelup   %22, rightPaddedString);%0A
 %09%09assertEquals(1
@@ -1745,32 +1745,35 @@
 he_commons () %7B%0A
+%09%09%0A
 %09%09String rightPa
@@ -1826,24 +1826,73 @@
 0, %220%22);%0A%09%09%0A
+%09%09assertEquals(%22levelup000%22, rightPaddedString);%0A
 %09%09assertEqua
@@ -2048,16 +2048,19 @@
 ns () %7B%0A
+%09%09%0A
 %09%09String
@@ -2118,27 +2118,76 @@
 , 10, %22 %22);%0A
-
 %09%09%0A
+%09%09assertEquals(%22levelup   %22, rightPaddedString);%0A
 %09%09assertEqua

format add url