mirror of
https://github.com/revanced/jadb.git
synced 2025-05-08 10:24:30 +02:00
#58 fixes in tests
This commit is contained in:
parent
4442663889
commit
b4fa17abff
@ -1,14 +1,18 @@
|
|||||||
package se.vidstige.jadb;
|
package se.vidstige.jadb;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.mockito.ArgumentCaptor;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
import static org.mockito.ArgumentCaptor.forClass;
|
||||||
import static org.mockito.ArgumentMatchers.anyString;
|
import static org.mockito.ArgumentMatchers.anyString;
|
||||||
import static org.mockito.Mockito.doThrow;
|
import static org.mockito.Mockito.doThrow;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.times;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
public class HostConnectToRemoteTcpDeviceTest {
|
public class HostConnectToRemoteTcpDeviceTest {
|
||||||
@ -17,9 +21,9 @@ public class HostConnectToRemoteTcpDeviceTest {
|
|||||||
public void testNormalConnection() throws ConnectionToRemoteDeviceException, IOException, JadbException {
|
public void testNormalConnection() throws ConnectionToRemoteDeviceException, IOException, JadbException {
|
||||||
//Prepare
|
//Prepare
|
||||||
Transport transport = mock(Transport.class);
|
Transport transport = mock(Transport.class);
|
||||||
when(transport.readString()).thenReturn("connected to host:1");
|
when(transport.readString()).thenReturn("connected to somehost:1");
|
||||||
|
|
||||||
InetSocketAddress inetSocketAddress = new InetSocketAddress("host", 1);
|
InetSocketAddress inetSocketAddress = new InetSocketAddress("somehost", 1);
|
||||||
|
|
||||||
//Do
|
//Do
|
||||||
HostConnectToRemoteTcpDevice hostConnectToRemoteTcpDevice = new HostConnectToRemoteTcpDevice(transport);
|
HostConnectToRemoteTcpDevice hostConnectToRemoteTcpDevice = new HostConnectToRemoteTcpDevice(transport);
|
||||||
@ -27,6 +31,10 @@ public class HostConnectToRemoteTcpDeviceTest {
|
|||||||
|
|
||||||
//Validate
|
//Validate
|
||||||
assertEquals(resultTcpAddressEntity, inetSocketAddress);
|
assertEquals(resultTcpAddressEntity, inetSocketAddress);
|
||||||
|
|
||||||
|
ArgumentCaptor<String> argument = forClass(String.class);
|
||||||
|
verify(transport, times(1)).send(argument.capture());
|
||||||
|
assertEquals("host:connect:somehost:1", argument.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = JadbException.class)
|
@Test(expected = JadbException.class)
|
||||||
@ -35,36 +43,45 @@ public class HostConnectToRemoteTcpDeviceTest {
|
|||||||
Transport transport = mock(Transport.class);
|
Transport transport = mock(Transport.class);
|
||||||
doThrow(new JadbException("Fake exception")).when(transport).verifyResponse();
|
doThrow(new JadbException("Fake exception")).when(transport).verifyResponse();
|
||||||
|
|
||||||
InetSocketAddress tcpAddressEntity = new InetSocketAddress("host", 1);
|
InetSocketAddress tcpAddressEntity = new InetSocketAddress("somehost", 1);
|
||||||
|
|
||||||
//Do
|
//Do
|
||||||
HostConnectToRemoteTcpDevice hostConnectToRemoteTcpDevice = new HostConnectToRemoteTcpDevice(transport);
|
HostConnectToRemoteTcpDevice hostConnectToRemoteTcpDevice = new HostConnectToRemoteTcpDevice(transport);
|
||||||
hostConnectToRemoteTcpDevice.connect(tcpAddressEntity);
|
hostConnectToRemoteTcpDevice.connect(tcpAddressEntity);
|
||||||
|
|
||||||
|
//Validate
|
||||||
|
verify(transport, times(1)).send(anyString());
|
||||||
|
verify(transport, times(1)).verifyResponse();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = ConnectionToRemoteDeviceException.class)
|
@Test(expected = ConnectionToRemoteDeviceException.class)
|
||||||
public void testProtocolException() throws ConnectionToRemoteDeviceException, IOException, JadbException {
|
public void testProtocolException() throws ConnectionToRemoteDeviceException, IOException, JadbException {
|
||||||
//Prepare
|
//Prepare
|
||||||
Transport transport = mock(Transport.class);
|
Transport transport = mock(Transport.class);
|
||||||
when(transport.readString()).thenReturn("connected to host:1");
|
when(transport.readString()).thenReturn("connected to somehost:1");
|
||||||
HostConnectToRemoteTcpDevice.ResponseValidator responseValidator = mock(HostConnectToRemoteTcpDevice.ResponseValidator.class);
|
HostConnectToRemoteTcpDevice.ResponseValidator responseValidator = mock(HostConnectToRemoteTcpDevice.ResponseValidator.class);
|
||||||
doThrow(new ConnectionToRemoteDeviceException("Fake exception")).when(responseValidator).validate(anyString());
|
doThrow(new ConnectionToRemoteDeviceException("Fake exception")).when(responseValidator).validate(anyString());
|
||||||
|
|
||||||
InetSocketAddress tcpAddressEntity = new InetSocketAddress("host", 1);
|
InetSocketAddress tcpAddressEntity = new InetSocketAddress("somehost", 1);
|
||||||
|
|
||||||
//Do
|
//Do
|
||||||
HostConnectToRemoteTcpDevice hostConnectToRemoteTcpDevice = new HostConnectToRemoteTcpDevice(transport, responseValidator);
|
HostConnectToRemoteTcpDevice hostConnectToRemoteTcpDevice = new HostConnectToRemoteTcpDevice(transport, responseValidator);
|
||||||
hostConnectToRemoteTcpDevice.connect(tcpAddressEntity);
|
hostConnectToRemoteTcpDevice.connect(tcpAddressEntity);
|
||||||
|
|
||||||
|
//Validate
|
||||||
|
verify(transport, times(1)).send(anyString());
|
||||||
|
verify(transport, times(1)).verifyResponse();
|
||||||
|
verify(responseValidator, times(1)).validate(anyString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testProtocolResponseValidatorSuccessfullyConnected() throws ConnectionToRemoteDeviceException, IOException, JadbException {
|
public void testProtocolResponseValidatorSuccessfullyConnected() throws ConnectionToRemoteDeviceException, IOException, JadbException {
|
||||||
new HostConnectToRemoteTcpDevice.ResponseValidatorImp().validate("connected to host:1");
|
new HostConnectToRemoteTcpDevice.ResponseValidatorImp().validate("connected to somehost:1");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testProtocolResponseValidatorAlreadyConnected() throws ConnectionToRemoteDeviceException, IOException, JadbException {
|
public void testProtocolResponseValidatorAlreadyConnected() throws ConnectionToRemoteDeviceException, IOException, JadbException {
|
||||||
new HostConnectToRemoteTcpDevice.ResponseValidatorImp().validate("already connected to host:1");
|
new HostConnectToRemoteTcpDevice.ResponseValidatorImp().validate("already connected to somehost:1");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = ConnectionToRemoteDeviceException.class)
|
@Test(expected = ConnectionToRemoteDeviceException.class)
|
||||||
|
@ -20,7 +20,7 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
public class FakeAdbServer implements AdbResponder {
|
public class FakeAdbServer implements AdbResponder {
|
||||||
private final AdbServer server;
|
private final AdbServer server;
|
||||||
private List<DeviceResponder> devices = new ArrayList<DeviceResponder>();
|
private final List<DeviceResponder> devices = new ArrayList<DeviceResponder>();
|
||||||
|
|
||||||
public FakeAdbServer(int port) {
|
public FakeAdbServer(int port) {
|
||||||
server = new AdbServer(this, port);
|
server = new AdbServer(this, port);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user