1 package com.xtremelabs.robolectric.shadows; 2 3 4 import android.app.Activity; 5 import android.content.Context; 6 import android.text.Html; 7 import android.widget.EditText; 8 import android.widget.TextView; 9 import com.xtremelabs.robolectric.WithTestDefaultsRunner; 10 import org.junit.Before; 11 import org.junit.Test; 12 import org.junit.runner.RunWith; 13 14 import static org.hamcrest.CoreMatchers.equalTo; 15 import static org.junit.Assert.assertThat; 16 17 @RunWith(WithTestDefaultsRunner.class) 18 public class HtmlTest { 19 private Context context; 20 21 @Before 22 public void setUp() throws Exception { 23 context = new Activity(); 24 } 25 26 @Test 27 public void shouldBeAbleToGetTextFromTextViewAfterUsingSetTextWithHtmlDotFromHtml() throws Exception { 28 TextView textView = new TextView(context); 29 textView.setText(Html.fromHtml("<b>some</b> html text")); 30 assertThat(textView.getText().toString(), equalTo("<b>some</b> html text")); 31 } 32 33 @Test 34 public void shouldBeAbleToGetTextFromEditTextAfterUsingSetTextWithHtmlDotFromHtml() throws Exception { 35 EditText editText = new EditText(context); 36 editText.setText(Html.fromHtml("<b>some</b> html text")); 37 assertThat(editText.getText().toString(), equalTo("<b>some</b> html text")); 38 } 39 40 @Test(expected = NullPointerException.class) 41 public void shouldThrowNullPointerExceptionWhenNullStringEncountered() throws Exception { 42 Html.fromHtml(null); 43 } 44 } 45