Skip to content
Permalink
Browse files

[JENKINS-51584] Improve unit test to show allocation trace.

improve the unit test to show the allocation trace on failure.
  • Loading branch information...
jtnord committed May 30, 2018
1 parent 5b6acd7 commit c4215dc6ad5f974c740bed925aaba655b27e453a
Showing with 20 additions and 3 deletions.
  1. +20 −3 test/src/test/java/jenkins/model/TransientActionFactoryTest.java
@@ -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;
@@ -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 {
@@ -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));
}

@@ -182,6 +185,20 @@ public void transientActionsAreNotPersistedOnQueueItems() throws Exception {
}
}

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.
You can’t perform that action at this time.