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;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.ArgumentCaptor.forClass;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.Mockito.doThrow;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class HostConnectToRemoteTcpDeviceTest {
|
||||
@ -17,9 +21,9 @@ public class HostConnectToRemoteTcpDeviceTest {
|
||||
public void testNormalConnection() throws ConnectionToRemoteDeviceException, IOException, JadbException {
|
||||
//Prepare
|
||||
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
|
||||
HostConnectToRemoteTcpDevice hostConnectToRemoteTcpDevice = new HostConnectToRemoteTcpDevice(transport);
|
||||
@ -27,6 +31,10 @@ public class HostConnectToRemoteTcpDeviceTest {
|
||||
|
||||
//Validate
|
||||
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)
|
||||
@ -35,36 +43,45 @@ public class HostConnectToRemoteTcpDeviceTest {
|
||||
Transport transport = mock(Transport.class);
|
||||
doThrow(new JadbException("Fake exception")).when(transport).verifyResponse();
|
||||
|
||||
InetSocketAddress tcpAddressEntity = new InetSocketAddress("host", 1);
|
||||
InetSocketAddress tcpAddressEntity = new InetSocketAddress("somehost", 1);
|
||||
|
||||
//Do
|
||||
HostConnectToRemoteTcpDevice hostConnectToRemoteTcpDevice = new HostConnectToRemoteTcpDevice(transport);
|
||||
hostConnectToRemoteTcpDevice.connect(tcpAddressEntity);
|
||||
|
||||
//Validate
|
||||
verify(transport, times(1)).send(anyString());
|
||||
verify(transport, times(1)).verifyResponse();
|
||||
}
|
||||
|
||||
@Test(expected = ConnectionToRemoteDeviceException.class)
|
||||
public void testProtocolException() throws ConnectionToRemoteDeviceException, IOException, JadbException {
|
||||
//Prepare
|
||||
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);
|
||||
doThrow(new ConnectionToRemoteDeviceException("Fake exception")).when(responseValidator).validate(anyString());
|
||||
|
||||
InetSocketAddress tcpAddressEntity = new InetSocketAddress("host", 1);
|
||||
InetSocketAddress tcpAddressEntity = new InetSocketAddress("somehost", 1);
|
||||
|
||||
//Do
|
||||
HostConnectToRemoteTcpDevice hostConnectToRemoteTcpDevice = new HostConnectToRemoteTcpDevice(transport, responseValidator);
|
||||
hostConnectToRemoteTcpDevice.connect(tcpAddressEntity);
|
||||
|
||||
//Validate
|
||||
verify(transport, times(1)).send(anyString());
|
||||
verify(transport, times(1)).verifyResponse();
|
||||
verify(responseValidator, times(1)).validate(anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProtocolResponseValidatorSuccessfullyConnected() throws ConnectionToRemoteDeviceException, IOException, JadbException {
|
||||
new HostConnectToRemoteTcpDevice.ResponseValidatorImp().validate("connected to host:1");
|
||||
new HostConnectToRemoteTcpDevice.ResponseValidatorImp().validate("connected to somehost:1");
|
||||
}
|
||||
|
||||
@Test
|
||||
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)
|
||||
|
@ -20,7 +20,7 @@ import java.util.List;
|
||||
*/
|
||||
public class FakeAdbServer implements AdbResponder {
|
||||
private final AdbServer server;
|
||||
private List<DeviceResponder> devices = new ArrayList<DeviceResponder>();
|
||||
private final List<DeviceResponder> devices = new ArrayList<DeviceResponder>();
|
||||
|
||||
public FakeAdbServer(int port) {
|
||||
server = new AdbServer(this, port);
|
||||
|
Loading…
x
Reference in New Issue
Block a user