### Question:
KaptchaPluginService { public Map<String, String> validateCaptcha(UserDto userDto, Long pluginId) { String captcha = userDto.getCaptchas().get(getFormElementId(String.valueOf(pluginId))); if (!isValid(captcha)) { ResourceBundle resourceBundle = ResourceBundle.getBundle("org.jtalks.jcommune.plugin.kaptcha.messages", userDto.getLanguage().getLocale()); String fieldName = getFormFieldName(String.valueOf(pluginId)); return new ImmutableMap.Builder<String, String>().put(fieldName, resourceBundle.getString("validation.captcha.wrong")).build(); } return new HashMap<>(); } KaptchaPluginService(int width, int height, int length, String possibleSymbols); Map<String, String> validateCaptcha(UserDto userDto, Long pluginId); String getHtml(HttpServletRequest request, String pluginId, Locale locale); void refreshCaptchaImage(HttpServletRequest request, HttpServletResponse response); void removeCurrentCaptcha();  }### Answer:
@Test public void testNoCoincidenceCaptchaWithInputValue() throws Exception { UserDto userDto = createUserDto(); String captchaText = "1234"; session.setAttribute(Constants.KAPTCHA_SESSION_KEY, captchaText); RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(request)); Map<String, String> errors = service.validateCaptcha(userDto, 1L); assertFalse(errors.isEmpty(), "Validation of captcha with valid value should not return any errors."); }
@Test public void testCoincidenceCaptchaWithInputValue() throws Exception { UserDto userDto = createUserDto(); session.setAttribute(Constants.KAPTCHA_SESSION_KEY, GENERATED_CAPTCHA_TEXT); RequestContextHolder.setRequestAttributes(new ServletRequestAttributes(request)); Map<String, String> errors = service.validateCaptcha(userDto, 1L); assertTrue(errors.isEmpty(), "Validation of captcha with valid value should not return any errors."); }
@Test public void testValidateCaptchaWhenImagesInBrowserIsDisabled() { UserDto userDto = createUserDto(); session.setAttribute(Constants.KAPTCHA_SESSION_KEY, null); Map<String, String> errors = service.validateCaptcha(userDto, 1L); assertFalse(errors.isEmpty()); }