Home | History | Annotate | Download | only in format
      1 /*
      2  * Copyright (C) 2011 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 
     17 package com.android.contacts.format;
     18 
     19 import android.text.Html;
     20 import android.text.Spanned;
     21 import android.text.TextUtils;
     22 import android.widget.TextView;
     23 
     24 import junit.framework.Assert;
     25 
     26 /**
     27  * Utility class to check the value of spanned text in text views.
     28  */
     29 public class SpannedTestUtils {
     30     /**
     31      * Checks that the text contained in the text view matches the given HTML text.
     32      *
     33      * @param expectedHtmlText the expected text to be in the text view
     34      * @param textView the text view from which to get the text
     35      */
     36     public static void checkHtmlText(String expectedHtmlText, TextView textView) {
     37         String actualHtmlText = Html.toHtml((Spanned) textView.getText());
     38         if (TextUtils.isEmpty(expectedHtmlText)) {
     39             // If the text is empty, it does not add the <p></p> bits to it.
     40             Assert.assertEquals("", actualHtmlText);
     41         } else {
     42             Assert.assertEquals("<p>" + expectedHtmlText + "</p>\n", actualHtmlText);
     43         }
     44     }
     45 
     46 }
     47