Changeset View
Changeset View
Standalone View
Standalone View
tests/org/kde/kdeconnect/LanLinkProviderTest.java
Show First 20 Lines • Show All 44 Lines • ▼ Show 20 Line(s) | 34 | public class LanLinkProviderTest extends AndroidTestCase { | |||
---|---|---|---|---|---|
45 | } | 45 | } | ||
46 | 46 | | |||
47 | @Override | 47 | @Override | ||
48 | protected void tearDown() throws Exception { | 48 | protected void tearDown() throws Exception { | ||
49 | super.tearDown(); | 49 | super.tearDown(); | ||
50 | 50 | | |||
51 | } | 51 | } | ||
52 | 52 | | |||
53 | public void testIdentityPackageReceived() throws Exception{ | 53 | public void testIdentityPackageReceived() throws Exception { | ||
54 | 54 | | |||
55 | NetworkPackage networkPackage = Mockito.mock(NetworkPackage.class); | 55 | NetworkPackage networkPackage = Mockito.mock(NetworkPackage.class); | ||
56 | Mockito.when(networkPackage.getType()).thenReturn("kdeconnect.identity"); | 56 | Mockito.when(networkPackage.getType()).thenReturn("kdeconnect.identity"); | ||
57 | Mockito.when(networkPackage.getString("deviceId")).thenReturn("testDevice"); | 57 | Mockito.when(networkPackage.getString("deviceId")).thenReturn("testDevice"); | ||
58 | Mockito.when(networkPackage.getString("deviceName")).thenReturn("Test Device"); | 58 | Mockito.when(networkPackage.getString("deviceName")).thenReturn("Test Device"); | ||
59 | Mockito.when(networkPackage.getInt("protocolVersion")).thenReturn(5); | 59 | Mockito.when(networkPackage.getInt("protocolVersion")).thenReturn(5); | ||
60 | Mockito.when(networkPackage.getString("deviceType")).thenReturn("phone"); | 60 | Mockito.when(networkPackage.getString("deviceType")).thenReturn("phone"); | ||
61 | 61 | | |||
62 | String serialized = "{\"type\":\"kdeconnect.identity\",\"id\":12345,\"body\":{\"deviceName\":\"Test Device\",\"deviceType\":\"phone\",\"deviceId\":\"testDevice\",\"protocolVersion\":5}}"; | 62 | String serialized = "{\"type\":\"kdeconnect.identity\",\"id\":12345,\"body\":{\"deviceName\":\"Test Device\",\"deviceType\":\"phone\",\"deviceId\":\"testDevice\",\"protocolVersion\":5}}"; | ||
63 | Mockito.when(networkPackage.serialize()).thenReturn(serialized); | 63 | Mockito.when(networkPackage.serialize()).thenReturn(serialized); | ||
64 | 64 | | |||
65 | Socket channel = Mockito.mock(Socket.class); | 65 | Socket channel = Mockito.mock(Socket.class); | ||
66 | try { | 66 | try { | ||
67 | Method method = LanLinkProvider.class.getDeclaredMethod("identityPackageReceived", NetworkPackage.class, Socket.class, LanLink.ConnectionStarted.class); | 67 | Method method = LanLinkProvider.class.getDeclaredMethod("identityPackageReceived", NetworkPackage.class, Socket.class, LanLink.ConnectionStarted.class); | ||
68 | method.setAccessible(true); | 68 | method.setAccessible(true); | ||
69 | method.invoke(linkProvider, networkPackage, channel, LanLink.ConnectionStarted.Locally); | 69 | method.invoke(linkProvider, networkPackage, channel, LanLink.ConnectionStarted.Locally); | ||
70 | }catch (Exception e){ | 70 | } catch (Exception e) { | ||
71 | throw e; | 71 | throw e; | ||
72 | } | 72 | } | ||
73 | 73 | | |||
74 | HashMap<String, LanLink> visibleComputers; | 74 | HashMap<String, LanLink> visibleComputers; | ||
75 | try { | 75 | try { | ||
76 | Field field = LanLinkProvider.class.getDeclaredField("visibleComputers"); | 76 | Field field = LanLinkProvider.class.getDeclaredField("visibleComputers"); | ||
77 | field.setAccessible(true); | 77 | field.setAccessible(true); | ||
78 | visibleComputers = (HashMap<String, LanLink>)field.get(linkProvider); | 78 | visibleComputers = (HashMap<String, LanLink>) field.get(linkProvider); | ||
79 | }catch (Exception e){ | 79 | } catch (Exception e) { | ||
80 | throw e; | 80 | throw e; | ||
81 | } | 81 | } | ||
82 | assertNotNull(visibleComputers.get("testDevice")); | 82 | assertNotNull(visibleComputers.get("testDevice")); | ||
83 | 83 | | |||
84 | } | 84 | } | ||
85 | } | 85 | } |