提交 c3af3bec 编写于 作者: J Jesse Glick

Making tests fail more meaningfully.

上级 f72bcaca
......@@ -61,7 +61,9 @@ public abstract class ConfidentialStore {
* Retrieves the currently active singleton instance of {@link ConfidentialStore}.
*/
public static @Nonnull ConfidentialStore get() {
if (TEST!=null) return TEST.get();
if (TEST != null) {
return TEST;
}
Jenkins j = Jenkins.getInstance();
if (j == null) {
......@@ -95,7 +97,7 @@ public abstract class ConfidentialStore {
/**
* Testing only. Used for testing {@link ConfidentialKey} without {@link Jenkins}
*/
/*package*/ static ThreadLocal<ConfidentialStore> TEST = null;
/*package*/ static ConfidentialStore TEST = null;
private static final Logger LOGGER = Logger.getLogger(ConfidentialStore.class.getName());
}
package hudson.model;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.*;
import java.io.ByteArrayOutputStream;
import hudson.console.AnnotatedLargeText;
import hudson.security.ACL;
import hudson.security.Permission;
import jenkins.security.ConfidentialStoreRule;
import org.acegisecurity.Authentication;
import static org.hamcrest.CoreMatchers.startsWith;
import org.junit.Rule;
import org.junit.Test;
/**
......@@ -15,6 +18,9 @@ import org.junit.Test;
*/
public class TaskActionTest {
@Rule
public ConfidentialStoreRule confidentialStoreRule = new ConfidentialStoreRule();
private static class MyTaskThread extends TaskThread {
MyTaskThread(TaskAction taskAction) {
super(taskAction, ListenerAndText.forMemory(taskAction));
......@@ -63,6 +69,6 @@ public class TaskActionTest {
}
ByteArrayOutputStream os = new ByteArrayOutputStream();
annotatedText.writeLogTo(0, os);
assertTrue(os.toString("UTF-8").startsWith("a linkCompleted"));
assertThat(os.toString("UTF-8"), startsWith("a linkCompleted"));
}
}
......@@ -14,16 +14,13 @@ public class ConfidentialStoreRule extends ExternalResource {
@Override
protected void before() throws Throwable {
tmp.create();
ConfidentialStore.TEST.set(new DefaultConfidentialStore(tmp.getRoot()));
ConfidentialStore.TEST = new DefaultConfidentialStore(tmp.getRoot());
}
@Override
protected void after() {
ConfidentialStore.TEST.set(null);
ConfidentialStore.TEST = null;
tmp.delete();
}
static {
ConfidentialStore.TEST = new ThreadLocal<ConfidentialStore>();
}
}
......@@ -27,6 +27,7 @@ import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.Future;
import static org.hamcrest.Matchers.containsString;
import static org.junit.Assert.*;
import org.junit.Rule;
import org.junit.Test;
......@@ -117,8 +118,7 @@ public class ConsoleAnnotatorTest {
// make sure raw console output doesn't include the garbage
TextPage raw = (TextPage)r.createWebClient().goTo(b.getUrl()+"consoleText","text/plain");
System.out.println(raw.getContent());
assertTrue(raw.getContent().contains("\nabc\ndef\n"));
assertThat(raw.getContent(), containsString("\nabc\ndef\n"));
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册