Asserting no unexpected pushes where sent.

This commit is contained in:
Samuel Carlsson 2014-03-26 10:09:31 +01:00
parent ee239467d0
commit e93bdb1658
2 changed files with 8 additions and 3 deletions

View File

@ -31,6 +31,7 @@ public class MockedTestCases {
public void tearDown() throws Exception { public void tearDown() throws Exception {
connection.close(); connection.close();
server.stop(); server.stop();
server.verifyExpectations();
} }
@Test @Test

View File

@ -47,6 +47,10 @@ public class FakeAdbServer implements AdbResponder {
devices.add(new DeviceResponder(serial)); devices.add(new DeviceResponder(serial));
} }
public void verifyExpectations() {
org.junit.Assert.assertEquals(0, remoteFileExpectations.size());
}
private static class RemoteFileExpectation { private static class RemoteFileExpectation {
private final String serial; private final String serial;
@ -83,7 +87,7 @@ public class FakeAdbServer implements AdbResponder {
} }
} }
private List<RemoteFileExpectation> _remoteFileExpectations = new ArrayList<RemoteFileExpectation>(); private List<RemoteFileExpectation> remoteFileExpectations = new ArrayList<RemoteFileExpectation>();
public void expectPush(String serial, RemoteFile path, String contents){ public void expectPush(String serial, RemoteFile path, String contents){
expectPush(serial, path, contents.getBytes(Charset.forName("UTF-8"))); expectPush(serial, path, contents.getBytes(Charset.forName("UTF-8")));
@ -91,11 +95,11 @@ public class FakeAdbServer implements AdbResponder {
public void expectPush(String serial, RemoteFile path, byte[] contents) public void expectPush(String serial, RemoteFile path, byte[] contents)
{ {
_remoteFileExpectations.add(new RemoteFileExpectation(serial, path, contents)); remoteFileExpectations.add(new RemoteFileExpectation(serial, path, contents));
} }
private void filePushed(String serial, RemoteFile path, byte[] contents) { private void filePushed(String serial, RemoteFile path, byte[] contents) {
boolean removed = _remoteFileExpectations.remove(new RemoteFileExpectation(serial, path, contents)); boolean removed = remoteFileExpectations.remove(new RemoteFileExpectation(serial, path, contents));
if (!removed) throw new RuntimeException("Unexpected push to device " + serial + " at " + path.getPath()); if (!removed) throw new RuntimeException("Unexpected push to device " + serial + " at " + path.getPath());
} }