Given the following sample onCreate()
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
Bundle extras = getIntent().getExtras();
if (extras != null && (null != extras.getString("myVar")))
{
setContentView(R.layout.success);
}
else
{
setContentView(R.layout.failure);
}
}
What I want to do, is to unit test this activity to make sure I can get either content view set depending on the extras that are passed in when the activity is created.
I have the following so far in my Robolectric test :
@Test
public void testNullExtrasSetsFailureView()
{
myActivity.onCreate(null);
// This is the bit I'm struggling with, how to obtain content view?
assertThat("the view the onCreate loads..", equalTo(R.layout.failure))
}
How can I achieve this? I've had a look through the API and I couldn't see any obvious way of locating the content view, other than findViewById()
but I want the layout not an individual view item.
Thanks