InitialValueCheckBox extends AppCompatCheckBox { public void setInitiallyChecked(boolean checked) { if (!mRestored) { setChecked(checked); } } InitialValueCheckBox(Context context);  InitialValueCheckBox(Context context, AttributeSet attrs);  InitialValueCheckBox(Context context, AttributeSet attrs, int defStyleAttr); @Override Parcelable onSaveInstanceState(); @Override void onRestoreInstanceState(Parcelable state); void setInitiallyChecked(boolean checked);  }
@Test public void setInitiallyChecked_setsChecked() { InitialValueCheckBox initialValueCheckBox = new InitialValueCheckBox(RuntimeEnvironment.application); initialValueCheckBox.setInitiallyChecked(true); assertTrue(initialValueCheckBox.isChecked()); initialValueCheckBox.setInitiallyChecked(false); assertFalse(initialValueCheckBox.isChecked()); }