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 1 unnecessary stubbings in ChangesSinceLastSuccessfulBuildMacroTest.java #200

Merged
merged 2 commits into from
Oct 20, 2023
Merged
Changes from all 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 @@ -53,7 +53,7 @@ public void testGetContent_shouldGetPreviousBuildFailures()
throws Exception {
AbstractBuild failureBuild = createBuild(Result.FAILURE, 41, "Changes for a failed build.");

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

Expand All @@ -76,9 +76,8 @@ public void testGetContent_whenReverseOrderIsTrueShouldReverseOrderOfChanges()

AbstractBuild failureBuild = createBuild(Result.FAILURE, 41, "Changes for a failed build.");

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

String contentStr = content.evaluate(currentBuild, listener, ChangesSinceLastSuccessfulBuildMacro.MACRO_NAME);

Expand All @@ -91,11 +90,10 @@ public void testGetContent_shouldGetPreviousBuildsThatArentSuccessful_HUDSON3519
throws Exception {
// Test for HUDSON-3519

AbstractBuild successfulBuild = createBuild(Result.SUCCESS, 2, "Changes for a successful build.");
AbstractBuild successfulBuild = createBuild2(Result.SUCCESS, 2, "Changes for a successful build.");

AbstractBuild unstableBuild = createBuild(Result.UNSTABLE, 3, "Changes for an unstable build.");
when(unstableBuild.getPreviousBuild()).thenReturn(successfulBuild);
when(successfulBuild.getNextBuild()).thenReturn(unstableBuild);

AbstractBuild abortedBuild = createBuild(Result.ABORTED, 4, "Changes for an aborted build.");
when(abortedBuild.getPreviousBuild()).thenReturn(unstableBuild);
Expand All @@ -109,7 +107,7 @@ public void testGetContent_shouldGetPreviousBuildsThatArentSuccessful_HUDSON3519
when(notBuiltBuild.getPreviousBuild()).thenReturn(failureBuild);
when(failureBuild.getNextBuild()).thenReturn(notBuiltBuild);

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

Expand Down Expand Up @@ -144,7 +142,7 @@ public void testShouldPrintDate()

AbstractBuild failureBuild = createBuild(Result.FAILURE, 41, "Changes for a failed build.");

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

Expand All @@ -162,7 +160,7 @@ public void testShouldPrintRevision()
content.changesFormat = "%r";

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

Expand All @@ -177,7 +175,7 @@ public void testShouldPrintPath()
content.changesFormat = "%p";

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

Expand All @@ -193,7 +191,7 @@ public void testWhenShowPathsIsTrueShouldPrintPath()

AbstractBuild failureBuild = createBuild(Result.FAILURE, 41, "Changes for a failed build.");

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

Expand All @@ -213,7 +211,7 @@ public void testRegexReplace()

AbstractBuild failureBuild = createBuild(Result.FAILURE, 41, "<defectId>DEFECT-666</defectId><message>Changes for a failed build.</message>");

AbstractBuild currentBuild = createBuild(Result.SUCCESS, 42, "<defectId>DEFECT-666</defectId><message>Changes for a successful build.</message>");
AbstractBuild currentBuild = createBuild3(Result.SUCCESS, 42, "<defectId>DEFECT-666</defectId><message>Changes for a successful build.</message>");
when(currentBuild.getPreviousBuild()).thenReturn(failureBuild);
when(failureBuild.getNextBuild()).thenReturn(currentBuild);

Expand Down Expand Up @@ -336,17 +334,14 @@ public void testShouldEscapeHtmlWhenArgumentEscapeHtmlSetToTrue()

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;
}

private AbstractBuild createBuildWithNoChangeSets(Result result, int buildNumber) {
AbstractBuild build = mock(AbstractBuild.class);
when(build.getResult()).thenReturn(result);
when(build.getChangeSets()).thenReturn(Collections.EMPTY_LIST);
when(build.getNumber()).thenReturn(buildNumber);

Expand All @@ -357,7 +352,6 @@ 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);

Expand All @@ -367,7 +361,6 @@ private AbstractBuild createBuild(Result result, int buildNumber, String message
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 @@ -429,4 +422,27 @@ public long getTimestamp() {
return 1382409540000L;
}
}

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;
}

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

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