### Question:
PaymentTypeValidatorContext { public Optional<PaymentTypeValidator> getValidator(String paymentType) { return Optional.ofNullable(context.get(paymentType)); } @Autowired  PaymentTypeValidatorContext(List<PaymentTypeValidator> paymentTypeValidators); Optional<PaymentTypeValidator> getValidator(String paymentType);  }### Answer:
@Test void getValidator() { List<PaymentTypeValidator> paymentTypeValidators = new ArrayList<>(); paymentTypeValidators.add(new SinglePaymentTypeValidatorImpl(null, null, null, null, null)); paymentTypeValidators.add(new PeriodicPaymentTypeValidatorImpl(null, null, null, null, null)); paymentTypeValidators.add(new BulkPaymentTypeValidatorImpl(null, null, null, null, null)); PaymentTypeValidatorContext context = new PaymentTypeValidatorContext(paymentTypeValidators); Optional<PaymentTypeValidator> paymentTypeValidator = context.getValidator(PaymentType.SINGLE.getValue()); assertTrue(paymentTypeValidator.isPresent()); assertTrue(paymentTypeValidator.get() instanceof SinglePaymentTypeValidatorImpl); paymentTypeValidator = context.getValidator(PaymentType.PERIODIC.getValue()); assertTrue(paymentTypeValidator.isPresent()); assertTrue(paymentTypeValidator.get() instanceof PeriodicPaymentTypeValidatorImpl); paymentTypeValidator = context.getValidator(PaymentType.BULK.getValue()); assertTrue(paymentTypeValidator.isPresent()); assertTrue(paymentTypeValidator.get() instanceof BulkPaymentTypeValidatorImpl); paymentTypeValidator = context.getValidator(""); assertFalse(paymentTypeValidator.isPresent()); paymentTypeValidator = context.getValidator(null); assertFalse(paymentTypeValidator.isPresent()); paymentTypeValidator = context.getValidator("unknown method"); assertFalse(paymentTypeValidator.isPresent()); }