mirror of
https://github.com/revanced/jadb.git
synced 2024-11-19 10:39:23 +01:00
Merge pull request #75 from anthonyflynn/package_manager_tests
Package manager tests
This commit is contained in:
commit
f9cfdfa419
@ -14,7 +14,12 @@ public class Package {
|
||||
public String toString() { return name; }
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) { return name.equals(o); }
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof Package)) return false;
|
||||
Package that = (Package) o;
|
||||
return name.equals(that.name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() { return name.hashCode(); }
|
||||
|
94
test/se/vidstige/jadb/test/unit/PackageManagerTest.java
Normal file
94
test/se/vidstige/jadb/test/unit/PackageManagerTest.java
Normal file
@ -0,0 +1,94 @@
|
||||
package se.vidstige.jadb.test.unit;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import se.vidstige.jadb.JadbConnection;
|
||||
import se.vidstige.jadb.JadbDevice;
|
||||
import se.vidstige.jadb.managers.Package;
|
||||
import se.vidstige.jadb.managers.PackageManager;
|
||||
import se.vidstige.jadb.test.fakes.FakeAdbServer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class PackageManagerTest {
|
||||
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 testGetPackagesWithSeveralPackages() throws Exception {
|
||||
//Arrange
|
||||
List<Package> expected = new ArrayList<>();
|
||||
expected.add(new Package("/system/priv-app/Contacts.apk-com.android.contacts"));
|
||||
expected.add(new Package("/system/priv-app/Teleservice.apk-com.android.phone"));
|
||||
|
||||
String response = "package:/system/priv-app/Contacts.apk-com.android.contacts\n" +
|
||||
"package:/system/priv-app/Teleservice.apk-com.android.phone";
|
||||
|
||||
server.expectShell(DEVICE_SERIAL, "pm list packages").returns(response);
|
||||
|
||||
//Act
|
||||
List<Package> actual = new PackageManager(device).getPackages();
|
||||
|
||||
//Assert
|
||||
assertEquals(expected, actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetPackagesMalformedIgnoredString() throws Exception {
|
||||
//Arrange
|
||||
List<Package> expected = new ArrayList<>();
|
||||
expected.add(new Package("/system/priv-app/Contacts.apk-com.android.contacts"));
|
||||
expected.add(new Package("/system/priv-app/Teleservice.apk-com.android.phone"));
|
||||
|
||||
String response = "package:/system/priv-app/Contacts.apk-com.android.contacts\n" +
|
||||
"[malformed_line]\n" +
|
||||
"package:/system/priv-app/Teleservice.apk-com.android.phone";
|
||||
|
||||
server.expectShell(DEVICE_SERIAL, "pm list packages").returns(response);
|
||||
|
||||
//Act
|
||||
List<Package> actual = new PackageManager(device).getPackages();
|
||||
|
||||
//Assert
|
||||
assertEquals(expected, actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetPackagesWithNoPackages() throws Exception {
|
||||
//Arrange
|
||||
List<Package> expected = new ArrayList<>();
|
||||
String response = "";
|
||||
|
||||
server.expectShell(DEVICE_SERIAL, "pm list packages").returns(response);
|
||||
|
||||
//Act
|
||||
List<Package> actual = new PackageManager(device).getPackages();
|
||||
|
||||
//Assert
|
||||
assertEquals(expected, actual);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user