Everything works fine and matches the example but the testing fails:
public static void main(String[] args) {
        PrintStream backup = System.out;

        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        PrintStream printStream = new PrintStream(outputStream);
        System.setOut(printStream);

        new TestString().printSomething();

        String result = outputStream.toString();
        System.setOut(backup);
        StringBuilder sb = new StringBuilder(result);
        while (sb.indexOf("te") != -1) sb.replace(sb.indexOf("te"), sb.indexOf("te") + 2, "??");
        String replacedString = sb.toString();
        System.out.println(replacedString);


    }

    public static class TestString {
        public void printSomething() {
            System.out.println("This is text for testing");
        }
    }