-
Notifications
You must be signed in to change notification settings - Fork 31
A first test for ForensicsTableModel
#341
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
a9705cb
52f1287
a29d400
54b8381
67d88a0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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(){ | ||||||
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); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use the generated assertions:
Suggested change
|
||||||
} | ||||||
|
||||||
@Test | ||||||
void getColumns() { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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()); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This would be much simpler without duplications:
|
||||||
} | ||||||
|
||||||
@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); | ||||||
} | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||||||
} | ||||||
|
||||||
} |
There was a problem hiding this comment.
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.