### Question:
DataObjectRequestProcessor implements RequestProcessor<DataObjectResponse<T>, DataObjectRequest<T>> { @Override public DataObjectResponse<T> handlePOST(DataObjectRequest<T> request) { if(getRequestValidator() != null) getRequestValidator().validatePOST(request); T dataObject = defaultFieldsOnCreate(request.getDataObject()); DefaultDataObjectResponse<T> response = new DefaultDataObjectResponse<>(); VisibilityFilter<T, DataObjectRequest<T>> visibilityFilter = visibilityFilterMap.get(VisibilityMethod.POST); if(!visibilityFilter.isVisible(request, dataObject)) { response.setErrorResponse(ErrorResponseFactory.unauthorized(String.format(AUTHORIZATION_EXCEPTION, dataObject.getCustomerId()), request.getCID())); return response; } try { T persistedObject = objectPersister.persist(dataObject); if(persistedObject == null) { Throwable throwable = new RuntimeException(UNABLE_TO_CREATE_EXCEPTION); response.setErrorResponse(ErrorResponseFactory.buildErrorResponse(throwable, 400, request.getCID())); return response; } response.add(persistedObject); } catch(PersistenceException e) { BadRequestException badRequestException = new BadRequestException(UNABLE_TO_CREATE_EXCEPTION, e); response.setErrorResponse(ErrorResponseFactory.badRequest(badRequestException, request.getCID())); } return response; } DataObjectRequestProcessor(ObjectPersister<T> objectPersister, DataObjectValidator<T, DataObjectRequest<T>> validator);  DataObjectRequestProcessor(ObjectPersister<T> objectPersister); @Override DataObjectResponse<T> handleGET(DataObjectRequest<T> request); @Override DataObjectResponse<T> handlePOST(DataObjectRequest<T> request); @Override DataObjectResponse<T> handlePUT(DataObjectRequest<T> request); DataObjectResponse<T> handlePUT(DataObjectRequest<T> request, T previouslyRetrievedObject); @Override DataObjectResponse<T> handleDELETE(DataObjectRequest<T> request); DataObjectRequestProcessor<T> setVisibilityFilterMap(
        VisibilityFilterMap<T, DataObjectRequest<T>> map); DataObjectRequestProcessor<T> setVisibilityFilter(VisibilityMethod method,
        VisibilityFilter<T, DataObjectRequest<T>> filter); RequestValidator<DataObjectRequest<T>> getRequestValidator(); void setRequestValidator(RequestValidator<DataObjectRequest<T>> requestValidator); ObjectPersister<T> getObjectPersister(); static final String OBJECT_NOT_FOUND_EXCEPTION; static final String AUTHORIZATION_EXCEPTION; static final String UNABLE_TO_CREATE_EXCEPTION; static final String UNABLE_TO_UPDATE_EXCEPTION; static final String UNABLE_TO_DELETE_EXCEPTION; }### Answer:
@Test public void testPOSTInvalidVisibility() { request.setDataObject(new SimpleObject("", "customerId")); doReturn(false).when(mockVisibilityFilter).isVisible(any(), any()); DataObjectResponse<SimpleObject> response = processor.handlePOST(request); Assert.assertTrue(response.isError()); Assert.assertEquals(response.getErrorResponse().getTitle(), "UnauthorizedException"); }
@Test public void testPOSTPersistNullResult() throws PersistenceException { request.setDataObject(new SimpleObject("", "customerId")); doReturn(true).when(mockVisibilityFilter).isVisible(any(), any()); doReturn(null).when(mockObjectPersister).persist(any()); DataObjectResponse<SimpleObject> response = processor.handlePOST(request); Assert.assertTrue(response.isError()); Assert.assertEquals(response.getErrorResponse().getTitle(), "RuntimeException"); }
@Test public void testPOSTPersistenceException() throws PersistenceException { request.setDataObject(new SimpleObject("", "customerId")); doReturn(true).when(mockVisibilityFilter).isVisible(any(), any()); doThrow(new PersistenceException("")).when(mockObjectPersister).persist(any()); DataObjectResponse<SimpleObject> response = processor.handlePOST(request); Assert.assertTrue(response.isError()); Assert.assertEquals(response.getErrorResponse().getTitle(), "BadRequestException"); }