### Question:
RestAuthTextInputCallbackHandler extends AbstractRestAuthCallbackHandler<TextInputCallback> { public TextInputCallback convertFromJson(TextInputCallback callback, JsonValue jsonCallback) throws RestAuthException { validateCallbackType(CALLBACK_NAME, jsonCallback); JsonValue input = jsonCallback.get("input"); if (input.size() != 1) { throw new JsonException("JSON Callback does not include a input field"); } JsonValue inputField = input.get(0); String value = inputField.get("value").asString(); callback.setText(value); return callback; }  TextInputCallback handle(HttpServletRequest request, HttpServletResponse response,
            JsonValue postBody, TextInputCallback originalCallback); String getCallbackClassName(); JsonValue convertToJson(TextInputCallback callback, int index); TextInputCallback convertFromJson(TextInputCallback callback, JsonValue jsonCallback);  }### Answer:
@Test public void shouldConvertFromJson() throws RestAuthException { TextInputCallback textInputCallback = new TextInputCallback("Enter text:", "DEFAULT_VALUE"); JsonValue jsonTextInputCallback = JsonValueBuilder.jsonValue() .array("input") .addLast(JsonValueBuilder.jsonValue().put("value", "TEXT_VALUE").build()) .array("output") .add(JsonValueBuilder.jsonValue().put("value", "Enter text:").build()) .addLast(JsonValueBuilder.jsonValue().put("value", "DEFAULT_VALUE").build()) .put("type", "TextInputCallback") .build(); TextInputCallback convertedTextInputCallback = restAuthTextInputCallbackHandler.convertFromJson( textInputCallback, jsonTextInputCallback); assertEquals(textInputCallback, convertedTextInputCallback); assertEquals("Enter text:", convertedTextInputCallback.getPrompt()); assertEquals("DEFAULT_VALUE", convertedTextInputCallback.getDefaultText()); assertEquals("TEXT_VALUE", convertedTextInputCallback.getText()); }
@Test (expectedExceptions = RestAuthException.class) public void shouldFailToConvertFromJsonWithInvalidType() throws RestAuthException { TextInputCallback textInputCallback = new TextInputCallback("Enter text:", "DEFAULT_VALUE"); JsonValue jsonTextInputCallback = JsonValueBuilder.jsonValue() .array("input") .addLast(JsonValueBuilder.jsonValue().put("value", "TEXT_VALUE").build()) .array("output") .add(JsonValueBuilder.jsonValue().put("value", "Enter text:").build()) .addLast(JsonValueBuilder.jsonValue().put("value", "DEFAULT_VALUE").build()) .put("type", "PasswordCallback") .build(); restAuthTextInputCallbackHandler.convertFromJson(textInputCallback, jsonTextInputCallback); fail(); }
@Test public void shouldNotFailToConvertFromJsonWithTypeLowerCase() throws RestAuthException { TextInputCallback textInputCallback = new TextInputCallback("Enter text:", "DEFAULT_VALUE"); JsonValue jsonTextInputCallback = JsonValueBuilder.jsonValue() .array("input") .addLast(JsonValueBuilder.jsonValue().put("value", "TEXT_VALUE").build()) .array("output") .add(JsonValueBuilder.jsonValue().put("value", "Enter text:").build()) .addLast(JsonValueBuilder.jsonValue().put("value", "DEFAULT_VALUE").build()) .put("type", "tExtinpuTcallback") .build(); TextInputCallback convertedTextInputCallback = restAuthTextInputCallbackHandler.convertFromJson( textInputCallback, jsonTextInputCallback); assertEquals(textInputCallback, convertedTextInputCallback); assertEquals("Enter text:", convertedTextInputCallback.getPrompt()); assertEquals("DEFAULT_VALUE", convertedTextInputCallback.getDefaultText()); assertEquals("TEXT_VALUE", convertedTextInputCallback.getText()); }