ReceiptTableActionAlterations extends StubTableActionAlterations<Receipt> { @NonNull @Override public Single<Receipt> postDelete(@Nullable final Receipt receipt) { return Single.fromCallable(() -> { if (receipt == null) { throw new Exception("Post delete failed due to a null receipt"); } if (receipt.getFile() != null) { storageManager.delete(receipt.getFile()); } return receipt; }); } ReceiptTableActionAlterations(@NonNull Context context,
                                         @NonNull ReceiptsTable receiptsTable,
                                         @NonNull StorageManager storageManager,
                                         @NonNull Lazy<Picasso> picasso);   ReceiptTableActionAlterations(@NonNull Context context,
                                  @NonNull ReceiptsTable receiptsTable,
                                  @NonNull StorageManager storageManager,
                                  @NonNull BuilderFactory1<Receipt, ReceiptBuilderFactory> receiptBuilderFactoryFactory,
                                  @NonNull Lazy<Picasso> picasso); @NonNull @Override Single<Receipt> preInsert(@NonNull final Receipt receipt); @NonNull @Override Single<Receipt> preUpdate(@NonNull final Receipt oldReceipt, @NonNull final Receipt newReceipt); @NonNull @Override Single<Receipt> postUpdate(@NonNull final Receipt oldReceipt, @Nullable final Receipt newReceipt); @NonNull @Override Single<Receipt> postDelete(@Nullable final Receipt receipt); @NonNull Single<Receipt> preCopy(@NonNull final Receipt receipt, @NonNull final Trip toTrip); void postCopy(@NonNull Receipt oldReceipt, @Nullable Receipt newReceipt); @NonNull Single<Receipt> preMove(@NonNull final Receipt receipt, @NonNull final Trip toTrip); void postMove(@NonNull Receipt oldReceipt, @Nullable Receipt newReceipt);  }
@Test public void postDeleteNull() throws Exception { receiptTableActionAlterations.postDelete(null) .test() .assertNoValues() .assertNotComplete() .assertError(Exception.class); verifyZeroInteractions(storageManager); }
@Test public void postDeleteSuccessWithoutFile() throws Exception { receiptTableActionAlterations.postDelete(receipt) .test() .assertValue(receipt) .assertComplete() .assertNoErrors(); verifyZeroInteractions(storageManager); }
@Test public void postDeleteSuccessWithFile() throws Exception { final File file = new File("abc"); when(receipt.getFile()).thenReturn(file); receiptTableActionAlterations.postDelete(receipt) .test() .assertValue(receipt) .assertComplete() .assertNoErrors(); verify(storageManager).delete(file); }