### Question:
RestAuthTextOutputCallbackHandler extends AbstractRestAuthCallbackHandler<TextOutputCallback> { public TextOutputCallback convertFromJson(TextOutputCallback callback, JsonValue jsonCallback) throws RestAuthException { validateCallbackType(CALLBACK_NAME, jsonCallback); return callback; }  TextOutputCallback handle(HttpServletRequest request, HttpServletResponse response,
            JsonValue postBody, TextOutputCallback originalCallback); String getCallbackClassName(); JsonValue convertToJson(TextOutputCallback callback, int index); TextOutputCallback convertFromJson(TextOutputCallback callback, JsonValue jsonCallback);  }### Answer:
@Test public void shouldConvertFromJson() throws RestAuthException { TextOutputCallback textOutputCallback = new TextOutputCallback(TextOutputCallback.INFORMATION, "MESSAGE"); JsonValue jsonTextOutputCallback = JsonValueBuilder.jsonValue() .array("output") .add(JsonValueBuilder.jsonValue().put("value", "MESSAGE").build()) .addLast(JsonValueBuilder.jsonValue().put("value", 0).build()) .put("type", "TextOutputCallback") .build(); TextOutputCallback convertedTextOutputCallback = testOutputRestAuthCallbackHandler.convertFromJson( textOutputCallback, jsonTextOutputCallback); assertEquals(textOutputCallback, convertedTextOutputCallback); assertEquals("MESSAGE", convertedTextOutputCallback.getMessage()); assertEquals(TextOutputCallback.INFORMATION, convertedTextOutputCallback.getMessageType()); }
@Test (expectedExceptions = RestAuthException.class) public void shouldFailToConvertFromJsonWithInvalidType() throws RestAuthException { TextOutputCallback textOutputCallback = new TextOutputCallback(TextOutputCallback.INFORMATION, "MESSAGE"); JsonValue jsonTextOutputCallback = JsonValueBuilder.jsonValue() .array("output") .add(JsonValueBuilder.jsonValue().put("value", "MESSAGE").build()) .addLast(JsonValueBuilder.jsonValue().put("value", 0).build()) .put("type", "PasswordCallback") .build(); testOutputRestAuthCallbackHandler.convertFromJson(textOutputCallback, jsonTextOutputCallback); fail(); }
@Test public void shouldFailToConvertFromJsonWithTypeLowerCase() throws RestAuthException { TextOutputCallback textOutputCallback = new TextOutputCallback(TextOutputCallback.INFORMATION, "MESSAGE"); JsonValue jsonTextOutputCallback = JsonValueBuilder.jsonValue() .array("output") .add(JsonValueBuilder.jsonValue().put("value", "MESSAGE").build()) .addLast(JsonValueBuilder.jsonValue().put("value", 0).build()) .put("type", "tExtoUtputcallback") .build(); TextOutputCallback convertedTextOutputCallback = testOutputRestAuthCallbackHandler.convertFromJson( textOutputCallback, jsonTextOutputCallback); assertEquals(textOutputCallback, convertedTextOutputCallback); assertEquals("MESSAGE", convertedTextOutputCallback.getMessage()); assertEquals(TextOutputCallback.INFORMATION, convertedTextOutputCallback.getMessageType()); }