### Question:
DepositGenerateAndRegisterCommand implements Runnable { @Override public void run() { final GenerateAction generateAction = generateParams.createGenerateAction(verboseOutputParam.isVerboseOutputEnabled()); try (final RegisterAction registerAction = registerParams.createRegisterAction(verboseOutputParam.isVerboseOutputEnabled())) { registerAction.displayConfirmation(generateParams.getValidatorCount()); final List<SafeFuture<TransactionReceipt>> transactionReceipts = generateAction .generateKeysStream() .map(registerValidator(registerAction)) .collect(Collectors.toList()); SafeFuture.allOf(transactionReceipts.toArray(SafeFuture[]::new)).get(2, TimeUnit.MINUTES); } catch (final Throwable t) { SUB_COMMAND_LOG.sendDepositFailure(t); shutdownFunction.accept(1); } shutdownFunction.accept(0); } DepositGenerateAndRegisterCommand(); @VisibleForTesting  DepositGenerateAndRegisterCommand(
      final Consumer<Integer> shutdownFunction,
      final RegisterParams registerParams,
      final GenerateParams generateParams,
      final VerboseOutputParam verboseOutputParam); @Override void run();  }### Answer:
@Test public void generatesAKeysAndRegistersIt() { final List<ValidatorKeys> validatorKeys = createValidatorKeys(1); when(generateParams.getValidatorCount()).thenReturn(1); when(generateAction.generateKeysStream()).thenReturn(validatorKeys.stream()); when(registerAction.sendDeposit(any(), any())) .thenReturn(SafeFuture.completedFuture(new TransactionReceipt())); final DepositGenerateAndRegisterCommand depositGenerateAndRegisterCommand = new DepositGenerateAndRegisterCommand( shutdownFunction, registerParams, generateParams, new VerboseOutputParam(true)); depositGenerateAndRegisterCommand.run(); final ValidatorKeys keys = validatorKeys.get(0); verify(generateAction).generateKeysStream(); verify(registerAction) .sendDeposit(keys.getValidatorKey(), keys.getWithdrawalKey().getPublicKey()); verify(registerAction).close(); }
@Test public void generatesMultipleKeysAndRegistersThem() { final int noOfKeysToCreate = 3; final List<ValidatorKeys> validatorKeys = createValidatorKeys(noOfKeysToCreate); when(generateParams.getValidatorCount()).thenReturn(noOfKeysToCreate); when(generateAction.generateKeysStream()).thenReturn(validatorKeys.stream()); when(registerAction.sendDeposit(any(), any())) .thenReturn(SafeFuture.completedFuture(new TransactionReceipt())); final DepositGenerateAndRegisterCommand depositGenerateAndRegisterCommand = new DepositGenerateAndRegisterCommand( shutdownFunction, registerParams, generateParams, new VerboseOutputParam(true)); depositGenerateAndRegisterCommand.run(); verify(generateAction).generateKeysStream(); for (int i = 0; i < noOfKeysToCreate; i++) { verify(registerAction) .sendDeposit( validatorKeys.get(i).getValidatorKey(), validatorKeys.get(i).getWithdrawalKey().getPublicKey()); } verify(registerAction).close(); }
@Test public void generatesAndRegistersWithoutDisplayConfirmation() { final DepositGenerateAndRegisterCommand depositGenerateAndRegisterCommand = new DepositGenerateAndRegisterCommand( shutdownFunction, registerParams, generateParams, new VerboseOutputParam(false)); depositGenerateAndRegisterCommand.run(); verify(generateParams).createGenerateAction(false); verify(registerParams).createRegisterAction(false); verify(generateAction).generateKeysStream(); }
@Test public void generatesAndRegistersWithDisplayConfirmation() { final DepositGenerateAndRegisterCommand depositGenerateAndRegisterCommand = new DepositGenerateAndRegisterCommand( shutdownFunction, registerParams, generateParams, new VerboseOutputParam(true)); depositGenerateAndRegisterCommand.run(); verify(generateParams).createGenerateAction(true); verify(registerParams).createRegisterAction(true); verify(generateAction).generateKeysStream(); }