### Question:
RestAuthLanguageCallbackHandler extends AbstractRestAuthCallbackHandler<LanguageCallback> { public LanguageCallback convertFromJson(LanguageCallback callback, JsonValue jsonCallback) throws RestAuthException { validateCallbackType(CALLBACK_NAME, jsonCallback); JsonValue input = jsonCallback.get("input"); if (input.size() != 2) { throw new JsonException("JSON Callback does not include the required input fields"); } String language = null; String country = null; for (int i = 0; i < input.size(); i++) { JsonValue inputField = input.get(i); String value = inputField.get("value").asString(); if (i == 0) { language = value; } else { country = value; } } callback.setLocale(createLocale(language, country)); return callback; }  LanguageCallback handle(HttpServletRequest request, HttpServletResponse response,
            JsonValue postBody, LanguageCallback originalCallback); String getCallbackClassName(); JsonValue convertToJson(LanguageCallback callback, int index); LanguageCallback convertFromJson(LanguageCallback callback, JsonValue jsonCallback);  }### Answer:
@Test public void shouldConvertFromJson() throws RestAuthException { LanguageCallback languageCallback = new LanguageCallback(); JsonValue jsonLanguageCallback = JsonValueBuilder.jsonValue() .array("input") .add(JsonValueBuilder.jsonValue().put("value", "language").build()) .addLast(JsonValueBuilder.jsonValue().put("value", "COUNTRY").build()) .put("type", "LanguageCallback") .build(); LanguageCallback convertedLanguageCallback = restAuthLanguageCallbackHandler.convertFromJson( languageCallback, jsonLanguageCallback); assertEquals(languageCallback, convertedLanguageCallback); Assert.assertNotNull(convertedLanguageCallback.getLocale()); assertEquals("language", convertedLanguageCallback.getLocale().getLanguage()); assertEquals("COUNTRY", convertedLanguageCallback.getLocale().getCountry()); }
@Test (expectedExceptions = RestAuthException.class) public void shouldFailToConvertFromJsonWithInvalidType() throws RestAuthException { LanguageCallback languageCallback = new LanguageCallback(); JsonValue jsonLanguageCallback = JsonValueBuilder.jsonValue() .array("input") .add(JsonValueBuilder.jsonValue().put("value", "language").build()) .addLast(JsonValueBuilder.jsonValue().put("value", "COUNTRY").build()) .put("type", "PasswordCallback") .build(); restAuthLanguageCallbackHandler.convertFromJson(languageCallback, jsonLanguageCallback); fail(); }
@Test public void shouldNotFailToConvertFromJsonWithTypeLowerCase() throws RestAuthException { LanguageCallback languageCallback = new LanguageCallback(); JsonValue jsonLanguageCallback = JsonValueBuilder.jsonValue() .array("input") .add(JsonValueBuilder.jsonValue().put("value", "lAngUage").build()) .addLast(JsonValueBuilder.jsonValue().put("value", "COuntRY").build()) .put("type", "lanGuagecalLback") .build(); LanguageCallback convertedLanguageCallback = restAuthLanguageCallbackHandler.convertFromJson( languageCallback, jsonLanguageCallback); assertEquals(languageCallback, convertedLanguageCallback); Assert.assertNotNull(convertedLanguageCallback.getLocale()); assertEquals("language", convertedLanguageCallback.getLocale().getLanguage()); assertEquals("COUNTRY", convertedLanguageCallback.getLocale().getCountry()); }