@Test public void doTransaction() { Function transactionFunction = Mockito.mock(Function.class); FuturePromise promise = Mockito.mock(FuturePromise.class); TransactionHandler transactionHandler = new TransactionHandler(Long.class, transactionFunction, promise); MutableData mutableData = Mockito.mock(MutableData.class); Mockito.when(mutableData.getValue()).thenReturn("test_value"); transactionHandler.doTransaction(mutableData); PowerMockito.verifyStatic(Transaction.class, VerificationModeFactory.times(1)); Transaction.success(Mockito.nullable(MutableData.class)); }
@Override @SuppressWarnings("unchecked") public Transaction.Result doTransaction(MutableData mutableData) { try { if (mutableData.getValue() == null) { mutableData.setValue(transactionFunction.apply((R) DefaultTypeRecognizer.getDefaultValue(dataType))); return Transaction.success(mutableData); } MapConversion mapConversionAnnotation = null; R transactionData; if (promise.getThenConsumer() != null) { mapConversionAnnotation = AnnotationFinder.getMethodAnnotation(MapConversion.class, promise.getThenConsumer()); } if (mapConversionAnnotation != null) { transactionData = (R) mutableData.getValue(mapConversionAnnotation.value()); } else { transactionData = (R) mutableData.getValue(); } mutableData.setValue(transactionFunction.apply(transactionData)); return Transaction.success(mutableData); } catch (Exception e) { GdxFIRLogger.error(TRANSACTION_ERROR, e); return Transaction.abort(); } }
TransactionHandler implements Transaction.Handler { @Override @SuppressWarnings("unchecked") public Transaction.Result doTransaction(MutableData mutableData) { try { if (mutableData.getValue() == null) { mutableData.setValue(transactionFunction.apply((R) DefaultTypeRecognizer.getDefaultValue(dataType))); return Transaction.success(mutableData); } MapConversion mapConversionAnnotation = null; R transactionData; if (promise.getThenConsumer() != null) { mapConversionAnnotation = AnnotationFinder.getMethodAnnotation(MapConversion.class, promise.getThenConsumer()); } if (mapConversionAnnotation != null) { transactionData = (R) mutableData.getValue(mapConversionAnnotation.value()); } else { transactionData = (R) mutableData.getValue(); } mutableData.setValue(transactionFunction.apply(transactionData)); return Transaction.success(mutableData); } catch (Exception e) { GdxFIRLogger.error(TRANSACTION_ERROR, e); return Transaction.abort(); } } }
TransactionHandler implements Transaction.Handler { @Override @SuppressWarnings("unchecked") public Transaction.Result doTransaction(MutableData mutableData) { try { if (mutableData.getValue() == null) { mutableData.setValue(transactionFunction.apply((R) DefaultTypeRecognizer.getDefaultValue(dataType))); return Transaction.success(mutableData); } MapConversion mapConversionAnnotation = null; R transactionData; if (promise.getThenConsumer() != null) { mapConversionAnnotation = AnnotationFinder.getMethodAnnotation(MapConversion.class, promise.getThenConsumer()); } if (mapConversionAnnotation != null) { transactionData = (R) mutableData.getValue(mapConversionAnnotation.value()); } else { transactionData = (R) mutableData.getValue(); } mutableData.setValue(transactionFunction.apply(transactionData)); return Transaction.success(mutableData); } catch (Exception e) { GdxFIRLogger.error(TRANSACTION_ERROR, e); return Transaction.abort(); } } TransactionHandler(Class<?> dataType, Function<R, R> transactionFunction, FuturePromise<Void> promise); }
TransactionHandler implements Transaction.Handler { @Override @SuppressWarnings("unchecked") public Transaction.Result doTransaction(MutableData mutableData) { try { if (mutableData.getValue() == null) { mutableData.setValue(transactionFunction.apply((R) DefaultTypeRecognizer.getDefaultValue(dataType))); return Transaction.success(mutableData); } MapConversion mapConversionAnnotation = null; R transactionData; if (promise.getThenConsumer() != null) { mapConversionAnnotation = AnnotationFinder.getMethodAnnotation(MapConversion.class, promise.getThenConsumer()); } if (mapConversionAnnotation != null) { transactionData = (R) mutableData.getValue(mapConversionAnnotation.value()); } else { transactionData = (R) mutableData.getValue(); } mutableData.setValue(transactionFunction.apply(transactionData)); return Transaction.success(mutableData); } catch (Exception e) { GdxFIRLogger.error(TRANSACTION_ERROR, e); return Transaction.abort(); } } TransactionHandler(Class<?> dataType, Function<R, R> transactionFunction, FuturePromise<Void> promise); @Override @SuppressWarnings("unchecked") Transaction.Result doTransaction(MutableData mutableData); @Override void onComplete(DatabaseError databaseError, boolean committed, DataSnapshot dataSnapshot); }
TransactionHandler implements Transaction.Handler { @Override @SuppressWarnings("unchecked") public Transaction.Result doTransaction(MutableData mutableData) { try { if (mutableData.getValue() == null) { mutableData.setValue(transactionFunction.apply((R) DefaultTypeRecognizer.getDefaultValue(dataType))); return Transaction.success(mutableData); } MapConversion mapConversionAnnotation = null; R transactionData; if (promise.getThenConsumer() != null) { mapConversionAnnotation = AnnotationFinder.getMethodAnnotation(MapConversion.class, promise.getThenConsumer()); } if (mapConversionAnnotation != null) { transactionData = (R) mutableData.getValue(mapConversionAnnotation.value()); } else { transactionData = (R) mutableData.getValue(); } mutableData.setValue(transactionFunction.apply(transactionData)); return Transaction.success(mutableData); } catch (Exception e) { GdxFIRLogger.error(TRANSACTION_ERROR, e); return Transaction.abort(); } } TransactionHandler(Class<?> dataType, Function<R, R> transactionFunction, FuturePromise<Void> promise); @Override @SuppressWarnings("unchecked") Transaction.Result doTransaction(MutableData mutableData); @Override void onComplete(DatabaseError databaseError, boolean committed, DataSnapshot dataSnapshot);  }