### Question:
MethodValidatorController { public MethodValidator getMethod(String methodName) { return Optional.ofNullable(methodValidatorContext.get(methodName)).orElse(defaultMethodValidator); } @Autowired  MethodValidatorController(List<MethodValidator> methodValidators, DefaultMethodValidatorImpl defaultMethodValidator); MethodValidator getMethod(String methodName);  }### Answer:
@Test void getMethod() { List<MethodValidator> methodValidators = new ArrayList<>(); methodValidators.add(new ConsentMethodValidatorImpl(null, null)); methodValidators.add(new PaymentMethodValidatorImpl(null, null)); methodValidators.add(new CancelPaymentMethodValidatorImpl(null, null)); DefaultMethodValidatorImpl defaultMethodValidator = new DefaultMethodValidatorImpl(null); MethodValidatorController controller = new MethodValidatorController(methodValidators, defaultMethodValidator); MethodValidator methodValidator = controller.getMethod("_createConsent"); assertTrue(methodValidator instanceof ConsentMethodValidatorImpl); methodValidator = controller.getMethod("_initiatePayment"); assertTrue(methodValidator instanceof PaymentMethodValidatorImpl); methodValidator = controller.getMethod("_cancelPayment"); assertTrue(methodValidator instanceof CancelPaymentMethodValidatorImpl); methodValidator = controller.getMethod(""); assertTrue(methodValidator instanceof DefaultMethodValidatorImpl); methodValidator = controller.getMethod(null); assertTrue(methodValidator instanceof DefaultMethodValidatorImpl); methodValidator = controller.getMethod("unknown method"); assertNotNull(methodValidator); }