Move tests to JUnit 5 wherever possible

This commit is contained in:
Andy Wilkinson
2019-05-24 11:24:29 +01:00
parent 36f56d034a
commit b18fffaf14
1320 changed files with 13424 additions and 14185 deletions

View File

@@ -21,7 +21,6 @@ import java.io.OutputStream;
import java.io.PrintStream;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Deque;
import java.util.List;
import java.util.function.Consumer;
@@ -143,11 +142,13 @@ class OutputCapture implements CapturedOutput {
*/
private static class SystemCapture {
private final Object monitor = new Object();
private final PrintStreamCapture out;
private final PrintStreamCapture err;
private final List<CapturedString> capturedStrings = Collections.synchronizedList(new ArrayList<>());
private final List<CapturedString> capturedStrings = new ArrayList<>();
SystemCapture() {
this.out = new PrintStreamCapture(System.out, this::captureOut);
@@ -162,23 +163,31 @@ class OutputCapture implements CapturedOutput {
}
private void captureOut(String string) {
this.capturedStrings.add(new CapturedString(Type.OUT, string));
synchronized (this.monitor) {
this.capturedStrings.add(new CapturedString(Type.OUT, string));
}
}
private void captureErr(String string) {
this.capturedStrings.add(new CapturedString(Type.ERR, string));
synchronized (this.monitor) {
this.capturedStrings.add(new CapturedString(Type.ERR, string));
}
}
public void append(StringBuilder builder, Predicate<Type> filter) {
for (CapturedString stringCapture : this.capturedStrings) {
if (filter.test(stringCapture.getType())) {
builder.append(stringCapture);
synchronized (this.monitor) {
for (CapturedString stringCapture : this.capturedStrings) {
if (filter.test(stringCapture.getType())) {
builder.append(stringCapture);
}
}
}
}
public void reset() {
this.capturedStrings.clear();
synchronized (this.monitor) {
this.capturedStrings.clear();
}
}
}

View File

@@ -36,7 +36,7 @@ import static org.hamcrest.Matchers.allOf;
*/
public class OutputCaptureRule implements TestRule {
private final org.springframework.boot.test.system.OutputCapture delegate = new org.springframework.boot.test.system.OutputCapture();
private final OutputCapture delegate = new OutputCapture();
private List<Matcher<? super String>> matchers = new ArrayList<>();