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");
}
@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 {
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
return dateFormat.parse(date).getTime();

View File

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