class MergeRequestRest {

    @GET
    @Produces(MediaType.APPLICATION_JSON)
    @RolesAllowed("user")
    @ApiOperation("Retrieves all MergeRequests in the application")
    public Response getMergeRequests(@QueryParam("sort") String sort,
                              @DefaultValue("false") @QueryParam("ascending") boolean asc,
                              @DefaultValue("false") @QueryParam("accepted") boolean accepted) {
        MergeRequestFilterParams.Builder builder = new MergeRequestFilterParams.Builder();
        if (!StringUtils.isEmpty(sort)) {
            builder.setSortBy(createIRI(sort, vf));
        }
        builder.setAscending(asc).setAccepted(accepted);
        try {
            JSONArray result = JSONArray.fromObject(manager.getMergeRequests(builder.build()).stream()
                    .map(request -> modelToJsonld(request.getModel(), transformer))
                    .map(RestUtils::getObjectFromJsonld)
                    .collect(Collectors.toList()));
            return Response.ok(result).build();
        } catch (IllegalStateException | MobiException ex) {
            throw ErrorUtils.sendError(ex, ex.getMessage(), Response.Status.INTERNAL_SERVER_ERROR);
        }
    }

}

class MergeRequestRestTest  {

    private MergeRequestRest rest;
    private MergeRequestFactory mergeRequestFactory;
    private CommentFactory commentFactory;
    private UserFactory userFactory;
    private ValueFactory vf;
    private ModelFactory mf;
    private ValueConverterRegistry vcr;
    private MergeRequest request1;
    private MergeRequest request2;
    private Comment comment1;
    private Comment comment2;
    private Comment comment3;
    private List<List<Comment>> commentChains;
    private User user;
    private final String CATALOG_IRI;
    private final String RECORD_ID;
    private final String BRANCH_ID;
    private final String doesNotExist;
    private final String invalidIRIString;
    private final String commentText;
    private final String updateCommentText;
    private final String largeComment;
    @Mock
    private MergeRequestManager requestManager;
    @Mock
    private EngineManager engineManager;
    @Mock
    private SesameTransformer transformer;
    @Mock
    private CatalogConfigProvider configProvider;

    @Test
    public void getMergeRequestsWithErrorTest() {

        // Setup
        doThrow(new MobiException()).when(requestManager).getMergeRequests(any(MergeRequestFilterParams.class));

        Response response = target().path("merge-requests").request().get();
        assertEquals(response.getStatus(), 500);
        verify(requestManager).getMergeRequests(any(MergeRequestFilterParams.class));
    }

}