UriInfo uriInfo = mock(UriInfo.class);
FilterExpression filter = mock(FilterExpression.class);
when(filter.getExpressionString()).thenReturn("wrong");
when(uriInfo.getFilter()).thenReturn(filter);
ExpressionParserException exception = mock(ExpressionParserException.class);
when(exception.getMessageReference()).thenReturn(ExpressionParserException.COMMON_ERROR);
when(exception.getStackTrace()).thenReturn(new StackTraceElement[] {
new StackTraceElement("class", "method", "file", 42) });
CommonExpression filterTree = mock(CommonExpression.class);
when(filterTree.getUriLiteral()).thenReturn("wrong");
when(exception.getFilterTree()).thenReturn(filterTree);
final ODataResponse response =
new ODataDebugResponseWrapper(context, wrappedResponse, uriInfo, exception,
ODataDebugResponseWrapper.ODATA_DEBUG_JSON)
.wrapResponse();
String entity = StringHelper.inputStreamToString((InputStream) response.getEntity());
assertEquals(EXPECTED.replace("}}}",
"}},\"uri\":{\"error\":{\"filter\":\"wrong\"},\"filter\":null},"
+ "\"stacktrace\":{\"exceptions\":[{\"class\":\"" + exception.getClass().getName() + "\","
+ "\"message\":\"Error while parsing a ODATA expression.\","
+ "\"invocation\":{\"class\":\"class\",\"method\":\"method\",\"line\":42}}],"
+ "\"stacktrace\":[{\"class\":\"class\",\"method\":\"method\",\"line\":42}]}}"),
entity);
}