mirror of
https://github.com/revanced/jadb.git
synced 2024-11-19 10:39:23 +01:00
Adding truly mocked test case.
This commit is contained in:
parent
fe5506023e
commit
88faded23d
@ -60,4 +60,8 @@ public class JadbConnection {
|
||||
public JadbDevice getAnyDevice() {
|
||||
return JadbDevice.createAny(main);
|
||||
}
|
||||
|
||||
public void close() throws IOException {
|
||||
main.close();
|
||||
}
|
||||
}
|
||||
|
@ -57,4 +57,9 @@ class Transport {
|
||||
verifyResponse();
|
||||
return new SyncTransport(outputStream, inputStream);
|
||||
}
|
||||
|
||||
public void close() throws IOException {
|
||||
inputStream.close();
|
||||
outputStream.close();
|
||||
}
|
||||
}
|
||||
|
@ -2,28 +2,34 @@ package se.vidstige.jadb.test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.*;
|
||||
|
||||
import se.vidstige.jadb.JadbDevice;
|
||||
import se.vidstige.jadb.JadbConnection;
|
||||
import se.vidstige.jadb.JadbException;
|
||||
import se.vidstige.jadb.test.fakes.AdbServer;
|
||||
|
||||
public class MockedTestCases {
|
||||
|
||||
@Test
|
||||
public void testGetState() throws Exception {
|
||||
JadbConnection jadb = new JadbConnection();
|
||||
List<JadbDevice> devices = jadb.getDevices();
|
||||
JadbDevice device = devices.get(0);
|
||||
device.getState();
|
||||
}
|
||||
|
||||
@Test(expected=JadbException.class)
|
||||
public void invalidShellCommand() throws Exception
|
||||
{
|
||||
JadbConnection jadb = new JadbConnection("localhost", 5037);
|
||||
List<JadbDevice> devices = jadb.getDevices();
|
||||
JadbDevice device = devices.get(0);
|
||||
device.executeShell("cmd", "foo", "bar");
|
||||
}
|
||||
private AdbServer server;
|
||||
private JadbConnection connection;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception{
|
||||
server = new AdbServer();
|
||||
server.start();
|
||||
connection = new JadbConnection("localhost", 15037);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
connection.close();
|
||||
server.stop();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testListDevices() throws Exception {
|
||||
List<JadbDevice> devices = connection.getDevices();
|
||||
Assert.assertEquals("X", devices.get(0).getSerial());
|
||||
}
|
||||
}
|
||||
|
@ -56,7 +56,10 @@ public class AdbServer implements Runnable {
|
||||
clientThread.start();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void stop() throws IOException {
|
||||
socket.close();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user