/**
   * Tests that the visitor properly appends or overwrites according to the file block "append
   * mode".
   */
  public void testFileBlockAppendMode() {
    final FileBlock mtlFileBlock = getDummyFileBlock();
    final String fileName = "validFile.url"; // $NON-NLS-1$
    mtlFileBlock.setFileUrl(createOCLExpression('\'' + fileName + '\''));
    mtlFileBlock.setOpenMode(OpenModeKind.APPEND);

    /*
     * Appending with no file at first : we expect the preview to contain a single file with the result of
     * one evaluation
     */
    evaluationVisitor.visitExpression(getParentTemplate(mtlFileBlock));
    assertSame("Expecting a single preview", 1, getPreview().size()); // $NON-NLS-1$
    Map.Entry<String, String> entry = getPreview().entrySet().iterator().next();
    assertEquals(
        "Unexpected file URL.", //$NON-NLS-1$
        generationRoot.getAbsolutePath() + File.separatorChar + fileName,
        entry.getKey());
    assertEquals(
        "File hasn't been created as expected.",
        OUTPUT,
        entry.getValue().toString()); // $NON-NLS-1$

    /*
     * Appending a second time : we expect the preview to contain a single file with the result of two
     * evaluation
     */
    evaluationVisitor.visitExpression(getParentTemplate(mtlFileBlock));
    assertSame("Expecting a single preview", 1, getPreview().size()); // $NON-NLS-1$
    entry = getPreview().entrySet().iterator().next();
    assertEquals(
        "Unexpected file URL.", //$NON-NLS-1$
        generationRoot.getAbsolutePath() + File.separatorChar + fileName,
        entry.getKey());
    assertEquals(
        "File hasn't been appended to as expected.",
        OUTPUT //$NON-NLS-1$
            + System.getProperty("line.separator")
            + OUTPUT,
        entry.getValue().toString()); // $NON-NLS-1$

    // Now set the append mode to overwrite and check that the file is created anew.
    mtlFileBlock.setOpenMode(OpenModeKind.OVER_WRITE);
    evaluationVisitor.visitExpression(getParentTemplate(mtlFileBlock));
    assertSame("Expecting a single preview", 1, getPreview().size()); // $NON-NLS-1$
    entry = getPreview().entrySet().iterator().next();
    assertEquals(
        "Unexpected file URL.", //$NON-NLS-1$
        generationRoot.getAbsolutePath() + File.separatorChar + fileName,
        entry.getKey());
    assertEquals(
        "File hasn't been appended to as expected.",
        OUTPUT,
        entry
            .getValue() //$NON-NLS-1$
            .toString());
  }
 /**
  * Creates a dummy file block containing a single string literal as its body.
  *
  * @return Dummy file block.
  */
 private FileBlock getDummyFileBlock() {
   final FileBlock mtlFileBlock = MtlFactory.eINSTANCE.createFileBlock();
   mtlFileBlock.setOpenMode(OpenModeKind.OVER_WRITE);
   mtlFileBlock.getBody().add(createOCLExpression('\'' + OUTPUT + '\''));
   getDummyTemplate().getBody().add(mtlFileBlock);
   return mtlFileBlock;
 }