-
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
Conversation
Codecov Report
@@ Coverage Diff @@
## master #341 +/- ##
============================================
+ Coverage 50.04% 52.88% +2.83%
- Complexity 253 257 +4
============================================
Files 42 42
Lines 1093 1093
Branches 92 92
============================================
+ Hits 547 578 +31
+ Misses 510 479 -31
Partials 36 36
Continue to review full report at Codecov.
|
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.
AssertJ has some nice shortcuts to keep the code clean (and small)!
private static final int ONE_DAY = 60 * 60 * 24; | ||
|
||
@Test | ||
void shouldCreateForensicsTableModel(){ |
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.
@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); | ||
} | ||
|
||
@Test | ||
void getColumns() { |
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.
I think it has no extra value if you separate this test in 3 methods: combine them in a single one.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Use the generated assertions:
assertThat(tableModel.getId()).isEqualTo(ForensicsJobAction.FORENSICS_ID); | |
assertThat(tableModel).hasId(ForensicsJobAction.FORENSICS_ID); |
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 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(), ... );
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Check one row content as well.
assertThat(actual).isInstanceOf(ForensicsRow.class); | ||
assertThat((ForensicsRow) actual).hasAuthorsSize(0); |
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.
A simpler way to avoid the cast is:
assertThat(actual).isInstanceOfSatisfying(ForensicsRow.class,
row -> assertThat(row).hasAuthorsSize(0));
|
||
assertThat(forensicsRow) | ||
.hasFileName( | ||
"<a href=\"fileName.-734768633\" data-bs-toggle=\"tooltip\" data-bs-placement=\"left\" title=\"filename\">filename</a>") |
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.
This might be too fragile but is ok for now. (It might break just because the UI changes.)
A first test for
ForensicsTableModel
, which uses the constructor to create an instance and check getId(), getColumns() and getRows().