Adding truly mocked test case.

This commit is contained in:
Samuel Carlsson 2014-03-20 10:31:13 +01:00
parent fe5506023e
commit 88faded23d
4 changed files with 36 additions and 18 deletions

View File

@ -60,4 +60,8 @@ public class JadbConnection {
public JadbDevice getAnyDevice() {
return JadbDevice.createAny(main);
}
public void close() throws IOException {
main.close();
}
}

View File

@ -57,4 +57,9 @@ class Transport {
verifyResponse();
return new SyncTransport(outputStream, inputStream);
}
public void close() throws IOException {
inputStream.close();
outputStream.close();
}
}

View File

@ -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());
}
}

View File

@ -56,7 +56,10 @@ public class AdbServer implements Runnable {
clientThread.start();
}
} catch (IOException e) {
e.printStackTrace();
}
}
public void stop() throws IOException {
socket.close();
}
}