LeftPadUtilsTest.java•1.37 kB
package org.example;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
public class LeftPadUtilsTest {
@Test
public void testNullInput() {
assertNull(LeftPadUtils.leftPad(null, 5, "x"));
}
@Test
public void testNoPaddingNeeded() {
String s = "hello";
assertEquals("hello", LeftPadUtils.leftPad(s, 3, " "));
}
@Test
public void testPadEqualLength() {
String s = "bob";
assertEquals("---bob", LeftPadUtils.leftPad(s, 6, "---"));
}
@Test
public void testPadLessThanPadLen() {
String s = "x";
assertEquals("abx", LeftPadUtils.leftPad(s, 3, "abcd"));
}
@Test
public void testPadGreaterThanPadLen() {
String s = "A";
assertEquals("01010A", LeftPadUtils.leftPad(s, 6, "01"));
}
@Test
public void testEmptyPadUsesSpace() {
String s = "z";
assertEquals(" z", LeftPadUtils.leftPad(s, 3, ""));
}
@Test
public void testPrivateConstructorCovered() throws Exception {
var ctor = LeftPadUtils.class.getDeclaredConstructor();
ctor.setAccessible(true);
try {
ctor.newInstance();
} catch (Throwable ignored) {
// constructor throws AssertionError by design; invocation covers constructor for coverage
}
}
}