1 package edu.jiangxin.apktoolbox.android.dumpsys.tojson;
2
3 import org.json.JSONArray;
4 import org.json.JSONObject;
5 import org.junit.jupiter.api.Test;
6
7 import java.io.File;
8 import java.net.URL;
9
10 import static org.junit.jupiter.api.Assertions.assertEquals;
11 import static org.junit.jupiter.api.Assertions.assertNotNull;
12
13 public class Alarm2JsonTest {
14 @Test
15 public void testDumpsys2Json_parsesAlarmDumpCorrectly() throws Exception {
16 URL resource = getClass().getClassLoader().getResource("dumpsys/alarm.dumpsys");
17 assertNotNull(resource, "Test resource not found");
18 File file = new File(resource.toURI());
19
20 Alarm2Json parser = new Alarm2Json();
21 String jsonStr = parser.dumpsys2Json(file);
22 JSONObject result = new JSONObject(jsonStr);
23 JSONArray pendingAlarms = result.getJSONArray("119 pending alarms");
24 assertEquals(119, pendingAlarms.length());
25 }
26 }
27