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

Commit

Permalink
Avoid calling TransientActionFactory from mock tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jglick authored and centic9 committed Jun 16, 2023
1 parent 101ff30 commit b0d072d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
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

0 comments on commit b0d072d

Please sign in to comment.