Skip to content

Commit

Permalink
[JENKINS-51584] Improve unit test to show allocation trace.
Browse files Browse the repository at this point in the history
improve the unit test to show the allocation trace on failure.
  • Loading branch information
jtnord committed May 30, 2018
1 parent 5b6acd7 commit c4215dc
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions test/src/test/java/jenkins/model/TransientActionFactoryTest.java
Expand Up @@ -35,7 +35,8 @@
import hudson.model.ProminentProjectAction;
import hudson.model.queue.FoldableAction;

import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
Expand All @@ -50,7 +51,9 @@

import javax.annotation.Nonnull;

import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.*;

public class TransientActionFactoryTest {
Expand Down Expand Up @@ -163,7 +166,7 @@ public void transientActionsAreNotPersistedOnQueueItems() throws Exception {
FreeStyleProject p = r.createFreeStyleProject();
FreeStyleBuild build = r.buildAndAssertSuccess(p);
// MyProminentProjectAction is only added via the TransientActionFactory and should never be persisted.
assertThat(Util.filter(build.getActions(), MyProminentProjectAction.class), hasSize(0));
assertThat(Util.filter(build.getActions(), MyProminentProjectAction.class), is(empty()));
assertThat(Util.filter(build.getAllActions(), MyProminentProjectAction.class), hasSize(1));
}

Expand All @@ -182,6 +185,20 @@ public Collection<? extends Action> createFor(@Nonnull Actionable target) {
}
}

private static class MyProminentProjectAction extends InvisibleAction implements ProminentProjectAction {}
private static class MyProminentProjectAction extends InvisibleAction implements ProminentProjectAction {

private String allocation;

public MyProminentProjectAction() {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
new Exception("MyProminentProjectAction allocated at: ").printStackTrace(pw);
allocation = sw.toString();
}

public String toString() {
return allocation;
}
}

}

0 comments on commit c4215dc

Please sign in to comment.