Hello,
I have a custom WidgetProvider class which creates widgets and I am currently trying to unit test behaviour of different methods (such as onUpdate) and layout changes.
I was able to write a test for default layout inflation but I cannot find a way to test onUpdate?
@Test
public void widget2x1DefaultLayoutTest() throws Exception {
int id = shadowAppWidgetManager.createWidget(Widget2x1.class, R.layout.view_widget2x1);
View view = shadowAppWidgetManager.getViewFor(id);
Drawable drawable = context.getResources().getDrawable(R.drawable.icon);
ImageView logo = (ImageView) view.findViewById(R.id.widget_logo);
ImageView icon = (ImageView) view.findViewById(R.id.icon);
TextView max = (TextView) view.findViewById(R.id.max);
TextView min = (TextView) view.findViewById(R.id.min);
assertThat(logo.getVisibility(), is(View.VISIBLE));
assertThat(icon.getDrawable(), is(drawable));
assertThat(icon.getVisibility(), is(View.VISIBLE));
assertThat(maxTemperature.getText().toString(), is("--"));
assertThat(maxTemperature.getVisibility(), is(View.VISIBLE));
assertThat(minTemperature.getText().toString(), is("--"));
assertThat(minTemperature.getVisibility(), is(View.VISIBLE));
}
Any help would be appreciated.
Thanks,
Damian