public static String replaceSuffix(String str, String oldSuffix, String newSuffix) {
        if (!str.endsWith(oldSuffix))
            throw new IllegalArgumentException("Expected string to end with " + oldSuffix + " but string is " + str);
        return str.substring(0, str.length() - oldSuffix.length()) + newSuffix;
    }
@Test
    public void testReplaceSuffix() {
        assertEquals("blah.foo.text", Utils.replaceSuffix("blah.foo.txt", ".txt", ".text"));
        assertEquals("blah.foo", Utils.replaceSuffix("blah.foo.txt", ".txt", ""));
        assertEquals("txt.txt", Utils.replaceSuffix("txt.txt.txt", ".txt", ""));
        assertEquals("foo.txt", Utils.replaceSuffix("foo", "", ".txt"));
    }