BaseChildActivity extends CollectionActivity { public Child save() throws JSONException { if (!child.isValid()) { makeToast(R.string.save_child_invalid); return null; } if (child.isNew()) { child.setCreatedBy(getCurrentUser().getUserName()); child.setOrganisation(getCurrentUser().getOrganisation()); } child.generateUniqueId(); child.setSynced(false); @Cleanup ChildRepository repository = inject(ChildRepository.class); repository.createOrUpdate(child); return child; }  Child load(); Child save(); void view(); @Override void onCreate(Bundle savedInstanceState); void showAlertDialog(); static final int CLOSE_ACTIVITY; }
@Test public void testToastInvalidChild() throws JSONException { Child child = mock(Child.class); when(child.isValid()).thenReturn(false); activity.child = child; activity.save(); assertThat(ShadowToast.getTextOfLatestToast(), equalTo(activity.getString(R.string.save_child_invalid))); }
@Test @Ignore public void shouldMarkChildSyncStateToFalseWhenEverChildIsSaved() throws Exception { activity.child = new Child("id1", "user1", "{ 'test1' : 'value1', 'test2' : 0, 'test3' : [ '1', 2, '3' ] }"); activity.child.setSynced(true); activity.save(); assertEquals(false, activity.child.isSynced()); }