Updating for pull request changes:

* Renaming of main function
* Returning void instead of a boolean
This commit is contained in:
Daniel Llewellyn 2019-01-08 18:50:38 +00:00
parent 8c6b868341
commit d0f2d7ff59
3 changed files with 13 additions and 46 deletions

View File

@ -3,7 +3,6 @@ package se.vidstige.jadb;
import se.vidstige.jadb.managers.Bash;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
@ -146,8 +145,8 @@ public class JadbDevice {
*
* @return success or failure
*/
public boolean enableTcpip() throws IOException, JadbException {
return enableTcpip(DEFAULT_TCPIP_PORT);
public void enableAdbOverTCP() throws IOException, JadbException {
enableAdbOverTCP(DEFAULT_TCPIP_PORT);
}
/**
@ -157,11 +156,9 @@ public class JadbDevice {
*
* @return success or failure
*/
public boolean enableTcpip(int port) throws IOException, JadbException {
public void enableAdbOverTCP(int port) throws IOException, JadbException {
try (Transport transport = getTransport()) {
send(transport, String.format("tcpip:%d", port));
String expectedResult = String.format("restarting in TCP Mode: %d\n", port);
return transport.readString(expectedResult.length()).equals(expectedResult);
}
}

View File

@ -87,8 +87,8 @@ public class FakeAdbServer implements AdbResponder {
return findBySerial(serial).expectShell(commands);
}
public DeviceResponder.TcpIpException expectTcpip(String serial, String port) {
return findBySerial(serial).expectTcpip(port);
public void expectTcpip(String serial, Integer port) {
findBySerial(serial).expectTcpip(port);
}
public DeviceResponder.ListExpectation expectList(String serial, String remotePath) {
@ -106,7 +106,7 @@ public class FakeAdbServer implements AdbResponder {
private List<FileExpectation> fileExpectations = new ArrayList<>();
private List<ShellExpectation> shellExpectations = new ArrayList<>();
private List<ListExpectation> listExpectations = new ArrayList<>();
private List<TcpIpException> tcpipExpectations = new ArrayList<>();
private List<Integer> tcpipExpectations = new ArrayList<>();
private DeviceResponder(String serial, String type) {
this.serial = serial;
@ -163,11 +163,9 @@ public class FakeAdbServer implements AdbResponder {
@Override
public void enableIpCommand(String port, DataOutputStream outputStream) throws IOException {
for (TcpIpException expectation : tcpipExpectations) {
if (expectation.matches(port)) {
for (Integer expectation : tcpipExpectations) {
if (expectation == Integer.parseInt(port)) {
tcpipExpectations.remove(expectation);
outputStream.write(String.format("restarting in TCP Mode: %s\n", port).getBytes(StandardCharsets.UTF_8));
outputStream.flush();
return;
}
}
@ -191,34 +189,9 @@ public class FakeAdbServer implements AdbResponder {
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());
}
private static class TcpIpException implements ExpectationBuilder {
private String port;
public TcpIpException(final String port) {
this.port = port;
}
public boolean matches(String cmd) {
return cmd.equals(port);
}
@Override
public void failWith(String message) {
}
@Override
public void withContent(byte[] content) {
}
@Override
public void withContent(String content) {
}
}
private static class FileExpectation implements ExpectationBuilder {
private final RemoteFile path;
private byte[] content;
@ -363,10 +336,8 @@ public class FakeAdbServer implements AdbResponder {
return expectation;
}
public TcpIpException expectTcpip(String port) {
TcpIpException expectation = new TcpIpException(port);
tcpipExpectations.add(expectation);
return expectation;
public void expectTcpip(int port) {
tcpipExpectations.add(port);
}
}
}

View File

@ -17,7 +17,6 @@ import java.nio.charset.StandardCharsets;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.List;
public class MockedTestCases {
@ -108,9 +107,9 @@ public class MockedTestCases {
@Test
public void testExecuteEnableTcpip() throws IOException, JadbException {
server.add("serial-123");
server.expectTcpip("serial-123", "5555");
server.expectTcpip("serial-123", 5555);
JadbDevice device = connection.getDevices().get(0);
device.enableTcpip();
device.enableAdbOverTCP();
}
@Test