#58 fixes in spaces and newline at the end of new files. Fixed typo in test

This commit is contained in:
Art 2017-03-20 14:48:09 +03:00
parent 0a12f784ca
commit 64544b5bff
3 changed files with 15 additions and 15 deletions

View File

@ -51,22 +51,22 @@ class HostConnectToRemoteTcpDevice {
}
public void validate(String response) throws ConnectionToRemoteDeviceException {
if(!checkIfConnectedSuccessfully(response) && !checkIfAlreadyConnected(response)) {
if (!checkIfConnectedSuccessfully(response) && !checkIfAlreadyConnected(response)) {
throw new ConnectionToRemoteDeviceException(extractError(response));
}
}
private boolean checkIfConnectedSuccessfully(String response) {
private boolean checkIfConnectedSuccessfully(String response) {
return response.startsWith(SUCCESSFULLY_CONNECTED);
}
private boolean checkIfAlreadyConnected(String response) {
private boolean checkIfAlreadyConnected(String response) {
return response.startsWith(ALREADY_CONNECTED);
}
private String extractError(String response) {
int lastColon = response.lastIndexOf(":");
if(lastColon != -1) {
if (lastColon != -1) {
return response.substring(lastColon, response.length());
} else {
return response;

View File

@ -8,7 +8,7 @@ public class HostDisconnectFromRemoteTcpDevice {
private final Transport transport;
private final ResponseValidator responseValidator;
public HostDisconnectFromRemoteTcpDevice(Transport transport) {
HostDisconnectFromRemoteTcpDevice(Transport transport) {
this.transport = transport;
this.responseValidator = new ResponseValidatorImp();
}
@ -19,7 +19,7 @@ public class HostDisconnectFromRemoteTcpDevice {
this.responseValidator = responseValidator;
}
public TcpAddressEntity disconnect(TcpAddressEntity tcpAddressEntity)
TcpAddressEntity disconnect(TcpAddressEntity tcpAddressEntity)
throws IOException, JadbException, ConnectionToRemoteDeviceException {
transport.send(String.format("host:disconnect:%s:%d", tcpAddressEntity.getHost(), tcpAddressEntity.getPort()));
verifyTransportLevel();
@ -47,26 +47,26 @@ public class HostDisconnectFromRemoteTcpDevice {
private final static String ALREADY_DISCONNECTED = "error: no such device";
public ResponseValidatorImp() {
ResponseValidatorImp() {
}
public void validate(String response) throws ConnectionToRemoteDeviceException {
if(!checkIfConnectedSuccessfully(response) && !checkIfAlreadyConnected(response)) {
if (!checkIfConnectedSuccessfully(response) && !checkIfAlreadyConnected(response)) {
throw new ConnectionToRemoteDeviceException(extractError(response));
}
}
private boolean checkIfConnectedSuccessfully(String response) {
private boolean checkIfConnectedSuccessfully(String response) {
return response.startsWith(SUCCESSFULLY_DISCONNECTED);
}
private boolean checkIfAlreadyConnected(String response) {
private boolean checkIfAlreadyConnected(String response) {
return response.startsWith(ALREADY_DISCONNECTED);
}
private String extractError(String response) {
int lastColon = response.lastIndexOf(":");
if(lastColon != -1) {
if (lastColon != -1) {
return response.substring(lastColon, response.length());
} else {
return response;

View File

@ -47,19 +47,19 @@ public class HostDisconnectFromRemoteTcpDeviceTest {
//Prepare
Transport transport = mock(Transport.class);
when(transport.readString()).thenReturn("any string");
HostConnectToRemoteTcpDevice.ResponseValidator responseValidator = mock(HostConnectToRemoteTcpDevice.ResponseValidator.class);
HostDisconnectFromRemoteTcpDevice.ResponseValidator responseValidator = mock(HostDisconnectFromRemoteTcpDevice.ResponseValidator.class);
doThrow(new ConnectionToRemoteDeviceException("Fake exception")).when(responseValidator).validate(anyString());
TcpAddressEntity tcpAddressEntity = new TcpAddressEntity("host", 1);
//Do
HostDisconnectFromRemoteTcpDevice hostConnectToRemoteTcpDevice = new HostDisconnectFromRemoteTcpDevice(transport);
HostDisconnectFromRemoteTcpDevice hostConnectToRemoteTcpDevice = new HostDisconnectFromRemoteTcpDevice(transport, responseValidator);
hostConnectToRemoteTcpDevice.disconnect(tcpAddressEntity);
}
@Test
public void testProtocolResponseValidatorSuccessfullyConnected() throws ConnectionToRemoteDeviceException, IOException, JadbException {
new HostDisconnectFromRemoteTcpDevice.ResponseValidatorImp().validate("disconnected 127.0.0.1:10001");
new HostDisconnectFromRemoteTcpDevice.ResponseValidatorImp().validate("disconnected 127.0.0.1:10001");
}
@Test
@ -71,4 +71,4 @@ public class HostDisconnectFromRemoteTcpDeviceTest {
public void testProtocolResponseValidatorErrorInValidate() throws ConnectionToRemoteDeviceException, IOException, JadbException {
new HostDisconnectFromRemoteTcpDevice.ResponseValidatorImp().validate("some error occurred");
}
}
}