Skip to content
Merged
Changes from 2 commits
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,41 @@
package io.jenkins.plugins.forensics.miner;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.*;
import static org.mockito.Mockito.*;

class AddedVersusDeletedLinesForensicsSeriesBuilderTest {

private static final String ADDED = "added";
private static final String DELETED = "deleted";

@Test
void shouldCreateSeriesWithMockito() {
// Given
AddedVersusDeletedLinesForensicsSeriesBuilder builder = new AddedVersusDeletedLinesForensicsSeriesBuilder();
ForensicsBuildAction actionStub = mock(ForensicsBuildAction.class);
when(actionStub.getCommitStatistics()).thenReturn(createCommitStatistics(0, 0));
Copy link
Member

Choose a reason for hiding this comment

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

Use different values so we see that the key mapping is correct.


// When
Map<String, Integer> series = builder.computeSeries(actionStub);

// Then
assertThat(series)
.containsEntry(ADDED, 0)
.containsEntry(DELETED, 0);

}

private CommitStatistics createCommitStatistics(final int added, final int delted) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
private CommitStatistics createCommitStatistics(final int added, final int delted) {
private CommitStatistics createCommitStatistics(final int added, final int deleted) {

List<CommitDiffItem> commits = new ArrayList<>();
CommitDiffItem item = new CommitDiffItem("1", "author", 1);
item.addLines(added).deleteLines(delted);
commits.add(item);
return new CommitStatistics(commits);
}
}