13d7311f76f3f41a5794b01536498c634b3ff2a69Flavio Lerda/* 23d7311f76f3f41a5794b01536498c634b3ff2a69Flavio Lerda * Copyright (C) 2011 The Android Open Source Project 33d7311f76f3f41a5794b01536498c634b3ff2a69Flavio Lerda * 43d7311f76f3f41a5794b01536498c634b3ff2a69Flavio Lerda * Licensed under the Apache License, Version 2.0 (the "License"); 53d7311f76f3f41a5794b01536498c634b3ff2a69Flavio Lerda * you may not use this file except in compliance with the License. 63d7311f76f3f41a5794b01536498c634b3ff2a69Flavio Lerda * You may obtain a copy of the License at 73d7311f76f3f41a5794b01536498c634b3ff2a69Flavio Lerda * 83d7311f76f3f41a5794b01536498c634b3ff2a69Flavio Lerda * http://www.apache.org/licenses/LICENSE-2.0 93d7311f76f3f41a5794b01536498c634b3ff2a69Flavio Lerda * 103d7311f76f3f41a5794b01536498c634b3ff2a69Flavio Lerda * Unless required by applicable law or agreed to in writing, software 113d7311f76f3f41a5794b01536498c634b3ff2a69Flavio Lerda * distributed under the License is distributed on an "AS IS" BASIS, 123d7311f76f3f41a5794b01536498c634b3ff2a69Flavio Lerda * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 133d7311f76f3f41a5794b01536498c634b3ff2a69Flavio Lerda * See the License for the specific language governing permissions and 143d7311f76f3f41a5794b01536498c634b3ff2a69Flavio Lerda * limitations under the License. 153d7311f76f3f41a5794b01536498c634b3ff2a69Flavio Lerda */ 163d7311f76f3f41a5794b01536498c634b3ff2a69Flavio Lerda 173d7311f76f3f41a5794b01536498c634b3ff2a69Flavio Lerdapackage com.android.contacts.format; 183d7311f76f3f41a5794b01536498c634b3ff2a69Flavio Lerda 193d7311f76f3f41a5794b01536498c634b3ff2a69Flavio Lerdaimport android.text.Html; 203d7311f76f3f41a5794b01536498c634b3ff2a69Flavio Lerdaimport android.text.Spanned; 213d7311f76f3f41a5794b01536498c634b3ff2a69Flavio Lerdaimport android.text.TextUtils; 223d7311f76f3f41a5794b01536498c634b3ff2a69Flavio Lerdaimport android.widget.TextView; 233d7311f76f3f41a5794b01536498c634b3ff2a69Flavio Lerda 243d7311f76f3f41a5794b01536498c634b3ff2a69Flavio Lerdaimport junit.framework.Assert; 253d7311f76f3f41a5794b01536498c634b3ff2a69Flavio Lerda 263d7311f76f3f41a5794b01536498c634b3ff2a69Flavio Lerda/** 273d7311f76f3f41a5794b01536498c634b3ff2a69Flavio Lerda * Utility class to check the value of spanned text in text views. 283d7311f76f3f41a5794b01536498c634b3ff2a69Flavio Lerda */ 293d7311f76f3f41a5794b01536498c634b3ff2a69Flavio Lerdapublic class SpannedTestUtils { 303d7311f76f3f41a5794b01536498c634b3ff2a69Flavio Lerda /** 313d7311f76f3f41a5794b01536498c634b3ff2a69Flavio Lerda * Checks that the text contained in the text view matches the given HTML text. 323d7311f76f3f41a5794b01536498c634b3ff2a69Flavio Lerda * 333d7311f76f3f41a5794b01536498c634b3ff2a69Flavio Lerda * @param expectedHtmlText the expected text to be in the text view 343d7311f76f3f41a5794b01536498c634b3ff2a69Flavio Lerda * @param textView the text view from which to get the text 353d7311f76f3f41a5794b01536498c634b3ff2a69Flavio Lerda */ 363d7311f76f3f41a5794b01536498c634b3ff2a69Flavio Lerda public static void checkHtmlText(String expectedHtmlText, TextView textView) { 373d7311f76f3f41a5794b01536498c634b3ff2a69Flavio Lerda String actualHtmlText = Html.toHtml((Spanned) textView.getText()); 383d7311f76f3f41a5794b01536498c634b3ff2a69Flavio Lerda if (TextUtils.isEmpty(expectedHtmlText)) { 393d7311f76f3f41a5794b01536498c634b3ff2a69Flavio Lerda // If the text is empty, it does not add the <p></p> bits to it. 403d7311f76f3f41a5794b01536498c634b3ff2a69Flavio Lerda Assert.assertEquals("", actualHtmlText); 413d7311f76f3f41a5794b01536498c634b3ff2a69Flavio Lerda } else { 423d7311f76f3f41a5794b01536498c634b3ff2a69Flavio Lerda Assert.assertEquals("<p>" + expectedHtmlText + "</p>\n", actualHtmlText); 433d7311f76f3f41a5794b01536498c634b3ff2a69Flavio Lerda } 443d7311f76f3f41a5794b01536498c634b3ff2a69Flavio Lerda } 453d7311f76f3f41a5794b01536498c634b3ff2a69Flavio Lerda 463d7311f76f3f41a5794b01536498c634b3ff2a69Flavio Lerda} 47