This commit is contained in:
Arthur 2016-09-30 18:30:28 +03:00
parent 02f6f6d79d
commit 9c83f0320c
3 changed files with 58 additions and 1 deletions

View File

@ -80,7 +80,7 @@ public class JadbDevice {
}
//@VisibleForTesting
Map<String, String> parseProp(BufferedReader bufferedReader) throws IOException {
private Map<String, String> parseProp(BufferedReader bufferedReader) throws IOException {
final Pattern pattern = Pattern.compile("^\\[(.*)\\]:.\\[(.*)\\]");
HashMap<String, String> result = new HashMap<>();

View File

@ -0,0 +1,19 @@
package se.vidstige.jadb;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
public class FakeJadbDevice extends JadbDevice {
private final List<InputStream> executeShellResponse;
public FakeJadbDevice(String serial, String type, ITransportFactory tFactory, List<InputStream> executeShellResponse) {
super(serial, type, tFactory);
this.executeShellResponse = executeShellResponse;
}
@Override
public InputStream executeShell(String command, String... args) throws IOException, JadbException {
return executeShellResponse.get(0);
}
}

View File

@ -0,0 +1,38 @@
package se.vidstige.jadb.test.unit;
import org.junit.Test;
import se.vidstige.jadb.FakeJadbDevice;
import se.vidstige.jadb.ITransportFactory;
import se.vidstige.jadb.JadbDevice;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import static org.junit.Assert.*;
public class JadbDeviceTest {
@Test
public void getprop() throws Exception {
final String key1 = "bluetooth.hciattach";
final String value1 = "true";
final String key2 = "bluetooth.status";
final String value2 = "off";
String response = "[" + key1 + "]: [" + value1 + "]\n" +
"[" + key2 + "]: [" + value2 + "]\n";
List<InputStream> executeShellResponse = Collections.singletonList((InputStream) new ByteArrayInputStream(response.getBytes(StandardCharsets.UTF_8)));
Map<String, String> props = new FakeJadbDevice("serial", "type", null, executeShellResponse).getprop();
assertNotNull(props.get(key1));
assertEquals(props.get(key1), value1);
assertNotNull(props.get(key2));
assertEquals(props.get(key2), value2);
}
}