mirror of
https://github.com/revanced/jadb.git
synced 2025-02-05 23:16:47 +01:00
add unit test for getState
This commit is contained in:
parent
4486bd0a7a
commit
86ccd4ab42
@ -86,6 +86,31 @@ class AdbProtocolHandler implements Runnable {
|
||||
shell(shellCommand, output, input);
|
||||
output.close();
|
||||
return;
|
||||
} else if ("host:get-state".equals(command)) {
|
||||
// TODO: Check so that exactly one device is selected.
|
||||
AdbDeviceResponder device = responder.getDevices().get(0);
|
||||
output.writeBytes("OKAY");
|
||||
send(output, device.getType());
|
||||
} else if (command.startsWith("host-serial:")) {
|
||||
String[] strs = command.split(":",0);
|
||||
if (strs.length != 3) {
|
||||
throw new ProtocolException("Invalid command: " + command);
|
||||
}
|
||||
|
||||
String serial = strs[1];
|
||||
boolean found = false;
|
||||
output.writeBytes("OKAY");
|
||||
for (AdbDeviceResponder d : responder.getDevices()) {
|
||||
if (d.getSerial().equals(serial)) {
|
||||
send(output, d.getType());
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!found) {
|
||||
send(output, "unknown");
|
||||
}
|
||||
} else {
|
||||
throw new ProtocolException("Unknown command: " + command);
|
||||
}
|
||||
@ -146,4 +171,4 @@ class AdbProtocolHandler implements Runnable {
|
||||
writer.writeBytes(getCommandLength(response));
|
||||
writer.writeBytes(response);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -47,7 +47,11 @@ public class FakeAdbServer implements AdbResponder {
|
||||
}
|
||||
|
||||
public void add(String serial) {
|
||||
devices.add(new DeviceResponder(serial));
|
||||
devices.add(new DeviceResponder(serial, "device"));
|
||||
}
|
||||
|
||||
public void add(String serial, String type) {
|
||||
devices.add(new DeviceResponder(serial, type));
|
||||
}
|
||||
|
||||
public void verifyExpectations() {
|
||||
@ -89,11 +93,13 @@ public class FakeAdbServer implements AdbResponder {
|
||||
|
||||
private class DeviceResponder implements AdbDeviceResponder {
|
||||
private final String serial;
|
||||
private final String type;
|
||||
private List<FileExpectation> fileExpectations = new ArrayList<FileExpectation>();
|
||||
private List<ShellExpectation> shellExpectations = new ArrayList<ShellExpectation>();
|
||||
|
||||
private DeviceResponder(String serial) {
|
||||
private DeviceResponder(String serial, String type) {
|
||||
this.serial = serial;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -103,7 +109,7 @@ public class FakeAdbServer implements AdbResponder {
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return "device";
|
||||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -45,6 +45,19 @@ public class MockedTestCases {
|
||||
Assert.assertEquals("serial-123", devices.get(0).getSerial());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetDeviceState() throws Exception {
|
||||
server.add("serial-1", "offline");
|
||||
server.add("serial-2", "device");
|
||||
server.add("serial-3", "unknown");
|
||||
server.add("serial-4", "foobar");
|
||||
List<JadbDevice> devices = connection.getDevices();
|
||||
Assert.assertEquals(JadbDevice.State.Offline, devices.get(0).getState());
|
||||
Assert.assertEquals(JadbDevice.State.Device, devices.get(1).getState());
|
||||
Assert.assertEquals(JadbDevice.State.Unknown, devices.get(2).getState());
|
||||
Assert.assertEquals(JadbDevice.State.Unknown, devices.get(3).getState());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListNoDevices() throws Exception {
|
||||
List<JadbDevice> devices = connection.getDevices();
|
||||
|
Loading…
x
Reference in New Issue
Block a user