mirror of
https://github.com/revanced/jadb.git
synced 2024-06-10 07:07:49 +02:00
vidstige/jadb#38 added unit tests
This commit is contained in:
parent
02f6f6d79d
commit
9c83f0320c
|
@ -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<>();
|
||||
|
|
19
test/se/vidstige/jadb/FakeJadbDevice.java
Normal file
19
test/se/vidstige/jadb/FakeJadbDevice.java
Normal 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);
|
||||
}
|
||||
}
|
38
test/se/vidstige/jadb/test/unit/JadbDeviceTest.java
Normal file
38
test/se/vidstige/jadb/test/unit/JadbDeviceTest.java
Normal 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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user