### Question:
ChargeDefinitionCommandHandler { @SuppressWarnings("unused") @Transactional @CommandHandler(logStart = CommandLogLevel.INFO, logFinish = CommandLogLevel.INFO) @EventEmitter(selectorName = EventConstants.SELECTOR_NAME, selectorValue = EventConstants.POST_CHARGE_DEFINITION) public ChargeDefinitionEvent process(final CreateChargeDefinitionCommand command) { final ChargeDefinition chargeDefinition = command.getInstance(); final String productIdentifier = command.getProductIdentifier(); final ProductEntity productEntity = productRepository.findByIdentifier(productIdentifier) .orElseThrow(() -> ServiceException.badRequest("The given product identifier does not refer to a product {0}", productIdentifier)); final SegmentRange segmentRange = getSegmentRange(chargeDefinition, productIdentifier); final ChargeDefinitionEntity chargeDefinitionEntity = ChargeDefinitionMapper.map(productEntity, chargeDefinition, segmentRange.fromSegment, segmentRange.toSegment); chargeDefinitionRepository.save(chargeDefinitionEntity); return new ChargeDefinitionEvent( command.getProductIdentifier(), command.getInstance().getIdentifier()); } @Autowired  ChargeDefinitionCommandHandler(
      final ProductRepository productRepository,
      final ChargeDefinitionRepository chargeDefinitionRepository,
      final BalanceSegmentRepository balanceSegmentRepository); @SuppressWarnings("unused") @Transactional @CommandHandler(logStart = CommandLogLevel.INFO, logFinish = CommandLogLevel.INFO) @EventEmitter(selectorName = EventConstants.SELECTOR_NAME, selectorValue = EventConstants.POST_CHARGE_DEFINITION) ChargeDefinitionEvent process(final CreateChargeDefinitionCommand command); @SuppressWarnings("unused") @Transactional @CommandHandler(logStart = CommandLogLevel.INFO, logFinish = CommandLogLevel.INFO) @EventEmitter(selectorName = EventConstants.SELECTOR_NAME, selectorValue = EventConstants.PUT_CHARGE_DEFINITION) ChargeDefinitionEvent process(final ChangeChargeDefinitionCommand command); @SuppressWarnings("unused") @Transactional @CommandHandler(logStart = CommandLogLevel.INFO, logFinish = CommandLogLevel.INFO) @EventEmitter(selectorName = EventConstants.SELECTOR_NAME, selectorValue = EventConstants.DELETE_PRODUCT_CHARGE_DEFINITION) ChargeDefinitionEvent process(final DeleteProductChargeDefinitionCommand command);  }### Answer:
@Test public void processDeleteHandlesCaseOfMissingChargeCorrectly() throws Exception { final String productIdentifier = "bibbledybobbeldy"; final String chargeDefinitionIdentifier = "booboo"; final ChargeDefinitionRepository chargeDefinitionRepositoryMock = Mockito.mock(ChargeDefinitionRepository.class); Mockito.doReturn(Optional.empty()) .when(chargeDefinitionRepositoryMock) .findByProductIdAndChargeDefinitionIdentifier(productIdentifier, chargeDefinitionIdentifier); final BalanceSegmentRepository balanceSegmentRepository = Mockito.mock(BalanceSegmentRepository.class); final ChargeDefinitionCommandHandler testSubject = new ChargeDefinitionCommandHandler(null, chargeDefinitionRepositoryMock, balanceSegmentRepository); try { testSubject.process(new DeleteProductChargeDefinitionCommand(productIdentifier, chargeDefinitionIdentifier)); Assert.assertTrue(false); } catch (final ServiceException e) { Assert.assertTrue(e.getMessage().contains(productIdentifier)); Assert.assertTrue(e.getMessage().contains(chargeDefinitionIdentifier)); } }