Left pad string with spaces

This example will show how to pad a string at the beginning with spaces in groovy. We took a random string Nine and will call the padLeft passing in the number of characters and the space to pad with. The string produced will be the length of nine with leading spaces. A similar example showing how to pad a string with leading spaces in java guava or apache commons.

@Test
void left_pad_string_with_spaces() {

    def ninePadded = "Nine".padLeft(9, " ")

    assert "     Nine" == ninePadded
    assert 9 == ninePadded.length()

}