Пример #1
0
  /**
   * Test the use of default text.
   *
   * @throws Exception
   */
  @Test
  public void canWriteChangeLogToEmptyChangeLogButWithSomeDefaultContent() throws Exception {
    // set GNU formatter
    clogWriter.setFormatter(new GNUFormat());

    // Open up a new ChangeLog file at newPathToChangeLog with empty content
    // and get the IEditorPart
    InputStream newFileInputStream = new ByteArrayInputStream("".getBytes()); // no content
    String destinationPath = "/this/is/some/random/path";
    IFile emptyChangeLogFile =
        project.addFileToProject(destinationPath, CHANGELOG_FILE_NAME, newFileInputStream);
    IEditorPart editorContent = EditorHelper.openEditor(emptyChangeLogFile);
    clogWriter.setChangelog(editorContent);

    String authorName = "Test Author";
    String email = "*****@*****.**";
    clogWriter.setDateLine(clogWriter.getFormatter().formatDateLine(authorName, email));
    clogWriter.setChangelogLocation(destinationPath + "/" + CHANGELOG_FILE_NAME);

    // Set some default content
    String defaultContent = "Removed.";
    clogWriter.setDefaultContent(defaultContent);

    String relativePathOfChangedFile = "path/to/file/for/new/entry/test.c";
    clogWriter.setEntryFilePath(destinationPath + "/" + relativePathOfChangedFile);

    clogWriter.setGuessedFName("");

    // Write changelog to buffer - need to save for persistence
    clogWriter.writeChangeLog();

    // above written content is not persistent yet; save it to make it persistent
    clogWriter.getChangelog().doSave(null);

    // Construct the changelog entry by hand and match it with what has been written
    String expectedChangeLogEntry = new GNUFormat().formatDateLine(authorName, email);
    expectedChangeLogEntry += "\t* " + relativePathOfChangedFile + ": " + defaultContent + "\n";

    // Read in content written to file
    StringBuffer actualContent = new StringBuffer();
    try (BufferedReader br =
        new BufferedReader(
            new InputStreamReader(
                new FileInputStream(emptyChangeLogFile.getLocation().toFile())))) {
      String line;
      while ((line = br.readLine()) != null) {
        actualContent.append(line + "\n");
      }
    }
    // Assert proper content has been added
    assertEquals(expectedChangeLogEntry, actualContent.toString());
    EditorHelper.closeEditor(editorContent);
  }
Пример #2
0
 @Test
 public void testGetSetDefaultContent() {
   final String defaultContent = "DISCLAIMER: default ChangeLog content for new files?";
   clogWriter.setDefaultContent(defaultContent);
   assertEquals(defaultContent, clogWriter.getDefaultContent());
 }