mirror of
https://github.com/revanced/jadb.git
synced 2024-11-19 10:39:23 +01:00
Now actually asserting that non expected pushes are not sent.
This commit is contained in:
parent
89403cb126
commit
ee239467d0
@ -16,4 +16,21 @@ public class RemoteFile {
|
||||
public boolean isDirectory() { throw new NotImplementedException(); }
|
||||
|
||||
public String getPath() { return path;}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
RemoteFile that = (RemoteFile) o;
|
||||
|
||||
if (!path.equals(that.path)) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return path.hashCode();
|
||||
}
|
||||
}
|
||||
|
@ -49,11 +49,13 @@ public class MockedTestCases {
|
||||
@Test
|
||||
public void testPushFile() throws Exception {
|
||||
server.add("serial-123");
|
||||
server.expectPush("serial-123", new RemoteFile("/remote/path/abc.txt"), "abc");
|
||||
JadbDevice device = connection.getDevices().get(0);
|
||||
ByteArrayInputStream fileContents = new ByteArrayInputStream("abc".getBytes());
|
||||
device.push(fileContents, parseDate("1981-08-25 13:37"), 0666, new RemoteFile("/remote/path/abc.txt"));
|
||||
}
|
||||
|
||||
|
||||
private long parseDate(String date) throws ParseException {
|
||||
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
|
||||
return dateFormat.parse(date).getTime();
|
||||
|
@ -1,12 +1,15 @@
|
||||
package se.vidstige.jadb.test.fakes;
|
||||
|
||||
import se.vidstige.jadb.RemoteFile;
|
||||
import se.vidstige.jadb.server.AdbDeviceResponder;
|
||||
import se.vidstige.jadb.server.AdbResponder;
|
||||
import se.vidstige.jadb.server.AdbServer;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@ -44,12 +47,65 @@ public class FakeAdbServer implements AdbResponder {
|
||||
devices.add(new DeviceResponder(serial));
|
||||
}
|
||||
|
||||
private static class RemoteFileExpectation {
|
||||
|
||||
private final String serial;
|
||||
private final RemoteFile path;
|
||||
private final byte[] contents;
|
||||
|
||||
public RemoteFileExpectation(String serial, RemoteFile path, byte[] contents) {
|
||||
|
||||
this.serial = serial;
|
||||
this.path = path;
|
||||
this.contents = contents;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
RemoteFileExpectation that = (RemoteFileExpectation) o;
|
||||
|
||||
if (!Arrays.equals(contents, that.contents)) return false;
|
||||
if (!path.equals(that.path)) return false;
|
||||
if (serial != null ? !serial.equals(that.serial) : that.serial != null) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = serial != null ? serial.hashCode() : 0;
|
||||
result = 31 * result + path.hashCode();
|
||||
result = 31 * result + Arrays.hashCode(contents);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
private List<RemoteFileExpectation> _remoteFileExpectations = new ArrayList<RemoteFileExpectation>();
|
||||
|
||||
public void expectPush(String serial, RemoteFile path, String contents){
|
||||
expectPush(serial, path, contents.getBytes(Charset.forName("UTF-8")));
|
||||
}
|
||||
|
||||
public void expectPush(String serial, RemoteFile path, byte[] contents)
|
||||
{
|
||||
_remoteFileExpectations.add(new RemoteFileExpectation(serial, path, contents));
|
||||
}
|
||||
|
||||
private void filePushed(String serial, RemoteFile path, byte[] contents) {
|
||||
boolean removed = _remoteFileExpectations.remove(new RemoteFileExpectation(serial, path, contents));
|
||||
if (!removed) throw new RuntimeException("Unexpected push to device " + serial + " at " + path.getPath());
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<AdbDeviceResponder> getDevices() {
|
||||
return devices;
|
||||
}
|
||||
|
||||
private static class DeviceResponder implements AdbDeviceResponder {
|
||||
private class DeviceResponder implements AdbDeviceResponder {
|
||||
private final String serial;
|
||||
|
||||
private DeviceResponder(String serial) {
|
||||
@ -68,7 +124,7 @@ public class FakeAdbServer implements AdbResponder {
|
||||
|
||||
@Override
|
||||
public void filePushed(String path, int mode, ByteArrayOutputStream buffer) {
|
||||
|
||||
FakeAdbServer.this.filePushed(serial, new RemoteFile(path), buffer.toByteArray());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user