Skip to content
This repository has been archived by the owner on Nov 19, 2024. It is now read-only.

Avoid calling TransientActionFactory from mock tests #244

Merged
merged 1 commit into from
Jun 16, 2023
Merged
Show file tree
Hide file tree
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
@@ -1,5 +1,6 @@
package hudson.plugins.jacococoveragecolumn;

import hudson.model.Action;
import hudson.model.BuildListener;
import hudson.model.Descriptor.FormException;
import hudson.model.Job;
Expand Down Expand Up @@ -73,14 +74,15 @@ public void testGetPercentWithBuildAndAction() {
EasyMock.replay(context);

final Job<?, ?> mockJob = new MyJob("externaljob") {
@SuppressWarnings("deprecation") // avoid TransientActionFactory
@Override
@Exported
@QuickSilver
public MyRun getLastSuccessfulBuild() {
try {
MyRun newBuild = newBuild();
newBuild.addAction(new JacocoBuildAction(null, null, StreamTaskListener.fromStdout(), null, null));
assertEquals(1, newBuild.getAllActions().size());
assertEquals(1, newBuild.getActions().size());
return newBuild;
} catch (IOException e) {
throw new IllegalStateException(e);
Expand Down Expand Up @@ -250,5 +252,16 @@ private class MyRun extends Run<MyJob,MyRun> {
public MyRun(MyJob job) throws IOException {
super(job);
}

@SuppressWarnings("deprecation") // avoid TransientActionFactory
@Override
public <T extends Action> T getAction(Class<T> type) {
for (Action a : getActions()) {
if (type.isInstance(a)) {
return type.cast(a);
}
}
return null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public void testGetPercentWithBuildAndAction() {
EasyMock.replay(context);

final Job<?, ?> mockJob = new MyJob("externaljob") {
@SuppressWarnings("deprecation") // avoid TransientActionFactory
@Override
@Exported
@QuickSilver
Expand All @@ -49,7 +50,7 @@ public MyRun getLastSuccessfulBuild() {
Map<CoverageElement.Type, Coverage> ratios = new HashMap<>();
ratios.put(Type.BRANCH, new Coverage(100, 200));
newBuild.addAction(new JacocoBuildAction(ratios, null, StreamTaskListener.fromStdout(), null, null));
assertEquals(1, newBuild.getAllActions().size());
assertEquals(1, newBuild.getActions().size());
return newBuild;
} catch (IOException e) {
throw new IllegalStateException(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,14 @@ public void testGetPercentWithBuildAndAction() {
@Override
@Exported
@QuickSilver
@SuppressWarnings("deprecation") // avoid TransientActionFactory
public MyRun getLastSuccessfulBuild() {
try {
MyRun newBuild = newBuild();
Map<Type, Coverage> ratios = new HashMap<>();
ratios.put(Type.LINE, new Coverage(200, 100));
newBuild.addAction(new JacocoBuildAction(ratios, null, StreamTaskListener.fromStdout(), null, null));
assertEquals(1, newBuild.getAllActions().size());
assertEquals(1, newBuild.getActions().size());
return newBuild;
} catch (IOException e) {
throw new IllegalStateException(e);
Expand Down