Ejemplo n.º 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);
  }
Ejemplo n.º 2
0
 /** @throws java.lang.Exception */
 @Before
 public void setUp() throws Exception {
   clogWriter = new ChangeLogWriter();
   // create a testproject and add a file to it
   project = new ChangeLogTestProject("changelogWriterProject");
   // Generate full path to ChangeLog file
   changelogFilePath = CHANGELOG_FILE_PATH + CHANGELOG_FILE_NAME;
   // add a ChangeLog file to the project at the path specified by
   // CHANGELOG_FILE_PATH_SEGMENTS
   InputStream newFileInputStream = new ByteArrayInputStream(changeLogContent.getBytes());
   changelogFile =
       project.addFileToProject(
           CHANGELOG_FILE_PATH + CHANGELOG_FILE_NAME, CHANGELOG_FILE_NAME, newFileInputStream);
 }
Ejemplo n.º 3
0
 /** @throws java.lang.Exception */
 @After
 public void tearDown() throws CoreException {
   // dispose testproject
   project.getTestProject().delete(true, null);
 }