vidstige/jadb#38 some more changes for PR

This commit is contained in:
Arthur 2016-10-03 15:41:08 +03:00
parent f4c44d6e3f
commit db5d9e13bc
2 changed files with 57 additions and 56 deletions

View File

@ -95,15 +95,6 @@ public class MockedTestCases {
device.executeShell("ls", "space file"); device.executeShell("ls", "space file");
} }
@Test
public void testGetProps() throws Exception {
server.add("serial-123");
server.expectShell("serial-123", "getprop").returns("[] = nope\nx\n(");
JadbDevice device = connection.getDevices().get(0);
Map<String, String> x = new PropertyManager(device).getprop();
Assert.assertEquals(0, x.size());
}
private long parseDate(String date) throws ParseException { private long parseDate(String date) throws ParseException {
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm"); DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
return dateFormat.parse(date).getTime(); return dateFormat.parse(date).getTime();

View File

@ -1,5 +1,6 @@
package se.vidstige.jadb.test.unit; package se.vidstige.jadb.test.unit;
import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import se.vidstige.jadb.JadbConnection; import se.vidstige.jadb.JadbConnection;
@ -7,79 +8,88 @@ import se.vidstige.jadb.JadbDevice;
import se.vidstige.jadb.managers.PropertyManager; import se.vidstige.jadb.managers.PropertyManager;
import se.vidstige.jadb.test.fakes.FakeAdbServer; import se.vidstige.jadb.test.fakes.FakeAdbServer;
import java.util.HashMap;
import java.util.Map; import java.util.Map;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
public class PropertyManagerTest { public class PropertyManagerTest {
private final String DEVICE_SERIAL = "serial-123";
private FakeAdbServer server; private FakeAdbServer server;
private JadbConnection connection; private JadbConnection connection;
private JadbDevice device;
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
server = new FakeAdbServer(15037); server = new FakeAdbServer(15037);
server.start(); server.start();
server.add(DEVICE_SERIAL);
connection = new JadbConnection("localhost", 15037); connection = new JadbConnection("localhost", 15037);
device = connection.getDevices().get(0);
}
@After
public void tearDown() throws Exception {
server.stop();
server.verifyExpectations();
} }
@Test @Test
public void testGetPropsStandardFormat() throws Exception { public void testGetPropsStandardFormat() throws Exception {
final String key1 = "bluetooth.hciattach"; //Arrange
final String value1 = "true"; Map<String, String> expected = new HashMap<>();
expected.put("bluetooth.hciattach", "true");
expected.put("bluetooth.status", "off");
final String key2 = "bluetooth.status"; String response = "[bluetooth.status]: [off] \n" +
final String value2 = "off"; "[bluetooth.hciattach]: [true]";
String format = "[%s]: [%s] \n"; server.expectShell(DEVICE_SERIAL, "getprop").returns(response);
String response = String.format(format, key1, value1) + String.format(format, key2, value2); //Act
Map<String, String> actual = new PropertyManager(device).getprop();
//Assert
server.add("serial-123"); assertEquals(expected, actual);
server.expectShell("serial-123", "getprop").returns(response);
JadbDevice device = connection.getDevices().get(0);
Map<String, String> props = new PropertyManager(device).getprop();
assertNotNull(props.get(key1));
assertEquals(props.get(key1), value1);
assertNotNull(props.get(key2));
assertEquals(props.get(key2), value2);
} }
@Test @Test
public void testGetPropsMalformedString() throws Exception { public void testGetPropsMalformedIgnoredString() throws Exception {
final String key1 = "bluetooth.hciattach"; //Arrange
final String value1 = "true"; Map<String, String> expected = new HashMap<>();
expected.put("bluetooth.hciattach", "true");
expected.put("bluetooth.status", "off");
final String key2 = "bluetooth.status"; String response = "[bluetooth.status]: [off]\n" +
final String value2 = "off"; "[malformed_line]\n" +
"[bluetooth.hciattach]: [true]";
String format = "[%s]: [%s] \n"; server.expectShell(DEVICE_SERIAL, "getprop").returns(response);
String response1 = String.format(format, key1, value1) + "[malformed]" + String.format(format, key2, value2); //Act
String response2 = String.format(format, key1, value1) + "[malformed]\n" + String.format(format, key2, value2); Map<String, String> actual = new PropertyManager(device).getprop();
//Assert
assertEquals(expected, actual);
}
server.add("serial-123"); @Test
JadbDevice device = connection.getDevices().get(0); public void testGetPropsMalformedNotUsedString() throws Exception {
server.expectShell("serial-123", "getprop").returns(response1); //Arrange
Map<String, String> expected = new HashMap<>();
expected.put("bluetooth.status", "off");
//Test1 String response = "[bluetooth.status]: [off]\n" +
Map<String, String> props1 = new PropertyManager(device).getprop(); "malformed[bluetooth.hciattach]: [true]";
assertNotNull(props1.get(key1)); server.expectShell(DEVICE_SERIAL, "getprop").returns(response);
assertEquals(props1.get(key1), value1);
//Test2 //Act
server.expectShell("serial-123", "getprop").returns(response2); Map<String, String> actual = new PropertyManager(device).getprop();
Map<String, String> props2 = new PropertyManager(device).getprop();
assertNotNull(props2.get(key1)); //Assert
assertEquals(props2.get(key1), value1); assertEquals(expected, actual);
assertNotNull(props2.get(key2));
assertEquals(props2.get(key2), value2);
} }
} }