better assert messages on unit test fail

This commit is contained in:
Samuel Carlsson 2022-02-08 20:01:43 +01:00 committed by Samuel Carlsson
parent 081154ee1e
commit fd1a833e6d

View File

@ -186,10 +186,18 @@ public class FakeAdbServer implements AdbResponder {
} }
public void verifyExpectations() { public void verifyExpectations() {
org.junit.Assert.assertEquals(0, fileExpectations.size()); for (FileExpectation expectation : fileExpectations) {
org.junit.Assert.assertEquals(0, shellExpectations.size()); org.junit.Assert.fail(expectation.toString());
org.junit.Assert.assertEquals(0, listExpectations.size()); }
org.junit.Assert.assertEquals(0, tcpipExpectations.size()); for (ShellExpectation expectation : shellExpectations) {
org.junit.Assert.fail(expectation.toString());
}
for (ListExpectation expectation : listExpectations) {
org.junit.Assert.fail(expectation.toString());
}
for (int expectation : tcpipExpectations) {
org.junit.Assert.fail("Expected tcp/ip on" + expectation);
}
} }
private static class FileExpectation implements ExpectationBuilder { private static class FileExpectation implements ExpectationBuilder {
@ -233,6 +241,11 @@ public class FakeAdbServer implements AdbResponder {
public void returnFile(ByteArrayOutputStream buffer) throws IOException { public void returnFile(ByteArrayOutputStream buffer) throws IOException {
buffer.write(content); buffer.write(content);
} }
@Override
public String toString() {
return "Expected file " + path;
}
} }
public static class ShellExpectation { public static class ShellExpectation {
@ -254,6 +267,11 @@ public class FakeAdbServer implements AdbResponder {
public void writeOutputTo(DataOutputStream stdout) throws IOException { public void writeOutputTo(DataOutputStream stdout) throws IOException {
stdout.write(this.stdout); stdout.write(this.stdout);
} }
@Override
public String toString() {
return "Expected shell " + command;
}
} }
public static class ListExpectation { public static class ListExpectation {
@ -282,6 +300,11 @@ public class FakeAdbServer implements AdbResponder {
public List<RemoteFile> getFiles() { public List<RemoteFile> getFiles() {
return Collections.unmodifiableList(files); return Collections.unmodifiableList(files);
} }
@Override
public String toString() {
return "Expected file list " + remotePath;
}
private static class MockFileEntry extends RemoteFile { private static class MockFileEntry extends RemoteFile {