### Question:
RestAuthTextOutputCallbackHandler extends AbstractRestAuthCallbackHandler<TextOutputCallback> { public JsonValue convertToJson(TextOutputCallback callback, int index) { final String message = callback.getMessage(); final int messageType = callback.getMessageType(); final JsonValue jsonValue = JsonValueBuilder.jsonValue() .put("type", CALLBACK_NAME) .array("output") .add(createOutputField("message", message)) .addLast(createOutputField("messageType", String.valueOf(messageType))) .build(); return jsonValue; }  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 shouldConvertToJson() throws RestAuthException { TextOutputCallback textOutputCallback = new TextOutputCallback(TextOutputCallback.INFORMATION, "MESSAGE"); JsonValue jsonObject = testOutputRestAuthCallbackHandler.convertToJson(textOutputCallback, 1); assertEquals("TextOutputCallback", jsonObject.get("type").asString()); assertNotNull(jsonObject.get("output")); assertEquals(2, jsonObject.get("output").size()); assertEquals("MESSAGE", jsonObject.get("output").get(0).get("value").asString()); assertEquals(TextOutputCallback.INFORMATION, Integer.parseInt(jsonObject.get("output").get(1).get("value").asString())); assertEquals(2, jsonObject.size()); }
@Test public void shouldConvertToJsonAndEscapeCharacters() throws RestAuthException, JSONException { final String script = "for (var i = 0; i < 10; i++) { alert(\"alert\"); }"; TextOutputCallback textOutputCallback = new TextOutputCallback(TextOutputCallback.INFORMATION, script); JsonValue jsonObject = testOutputRestAuthCallbackHandler.convertToJson(textOutputCallback, 1); assertEquals("TextOutputCallback", jsonObject.get("type").asString()); assertNotNull(jsonObject.get("output")); assertEquals(2, jsonObject.get("output").size()); assertEquals(script, jsonObject.get("output").get(0).get("value").asString()); assertEquals(TextOutputCallback.INFORMATION, Integer.parseInt(jsonObject.get("output").get(1).get("value").asString())); assertEquals(2, jsonObject.size()); JSONObject parsed = new JSONObject(jsonObject.toString()); assertEquals(script, parsed.getJSONArray("output").getJSONObject(0).getString("value")); }