Skip to content
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

Removed 3 unnecessary stubbings in ChangesSinceLastBuildMacroTest.java #201

Merged
merged 4 commits into from
Oct 27, 2023
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
Expand Up @@ -54,11 +54,9 @@ public void testShouldGetChangesForLatestBuild()
@Test
public void testShouldGetChangesForLatestBuildEvenWhenPreviousBuildsExist()
throws Exception {
AbstractBuild failureBuild = createBuild(Result.FAILURE, 41, "Changes for a failed build.");
AbstractBuild failureBuild = createBuild2(Result.FAILURE, 41, "Changes for a failed build.");

AbstractBuild currentBuild = createBuild(Result.SUCCESS, 42, "Changes for a successful build.");
when(currentBuild.getPreviousBuild()).thenReturn(failureBuild);
when(failureBuild.getNextBuild()).thenReturn(currentBuild);

String content = changesSinceLastBuildMacro.evaluate(currentBuild, listener, ChangesSinceLastBuildMacro.MACRO_NAME);

Expand Down Expand Up @@ -213,22 +211,16 @@ public void testShouldEscapeHtmlWhenArgumentEscapeHtmlSetToTrue()

private AbstractBuild createBuild(Result result, int buildNumber, String message) {
AbstractBuild build = mock(AbstractBuild.class);
when(build.getResult()).thenReturn(result);
ChangeLogSet changes1 = createChangeLog(message);
when(build.getChangeSet()).thenReturn(changes1);
when(build.getChangeSets()).thenReturn(Collections.singletonList(changes1));
when(build.getNumber()).thenReturn(buildNumber);

return build;
}

private AbstractBuild createBuildWithAffectedFiles(Result result, int buildNumber, String message) {
AbstractBuild build = mock(AbstractBuild.class);
when(build.getResult()).thenReturn(result);
ChangeLogSet changes1 = createChangeLogWithAffectedFiles(message);
when(build.getChangeSet()).thenReturn(changes1);
when(build.getChangeSets()).thenReturn(Collections.singletonList(changes1));
when(build.getNumber()).thenReturn(buildNumber);

return build;
}
Expand All @@ -246,19 +238,15 @@ public ChangeLogSet createChangeLog(String message) {

private AbstractBuild createBuildWithNoChanges(Result result, int buildNumber) {
AbstractBuild build = mock(AbstractBuild.class);
when(build.getResult()).thenReturn(result);
ChangeLogSet changes1 = createEmptyChangeLog();
when(build.getChangeSet()).thenReturn(changes1);
when(build.getChangeSets()).thenReturn(Collections.singletonList(changes1));
when(build.getNumber()).thenReturn(buildNumber);

return build;
}

public ChangeLogSet createEmptyChangeLog() {
ChangeLogSet changes = mock(ChangeLogSet.class);
List<ChangeLogSet.Entry> entries = Collections.emptyList();
when(changes.iterator()).thenReturn(entries.iterator());
when(changes.isEmptySet()).thenReturn(true);

return changes;
Expand Down Expand Up @@ -358,4 +346,19 @@ public Collection<AffectedFile> getAffectedFiles() {
};
}
}

private AbstractBuild createBuild2(Result result, int buildNumber, String message) {
AbstractBuild build = mock(AbstractBuild.class);
ChangeLogSet changes1 = createChangeLog2(message);

Copy link
Member

Choose a reason for hiding this comment

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

nit: extra whitespace here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for pointing it out, we removed it.

return build;
}

public ChangeLogSet createChangeLog2(String message) {
ChangeLogSet changes = mock(ChangeLogSet.class);
List<ChangeLogSet.Entry> entries = new LinkedList<ChangeLogSet.Entry>();
ChangeLogSet.Entry entry = new ChangeLogEntry(message, "Ash Lux");
entries.add(entry);
return changes;
}
}