@Test
public void transformName() throws Exception
{

    MimetypeService dummyMimetypeService = new DummyMimetypeService("txt");
    
    // Case 1. A simple name with a reasonable extension.
    String original = "Letter to Bank Manager.doc";
    final String newMimetype = MimetypeMap.MIMETYPE_TEXT_PLAIN;
    String newName = TransformActionExecuter.transformName(dummyMimetypeService, original, newMimetype, true);
    assertEquals("Letter to Bank Manager.txt", newName);
    // Case 2. String after '.' is clearly not an extension
    original = "No.1 - First Document Title";
    newName = TransformActionExecuter.transformName(dummyMimetypeService, original, newMimetype, true);
    assertEquals(original + ".txt", newName);
    // Case 2b. String after '.' is clearly not an extension. Don't always add
    original = "No.1 - First Document Title";
    newName = TransformActionExecuter.transformName(dummyMimetypeService, original, newMimetype, false);
    assertEquals(original, newName);
    // Case 3. A name with no extension
    original = "Letter to Bank Manager";
    newName = TransformActionExecuter.transformName(dummyMimetypeService, original, newMimetype, true);
    assertEquals(original + ".txt", newName);
    
    // Case 3b. A name with no extension. Don't always add
    original = "Letter to Bank Manager";
    newName = TransformActionExecuter.transformName(dummyMimetypeService, original, newMimetype, false);
    assertEquals(original, newName);
    
    // Case 4. A name ending in a dot
    original = "Letter to Bank Manager.";
    newName = TransformActionExecuter.transformName(dummyMimetypeService, original, newMimetype, true);
    assertEquals(original + "txt", newName);
    
    // Case 4b. A name ending in a dot. Don't always add
    original = "Letter to Bank Manager.";
    newName = TransformActionExecuter.transformName(dummyMimetypeService, original, newMimetype, false);
    assertEquals(original, newName);
    
    // Case 5. Unknown mime type
    original = "Letter to Bank Manager.txt";
    final String unknownMimetype = "Marcel/Marceau";
    // The real MimetypeService returns a 'bin' extension for unknown mime types.
    dummyMimetypeService = new DummyMimetypeService("bin");
    
    newName = TransformActionExecuter.transformName(dummyMimetypeService, original, unknownMimetype, true);
    assertEquals("Letter to Bank Manager.bin", newName);
}