From fd1a833e6d509b8057f80588a1031e1465037fa8 Mon Sep 17 00:00:00 2001 From: Samuel Carlsson Date: Tue, 8 Feb 2022 20:01:43 +0100 Subject: [PATCH] better assert messages on unit test fail --- .../jadb/test/fakes/FakeAdbServer.java | 31 ++++++++++++++++--- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/test/se/vidstige/jadb/test/fakes/FakeAdbServer.java b/test/se/vidstige/jadb/test/fakes/FakeAdbServer.java index 48fb444..1614090 100644 --- a/test/se/vidstige/jadb/test/fakes/FakeAdbServer.java +++ b/test/se/vidstige/jadb/test/fakes/FakeAdbServer.java @@ -186,10 +186,18 @@ public class FakeAdbServer implements AdbResponder { } public void verifyExpectations() { - org.junit.Assert.assertEquals(0, fileExpectations.size()); - org.junit.Assert.assertEquals(0, shellExpectations.size()); - org.junit.Assert.assertEquals(0, listExpectations.size()); - org.junit.Assert.assertEquals(0, tcpipExpectations.size()); + for (FileExpectation expectation : fileExpectations) { + org.junit.Assert.fail(expectation.toString()); + } + 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 { @@ -233,6 +241,11 @@ public class FakeAdbServer implements AdbResponder { public void returnFile(ByteArrayOutputStream buffer) throws IOException { buffer.write(content); } + + @Override + public String toString() { + return "Expected file " + path; + } } public static class ShellExpectation { @@ -254,6 +267,11 @@ public class FakeAdbServer implements AdbResponder { public void writeOutputTo(DataOutputStream stdout) throws IOException { stdout.write(this.stdout); } + + @Override + public String toString() { + return "Expected shell " + command; + } } public static class ListExpectation { @@ -282,6 +300,11 @@ public class FakeAdbServer implements AdbResponder { public List getFiles() { return Collections.unmodifiableList(files); } + + @Override + public String toString() { + return "Expected file list " + remotePath; + } private static class MockFileEntry extends RemoteFile {