| OLD | NEW |
| (Empty) |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 package org.chromium.chrome.browser.physicalweb; | |
| 6 | |
| 7 import android.support.test.filters.SmallTest; | |
| 8 | |
| 9 import junit.framework.TestCase; | |
| 10 | |
| 11 import org.json.JSONException; | |
| 12 import org.json.JSONObject; | |
| 13 | |
| 14 /** | |
| 15 * Tests for {@link PwsResult}. | |
| 16 */ | |
| 17 public class PwsResultTest extends TestCase { | |
| 18 PwsResult mReferencePwsResult = null; | |
| 19 JSONObject mReferenceJsonObject = null; | |
| 20 | |
| 21 @Override | |
| 22 protected void setUp() throws Exception { | |
| 23 super.setUp(); | |
| 24 mReferencePwsResult = new PwsResult( | |
| 25 "https://shorturl.com", | |
| 26 "https://longurl.com", | |
| 27 "https://longurl.com/favicon.ico", | |
| 28 "This is a page", | |
| 29 "Pages are the best", | |
| 30 "group1"); | |
| 31 // Because we can't print JSON sorted by keys, the order is important he
re. | |
| 32 mReferenceJsonObject = new JSONObject("{" | |
| 33 + " \"scannedUrl\": \"https://shorturl.com\"," | |
| 34 + " \"resolvedUrl\": \"https://longurl.com\"," | |
| 35 + " \"icon\": \"https://longurl.com/favicon.ico\"," | |
| 36 + " \"title\": \"This is a page\"," | |
| 37 + " \"description\": \"Pages are the best\"," | |
| 38 + " \"group\": \"group1\"" | |
| 39 + "}"); | |
| 40 } | |
| 41 | |
| 42 @SmallTest | |
| 43 public void testJsonSerializeWorks() throws JSONException { | |
| 44 assertEquals(mReferenceJsonObject.toString(), | |
| 45 mReferencePwsResult.jsonSerialize().toString()); | |
| 46 } | |
| 47 | |
| 48 @SmallTest | |
| 49 public void testJsonDeserializeWorks() throws JSONException { | |
| 50 PwsResult pwsResult = PwsResult.jsonDeserialize(mReferenceJsonObject); | |
| 51 assertEquals(mReferencePwsResult.requestUrl, pwsResult.requestUrl); | |
| 52 assertEquals(mReferencePwsResult.responseUrl, pwsResult.responseUrl); | |
| 53 assertEquals(mReferencePwsResult.iconUrl, pwsResult.iconUrl); | |
| 54 assertEquals(mReferencePwsResult.title, pwsResult.title); | |
| 55 assertEquals(mReferencePwsResult.description, pwsResult.description); | |
| 56 assertEquals(mReferencePwsResult.group, pwsResult.group); | |
| 57 } | |
| 58 } | |
| OLD | NEW |