title: Is there a way to test pickers with Robolectric?
body: <p>I was following the tutorial from Android developer. Right now my class looks like this:</p>
  
  <pre><code>public class DatePickerFragment extends DialogFragment implements
          DatePickerDialog.OnDateSetListener {
  
      final Calendar calendar = Calendar.getInstance();
  
      @Override
      public Dialog onCreateDialog(Bundle savedInstanceState) {
          return new DatePickerDialog(getActivity(), this,
                  calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH),
                  calendar.get(Calendar.DAY_OF_MONTH));
      }
  
      @Override
      public void onDateSet(DatePicker view, int year, int month, int day) {
          calendar.set(year, month, day);
          Datable datable = (Datable) view.getContext();
          datable.setDate(calendar.getTime());
      }
  
  }
  </code></pre>
  
  <p>If I try to run a test like the following, I'm getting a NullPointerException on the first <code>getDataPicker()</code>. I want to check that the default date is today.</p>
  
  <pre><code>@Test
  public void testDatePickerFragment() {
      final Calendar calendar = Calendar.getInstance();
      int expectedYear = calendar.get(Calendar.YEAR);
      int expectedMonth = calendar.get(Calendar.MONTH);
      int expectedDay = calendar.get(Calendar.DAY_OF_MONTH);
  
      DatePickerFragment fragment = new DatePickerFragment();
  
      FragmentActivity activity = Robolectric
              .buildActivity(FragmentActivity.class).create().start()
              .resume().get();
  
      FragmentManager fragmentManager = activity.getSupportFragmentManager();
      FragmentTransaction fragmentTransaction = fragmentManager
              .beginTransaction();
      fragment.show(fragmentManager, "datePicker");
      fragmentTransaction.commit();
  
      DatePickerDialog dialog = (DatePickerDialog) ShadowDatePickerDialog
              .getLatestDialog();
  
      assertThat(dialog, is(not(nullValue())));
  
      assertThat(dialog.getDatePicker().getDayOfMonth(), is(expectedDay));
      assertThat(dialog.getDatePicker().getMonth(), is(expectedMonth));
      assertThat(dialog.getDatePicker().getYear(), is(expectedYear));
  }
  </code></pre>
  
  <p>I would like to be able to test this class without using it inside an activity (in that case I believe I can use the <code>buildActivity</code> method and then <code>ShadowDatePickerDialog</code> but that's the next step).</p>
  
  <p>So, is it possible to test the datePicker? I'm using robolectric 2.2</p>