### Question:
InputValidator { public static <T> T validate(InputStream input, final Class<T> clazz) throws JsonParseException, IOException { JsonFactory factory = mapper.getJsonFactory(); JsonParser parser = null; T obj = null; parser = factory.createJsonParser(input); JsonParser parserWrapper = new JsonParserDelegate(parser) { @Override public String getText() throws IOException, JsonParseException { String str = delegate.getText(); try { JsonInputValidator validator = JsonInputValidatorFactory.getValidator(clazz); if (validator != null) { validator.validate(delegate.getCurrentName(), str); } } catch (OAuthException e) { throw new JsonValidationException(e.getMessage()); } return str; } }; obj = mapper.readValue(parserWrapper, clazz); return obj; }  static T validate(InputStream input, final Class<T> clazz);  }### Answer:
@Test public void when_scope_input_invoke_validate_method_of_scope_validator_class() throws Exception { MockScopeValidator.install(); willDoNothing().given(JsonInputValidatorFactory.getValidator(Scope.class)).validate(anyString(), anyString()); String inputValue = "300"; String testString = "{\"" + Scope.JSON_CC_EXPIRES_IN + "\":\"" + inputValue + "\"}"; InputValidator.validate(new ByteArrayInputStream(testString.getBytes(CharsetUtil.UTF_8)), Scope.class); verify(ScopeValidator.getInstance()).validate(Scope.JSON_CC_EXPIRES_IN, inputValue); MockScopeValidator.deinstall(); }
@Test public void when_application_info_input_invoke_validate_method_of_application_info_validator_class() throws Exception { MockApplicationInfoValidator.install(); willDoNothing().given(JsonInputValidatorFactory.getValidator(ApplicationInfo.class)).validate(anyString(), anyString()); String inputValue = "1"; String testString = "{\"" + ApplicationInfo.JSON_STATUS + "\":\"" + inputValue + "\"}"; InputValidator.validate(new ByteArrayInputStream(testString.getBytes(CharsetUtil.UTF_8)), ApplicationInfo.class); verify(ApplicationInfoValidator.getInstance()).validate(ApplicationInfo.JSON_STATUS, inputValue); MockApplicationInfoValidator.deinstall(); }
@Test public void when_no_validator_do_not_throw_NPE() throws Exception { String testString = "{\"client_id\":\"123456\"}"; InputValidator.validate(new ByteArrayInputStream(testString.getBytes(CharsetUtil.UTF_8)), ClientCredentials.class); }