我在使用以下代码时遇到问题,我有点困惑
public class EchoApp {
public static void main(String[] args) {
for (String string : args) {
System.out.println(string);
}
}
}
以下测试失败:
import static org.hamcrest.CoreMatchers.equalTo;
import static org.mockito.Mockito.*;
import java.io.PrintStream;
import org.junit.Test;
public class AppTest {
@Test
public void test() {
Input input = new Input("Hello!", "World!");
Output output = new Output("Hello!", "World!");
PrintStream out = mock(PrintStream.class);
System.setOut(out);
EchoApp.main(input.wrap());
output.value.forEach(i -> {
verify(out).println(equalTo(i));
});
}
}
import java.util.Arrays;
import java.util.List;
class Input extends Immutable<List<String>> {
Input(final List<String> values) {
super(values);
}
Input(String... values) {
super(Arrays.asList(values));
}
String[] wrap() {
return value.toArray(new String[value.size()]);
}
@Override
public String toString() {
return "Input [value=" + value + "]";
}
}
import java.util.Arrays;
import java.util.List;
class Output extends Immutable<List<String>> {
Output(List<String> values) {
super(values);
}
Output(String... values) {
super(Arrays.asList(values));
}
@Override
public String toString() {
return "Output [value=" + value + "]";
}
}
class Immutable<T> {
final T value;
Immutable(T value) {
this.value = value;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((value == null) ? 0 : value.hashCode());
return result;
}
参数不同!通缉:printStream.println("你好!"); -> 在 AppTest.lambda$0(AppTest.java:24) 实际调用有不同的参数: printStream.println("Hello!"); -> 在 EchoApp.main(EchoApp.java:7)
人到中年有点甜
相关分类