### Question:
RestAuthNameCallbackHandler extends AbstractRestAuthCallbackHandler<NameCallback> { public NameCallback convertFromJson(NameCallback 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.setName(value); return callback; }  String getCallbackClassName(); NameCallback handle(HttpServletRequest request, HttpServletResponse response,
            JsonValue postBody, NameCallback originalCallback); JsonValue convertToJson(NameCallback callback, int index); NameCallback convertFromJson(NameCallback callback, JsonValue jsonCallback);  }### Answer:
@Test public void shouldConvertFromJson() throws RestAuthException { NameCallback nameCallback = new NameCallback("Enter username:"); JsonValue jsonNameCallback = JsonValueBuilder.jsonValue() .array("input") .addLast(JsonValueBuilder.jsonValue().put("value", "USERNAME").build()) .array("output") .addLast(JsonValueBuilder.jsonValue().put("value", "Enter username:").build()) .put("type", "NameCallback") .build(); NameCallback convertedNameCallback = restAuthNameCallbackHandler.convertFromJson(nameCallback, jsonNameCallback); Assert.assertEquals(nameCallback, convertedNameCallback); Assert.assertEquals("Enter username:", convertedNameCallback.getPrompt()); Assert.assertEquals("USERNAME", convertedNameCallback.getName()); }
@Test (expectedExceptions = RestAuthException.class) public void shouldFailToConvertFromJsonWithInvalidType() throws RestAuthException { NameCallback nameCallback = new NameCallback("Enter username:"); JsonValue jsonNameCallback = JsonValueBuilder.jsonValue() .array("input") .addLast(JsonValueBuilder.jsonValue().put("value", "USERNAME").build()) .array("output") .addLast(JsonValueBuilder.jsonValue().put("value", "Enter username:").build()) .put("type", "PasswordCallback") .build(); restAuthNameCallbackHandler.convertFromJson(nameCallback, jsonNameCallback); fail(); }
@Test public void shouldNotFailToConvertFromJsonWithTypeLowerCase() throws RestAuthException { NameCallback nameCallback = new NameCallback("Enter username:"); JsonValue jsonNameCallback = JsonValueBuilder.jsonValue() .array("input") .addLast(JsonValueBuilder.jsonValue().put("value", "USERNAME").build()) .array("output") .addLast(JsonValueBuilder.jsonValue().put("value", "Enter username:").build()) .put("type", "namecallback") .build(); NameCallback convertedNameCallback = restAuthNameCallbackHandler.convertFromJson(nameCallback, jsonNameCallback); Assert.assertEquals(nameCallback, convertedNameCallback); Assert.assertEquals("Enter username:", convertedNameCallback.getPrompt()); Assert.assertEquals("USERNAME", convertedNameCallback.getName()); }