TripForeignKeyAbstractTableController extends AbstractTableController<ModelType> { @Override public synchronized void unsubscribe(@NonNull TableEventsListener<ModelType> tableEventsListener) { if (tableEventsListener instanceof TripForeignKeyTableEventsListener) { final TripForeignKeyTableEventsListener<ModelType> tripForeignKeyTableEventsListener = (TripForeignKeyTableEventsListener<ModelType>) tableEventsListener; mForeignTableEventsListeners.remove(tripForeignKeyTableEventsListener); final BridgingTripForeignKeyTableEventsListener<ModelType> bridge = mBridgingTableEventsListeners.remove(tripForeignKeyTableEventsListener); if (bridge != null) { bridge.unsubscribe(); } } else { super.unsubscribe(tableEventsListener); } } TripForeignKeyAbstractTableController(@NonNull TripForeignKeyAbstractSqlTable<ModelType> table, @NonNull Analytics analytics);  TripForeignKeyAbstractTableController(@NonNull TripForeignKeyAbstractSqlTable<ModelType> table, @NonNull TableActionAlterations<ModelType> tableActionAlterations, @NonNull Analytics analytics);   TripForeignKeyAbstractTableController(@NonNull TripForeignKeyAbstractSqlTable<ModelType> table, @NonNull TableActionAlterations<ModelType> tableActionAlterations, @NonNull Analytics analytics, @NonNull Scheduler subscribeOnScheduler, @NonNull Scheduler observeOnScheduler); @Override synchronized void subscribe(@NonNull TableEventsListener<ModelType> tableEventsListener); @Override synchronized void unsubscribe(@NonNull TableEventsListener<ModelType> tableEventsListener); synchronized Single<List<ModelType>> get(@NonNull Trip trip); synchronized Single<List<ModelType>> get(@NonNull final Trip trip, final  boolean isDescending); @NonNull Observable<ForeignKeyGetResult<ModelType>> getForeignKeyGetStream();  }
@Test public void onInsertSuccess() throws Exception { final KeyedObject insertItem = new KeyedObject(); final DatabaseOperationMetadata databaseOperationMetadata = new DatabaseOperationMetadata(); when(mTableActionAlterations.preInsert(insertItem)).thenReturn(Single.just(insertItem)); when(mTable.insert(insertItem, databaseOperationMetadata)).thenReturn(Single.just(insertItem)); when(mTableActionAlterations.postInsert(insertItem)).thenReturn(Single.just(insertItem)); mAbstractTableController.unsubscribe(mListener2); mAbstractTableController.insert(insertItem, databaseOperationMetadata); verify(mListener1).onInsertSuccess(insertItem, databaseOperationMetadata); verify(mListener3).onInsertSuccess(insertItem, databaseOperationMetadata); verifyZeroInteractions(mListener2); }
@Test public void onPreInsertException() throws Exception { final KeyedObject insertItem = new KeyedObject(); final Exception e = new Exception(); final DatabaseOperationMetadata databaseOperationMetadata = new DatabaseOperationMetadata(); when(mTableActionAlterations.preInsert(insertItem)).thenReturn(Single.error(e)); when(mTable.insert(insertItem, databaseOperationMetadata)).thenReturn(Single.just(insertItem)); when(mTableActionAlterations.postInsert(insertItem)).thenReturn(Single.just(insertItem)); mAbstractTableController.unsubscribe(mListener2); mAbstractTableController.insert(insertItem, databaseOperationMetadata); verify(mAnalytics).record(any(ErrorEvent.class)); verify(mListener1).onInsertFailure(insertItem, e, databaseOperationMetadata); verify(mListener3).onInsertFailure(insertItem, e, databaseOperationMetadata); verifyZeroInteractions(mListener2); }
@Test public void onInsertException() throws Exception { final KeyedObject insertItem = new KeyedObject(); final Exception e = new Exception(); final DatabaseOperationMetadata databaseOperationMetadata = new DatabaseOperationMetadata(); when(mTableActionAlterations.preInsert(insertItem)).thenReturn(Single.just(insertItem)); when(mTable.insert(insertItem, databaseOperationMetadata)).thenReturn(Single.error(e)); when(mTableActionAlterations.postInsert(insertItem)).thenReturn(Single.just(insertItem)); mAbstractTableController.unsubscribe(mListener2); mAbstractTableController.insert(insertItem, databaseOperationMetadata); verify(mAnalytics).record(any(ErrorEvent.class)); verify(mListener1).onInsertFailure(insertItem, e, databaseOperationMetadata); verify(mListener3).onInsertFailure(insertItem, e, databaseOperationMetadata); verifyZeroInteractions(mListener2); }
@Test public void onPostInsertException() throws Exception { final KeyedObject insertItem = new KeyedObject(); final Exception e = new Exception(); final DatabaseOperationMetadata databaseOperationMetadata = new DatabaseOperationMetadata(); when(mTableActionAlterations.preInsert(insertItem)).thenReturn(Single.just(insertItem)); when(mTable.insert(insertItem, databaseOperationMetadata)).thenReturn(Single.just(insertItem)); when(mTableActionAlterations.postInsert(insertItem)).thenReturn(Single.error(e)); mAbstractTableController.unsubscribe(mListener2); mAbstractTableController.insert(insertItem, databaseOperationMetadata); verify(mAnalytics).record(any(ErrorEvent.class)); verify(mListener1).onInsertFailure(eq(insertItem), any(Exception.class), eq(databaseOperationMetadata)); verify(mListener3).onInsertFailure(eq(insertItem), any(Exception.class), eq(databaseOperationMetadata)); verifyZeroInteractions(mListener2); }
@Test public void onUpdateSuccess() throws Exception { final KeyedObject oldItem = new KeyedObject(); final KeyedObject newItem = new KeyedObject(); final DatabaseOperationMetadata databaseOperationMetadata = new DatabaseOperationMetadata(); when(mTableActionAlterations.preUpdate(oldItem, newItem)).thenReturn(Single.just(newItem)); when(mTable.update(oldItem, newItem, databaseOperationMetadata)).thenReturn(Single.just(newItem)); when(mTableActionAlterations.postUpdate(oldItem, newItem)).thenReturn(Single.just(newItem)); mAbstractTableController.unsubscribe(mListener2); mAbstractTableController.update(oldItem, newItem, databaseOperationMetadata); verify(mListener1).onUpdateSuccess(oldItem, newItem, databaseOperationMetadata); verify(mListener3).onUpdateSuccess(oldItem, newItem, databaseOperationMetadata); verifyZeroInteractions(mListener2); }
@Test public void onPreUpdateException() throws Exception { final KeyedObject oldItem = new KeyedObject(); final KeyedObject newItem = new KeyedObject(); final Exception e = new Exception(); final DatabaseOperationMetadata databaseOperationMetadata = new DatabaseOperationMetadata(); when(mTableActionAlterations.preUpdate(oldItem, newItem)).thenReturn(Single.error(e)); when(mTable.update(oldItem, newItem, databaseOperationMetadata)).thenReturn(Single.just(newItem)); when(mTableActionAlterations.postUpdate(oldItem, newItem)).thenReturn(Single.just(newItem)); mAbstractTableController.unsubscribe(mListener2); mAbstractTableController.update(oldItem, newItem, databaseOperationMetadata); verify(mAnalytics).record(any(ErrorEvent.class)); verify(mListener1).onUpdateFailure(oldItem, e, databaseOperationMetadata); verify(mListener3).onUpdateFailure(oldItem, e, databaseOperationMetadata); verifyZeroInteractions(mListener2); }
@Test public void onUpdateException() throws Exception { final KeyedObject oldItem = new KeyedObject(); final KeyedObject newItem = new KeyedObject(); final Exception e = new Exception(); final DatabaseOperationMetadata databaseOperationMetadata = new DatabaseOperationMetadata(); when(mTableActionAlterations.preUpdate(oldItem, newItem)).thenReturn(Single.just(newItem)); when(mTable.update(oldItem, newItem, databaseOperationMetadata)).thenReturn(Single.error(e)); when(mTableActionAlterations.postUpdate(oldItem, newItem)).thenReturn(Single.just(newItem)); mAbstractTableController.unsubscribe(mListener2); mAbstractTableController.update(oldItem, newItem, databaseOperationMetadata); verify(mAnalytics).record(any(ErrorEvent.class)); verify(mListener1).onUpdateFailure(oldItem, e, databaseOperationMetadata); verify(mListener3).onUpdateFailure(oldItem, e, databaseOperationMetadata); verifyZeroInteractions(mListener2); }
@Test public void onPostUpdateException() throws Exception { final KeyedObject oldItem = new KeyedObject(); final KeyedObject newItem = new KeyedObject(); final Exception e = new Exception(); final DatabaseOperationMetadata databaseOperationMetadata = new DatabaseOperationMetadata(); when(mTableActionAlterations.preUpdate(oldItem, newItem)).thenReturn(Single.just(newItem)); when(mTable.update(oldItem, newItem, databaseOperationMetadata)).thenReturn(Single.just(newItem)); when(mTableActionAlterations.postUpdate(oldItem, newItem)).thenReturn(Single.error(e)); mAbstractTableController.unsubscribe(mListener2); mAbstractTableController.update(oldItem, newItem, databaseOperationMetadata); verify(mAnalytics).record(any(ErrorEvent.class)); verify(mListener1).onUpdateFailure(eq(oldItem), any(Exception.class), eq(databaseOperationMetadata)); verify(mListener3).onUpdateFailure(eq(oldItem), any(Exception.class), eq(databaseOperationMetadata)); verifyZeroInteractions(mListener2); }
@Test public void onDeleteSuccess() throws Exception { final KeyedObject deleteCandidateItem = new KeyedObject(); final KeyedObject deletedItem = new KeyedObject(); final DatabaseOperationMetadata databaseOperationMetadata = new DatabaseOperationMetadata(); when(mTableActionAlterations.preDelete(deleteCandidateItem)).thenReturn(Single.just(deleteCandidateItem)); when(mTable.delete(deleteCandidateItem, databaseOperationMetadata)).thenReturn(Single.just(deletedItem)); when(mTableActionAlterations.postDelete(deletedItem)).thenReturn(Single.just(deletedItem)); mAbstractTableController.unsubscribe(mListener2); mAbstractTableController.delete(deleteCandidateItem, databaseOperationMetadata); verify(mListener1).onDeleteSuccess(deletedItem, databaseOperationMetadata); verify(mListener3).onDeleteSuccess(deletedItem, databaseOperationMetadata); verifyZeroInteractions(mListener2); }
@Test public void onPreDeleteException() throws Exception { final KeyedObject deleteCandidateItem = new KeyedObject(); final KeyedObject deletedItem = new KeyedObject(); final Exception e = new Exception(); final DatabaseOperationMetadata databaseOperationMetadata = new DatabaseOperationMetadata(); when(mTableActionAlterations.preDelete(deleteCandidateItem)).thenReturn(Single.error(e)); when(mTable.delete(deleteCandidateItem, databaseOperationMetadata)).thenReturn(Single.just(deletedItem)); when(mTableActionAlterations.postDelete(deletedItem)).thenReturn(Single.just(deletedItem)); mAbstractTableController.unsubscribe(mListener2); mAbstractTableController.delete(deleteCandidateItem, databaseOperationMetadata); verify(mAnalytics).record(any(ErrorEvent.class)); verify(mListener1).onDeleteFailure(deleteCandidateItem, e, databaseOperationMetadata); verify(mListener3).onDeleteFailure(deleteCandidateItem, e, databaseOperationMetadata); verifyZeroInteractions(mListener2); }
@Test public void onDeleteException() throws Exception { final KeyedObject deleteCandidateItem = new KeyedObject(); final KeyedObject deletedItem = new KeyedObject(); final Exception e = new Exception(); final DatabaseOperationMetadata databaseOperationMetadata = new DatabaseOperationMetadata(); when(mTableActionAlterations.preDelete(deleteCandidateItem)).thenReturn(Single.just(deleteCandidateItem)); when(mTable.delete(deleteCandidateItem, databaseOperationMetadata)).thenReturn(Single.error(e)); when(mTableActionAlterations.postDelete(deletedItem)).thenReturn(Single.just(deletedItem)); mAbstractTableController.unsubscribe(mListener2); mAbstractTableController.delete(deleteCandidateItem, databaseOperationMetadata); verify(mAnalytics).record(any(ErrorEvent.class)); verify(mListener1).onDeleteFailure(deleteCandidateItem, e, databaseOperationMetadata); verify(mListener3).onDeleteFailure(deleteCandidateItem, e, databaseOperationMetadata); verifyZeroInteractions(mListener2); }
@Test public void onPostDeleteException() throws Exception { final KeyedObject deleteCandidateItem = new KeyedObject(); final KeyedObject deletedItem = new KeyedObject(); final Exception e = new Exception(); final DatabaseOperationMetadata databaseOperationMetadata = new DatabaseOperationMetadata(); when(mTableActionAlterations.preDelete(deleteCandidateItem)).thenReturn(Single.just(deleteCandidateItem)); when(mTable.delete(deleteCandidateItem, databaseOperationMetadata)).thenReturn(Single.just(deletedItem)); when(mTableActionAlterations.postDelete(deletedItem)).thenReturn(Single.error(e)); mAbstractTableController.unsubscribe(mListener2); mAbstractTableController.delete(deleteCandidateItem, databaseOperationMetadata); verify(mAnalytics).record(any(ErrorEvent.class)); verify(mListener1).onDeleteFailure(eq(deleteCandidateItem), any(Exception.class), eq(databaseOperationMetadata)); verify(mListener3).onDeleteFailure(eq(deleteCandidateItem), any(Exception.class), eq(databaseOperationMetadata)); verifyZeroInteractions(mListener2); }