Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package io.jenkins.plugins.forensics.miner;

import java.util.Collections;

import org.junit.jupiter.api.Test;

import edu.hm.hafner.util.TreeString;
import edu.hm.hafner.util.TreeStringBuilder;


import io.jenkins.plugins.forensics.miner.FileStatistics.FileStatisticsBuilder;

import static io.jenkins.plugins.forensics.assertions.Assertions.assertThat;


class ForensicsTableModelTest {
private static final String FILE = "file";
private static final TreeString FILE_TREE_STRING = new TreeStringBuilder().intern(FILE);
private static final int ONE_DAY = 60 * 60 * 24;

@Test
void shouldCreateForensicsTableModel(){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should install the CheckStyle plugin, then those warnings will be flagged in IntelliJ.

RepositoryStatistics statistics = new RepositoryStatistics();
ForensicsTableModel tableModel = new ForensicsTableModel(statistics);
assertThat(tableModel).isNotNull();
}


@Test
void getId() {
RepositoryStatistics statistics = new RepositoryStatistics();
ForensicsTableModel tableModel = new ForensicsTableModel(statistics);
assertThat(tableModel.getId()).isEqualTo(ForensicsJobAction.FORENSICS_ID);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the generated assertions:

Suggested change
assertThat(tableModel.getId()).isEqualTo(ForensicsJobAction.FORENSICS_ID);
assertThat(tableModel).hasId(ForensicsJobAction.FORENSICS_ID);

}

@Test
void getColumns() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it has no extra value if you separate this test in 3 methods: combine them in a single one.

RepositoryStatistics statistics = new RepositoryStatistics();
ForensicsTableModel tableModel = new ForensicsTableModel(statistics);

assertThat(tableModel.getColumns().size()).isEqualTo(7);
assertThat(tableModel.getColumns().get(0).getHeaderLabel()).isEqualTo(Messages.Table_Column_File());
assertThat(tableModel.getColumns().get(1).getHeaderLabel()).isEqualTo(Messages.Table_Column_AuthorsSize());
assertThat(tableModel.getColumns().get(2).getHeaderLabel()).isEqualTo(Messages.Table_Column_CommitsSize());
assertThat(tableModel.getColumns().get(3).getHeaderLabel()).isEqualTo(Messages.Table_Column_LastCommit());
assertThat(tableModel.getColumns().get(4).getHeaderLabel()).isEqualTo(Messages.Table_Column_AddedAt());
assertThat(tableModel.getColumns().get(5).getHeaderLabel()).isEqualTo(Messages.Table_Column_LOC());
assertThat(tableModel.getColumns().get(6).getHeaderLabel()).isEqualTo(Messages.Table_Column_Churn());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be much simpler without duplications:

        assertThat(tableModel.getColumns())
                .hasSize(7)
                .extracting(TableColumn::getHeaderLabel)
                .containsExactly(
                        Messages.Table_Column_File(), ... );

}

@Test
void getRows() {
RepositoryStatistics statistics = new RepositoryStatistics();
statistics.addAll(Collections.singleton(createFileStatistics()));
ForensicsTableModel tableModel = new ForensicsTableModel(statistics);
tableModel.getRows();
assertThat(tableModel.getRows().size()).isEqualTo(1);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Check one row content as well.



private FileStatistics createFileStatistics() {
FileStatistics fileStatistics = new FileStatisticsBuilder().build(FILE);
CommitDiffItem commit = new CommitDiffItem("1", "one", ONE_DAY * 9)
.setNewPath(FILE_TREE_STRING);
fileStatistics.inspectCommit(commit);
return fileStatistics;
}

}