Looking for a bug

Report a typo

Imagine that you copied a palindrome checker method from stackoverflow.com and now want to be sure that it works as you expect. Here is that suspicious code:

public class StringUtils {
    public static boolean isPalindrome(String string) {
        if (string == null || string.isBlank() || string.length() < 2) {
            return false;
        }

        int start = 0;
        int end = string.length() - 1;

        while (start < end) {
            if (string.charAt(start) != string.charAt(end)) {
                return false;
            }
            start++;
            end--;
        }

        return true;
    }
}

You quickly wrote a test method with some test cases:

import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.*;

import static org.junit.jupiter.api.Assertions.*;

class StringTests {

    @ParameterizedTest
    @ValueSource(strings = {"rotator", "Stats", "(radar)", "level", "race car"})
    void testPalindrome(String str) {
        assertTrue(StringUtils.isPalindrome(str));
    }
}

Which of the test cases are going to fail when you run this test?

Select one or more options from the list
___

Create a free account to access the full topic