1 /* 2 * Copyright (C) 2013 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package com.android.loganalysis.item; 17 18 import junit.framework.TestCase; 19 20 import org.json.JSONArray; 21 import org.json.JSONException; 22 import org.json.JSONObject; 23 24 import java.util.Date; 25 26 /** 27 * Unit test for {@link SmartMonkeyLogItem}. 28 */ 29 public class SmartMonkeyLogItemTest extends TestCase { 30 /** 31 * Test that {@link SmartMonkeyLogItem#toJson()} returns correctly. 32 */ testToJson()33 public void testToJson() throws JSONException { 34 SmartMonkeyLogItem item = new SmartMonkeyLogItem(); 35 item.addApplication("application1"); 36 item.addPackage("package1"); 37 item.addAnrTime(new Date()); 38 item.addCrashTime(new Date()); 39 40 // Convert to JSON string and back again 41 JSONObject output = new JSONObject(item.toJson().toString()); 42 43 assertTrue(output.has(SmartMonkeyLogItem.APPLICATIONS)); 44 assertTrue(output.get(SmartMonkeyLogItem.APPLICATIONS) instanceof JSONArray); 45 assertTrue(output.has(SmartMonkeyLogItem.PACKAGES)); 46 assertTrue(output.get(SmartMonkeyLogItem.PACKAGES) instanceof JSONArray); 47 assertTrue(output.has(SmartMonkeyLogItem.ANR_TIMES)); 48 assertTrue(output.get(SmartMonkeyLogItem.ANR_TIMES) instanceof JSONArray); 49 assertTrue(output.has(SmartMonkeyLogItem.CRASH_TIMES)); 50 assertTrue(output.get(SmartMonkeyLogItem.CRASH_TIMES) instanceof JSONArray); 51 } 52 } 53