#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 { public void validate(String response) throws ConnectionToRemoteDeviceException {
if(!checkIfConnectedSuccessfully(response) && !checkIfAlreadyConnected(response)) { if (!checkIfConnectedSuccessfully(response) && !checkIfAlreadyConnected(response)) {
throw new ConnectionToRemoteDeviceException(extractError(response)); throw new ConnectionToRemoteDeviceException(extractError(response));
} }
} }
private boolean checkIfConnectedSuccessfully(String response) { private boolean checkIfConnectedSuccessfully(String response) {
return response.startsWith(SUCCESSFULLY_CONNECTED); return response.startsWith(SUCCESSFULLY_CONNECTED);
} }
private boolean checkIfAlreadyConnected(String response) { private boolean checkIfAlreadyConnected(String response) {
return response.startsWith(ALREADY_CONNECTED); return response.startsWith(ALREADY_CONNECTED);
} }
private String extractError(String response) { private String extractError(String response) {
int lastColon = response.lastIndexOf(":"); int lastColon = response.lastIndexOf(":");
if(lastColon != -1) { if (lastColon != -1) {
return response.substring(lastColon, response.length()); return response.substring(lastColon, response.length());
} else { } else {
return response; return response;

View File

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

View File

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