• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package com.xtremelabs.robolectric.shadows;
2 
3 import android.app.Activity;
4 import android.content.Context;
5 import android.view.View;
6 import android.widget.LinearLayout;
7 import android.widget.TextView;
8 import com.xtremelabs.robolectric.WithTestDefaultsRunner;
9 import org.junit.Before;
10 import org.junit.Test;
11 import org.junit.runner.RunWith;
12 
13 import static com.xtremelabs.robolectric.Robolectric.shadowOf;
14 import static org.junit.Assert.assertEquals;
15 
16 @RunWith(WithTestDefaultsRunner.class)
17 public class ViewInnerTextTest {
18     private Context activity;
19 
20     @Before
setUp()21     public void setUp() throws Exception {
22         activity = new Activity();
23     }
24 
25     @Test
testInnerText()26     public void testInnerText() throws Exception {
27         LinearLayout top = new LinearLayout(activity);
28         top.addView(textView("blah"));
29         top.addView(new View(activity));
30         top.addView(textView("a b c"));
31 
32         LinearLayout innerLayout = new LinearLayout(activity);
33         top.addView(innerLayout);
34 
35         innerLayout.addView(textView("d e f"));
36         innerLayout.addView(textView("g h i"));
37         innerLayout.addView(textView(""));
38         innerLayout.addView(textView(null));
39         innerLayout.addView(textView("jkl!"));
40 
41         top.addView(textView("mnop"));
42 
43         assertEquals("blah a b c d e f g h i jkl! mnop", shadowOf(top).innerText());
44     }
45 
46     @Test
shouldOnlyIncludeViewTextViewsText()47     public void shouldOnlyIncludeViewTextViewsText() throws Exception {
48         LinearLayout top = new LinearLayout(activity);
49         top.addView(textView("blah", View.VISIBLE));
50         top.addView(textView("blarg", View.GONE));
51         top.addView(textView("arrg", View.INVISIBLE));
52 
53         assertEquals("blah", shadowOf(top).innerText());
54     }
55 
56     @Test
shouldNotPrefixBogusSpaces()57     public void shouldNotPrefixBogusSpaces() throws Exception {
58         LinearLayout top = new LinearLayout(activity);
59         top.addView(textView("blarg", View.GONE));
60         top.addView(textView("arrg", View.INVISIBLE));
61         top.addView(textView("blah", View.VISIBLE));
62 
63         assertEquals("blah", shadowOf(top).innerText());
64     }
65 
textView(String text)66     private TextView textView(String text) {
67         return textView(text, View.VISIBLE);
68     }
69 
textView(String text, int visibility)70     private TextView textView(String text, int visibility) {
71         TextView textView = new TextView(activity);
72         textView.setText(text);
73         textView.setVisibility(visibility);
74         return textView;
75     }
76 }
77