Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.devbliss.doctest.machine;
  
  import java.util.List;
  
  
 
Default implementation of DocTestMachine.

This class ownes a list of com.devbliss.doctest.items.DocItem : listItem. Each time a say method is called, a com.devbliss.doctest.items.DocItem is added to listItem.
At the end of the workflow, the method endDocTest() is called and uses a com.devbliss.doctest.renderer.ReportRenderer to render the listItem .

Author(s):
bmary
 
 public class DocTestMachineImpl implements DocTestMachine {
 
     // The name of the report.
     // Usually I don't like that, but we don't have another option to generate
     // the name under test because of the static way JUnit runs files and uses
     // AfterClass and BeforeClass.
     private String fileName;
 
     public StringBuffer outputOfTestsBuffer = new StringBuffer();
     private final List<DocItemlistItem;
 
     private final ReportRenderer reportRenderer;
     private final JSONHelper jsonHelper;
     private final UriHelper uriHelper;
     private final HeadersHelper headersHelper;
     private String introduction;
 
     @Inject
     public DocTestMachineImpl(
             ReportRenderer reportRenderer,
             JSONHelper jsonHelper,
             UriHelper uriHelper,
             HeadersHelper headersHelper) {
         this. = uriHelper;
          = new ArrayList<DocItem>();
         this. = reportRenderer;
         this. = jsonHelper;
         this. = headersHelper;
     }
 
     public void beginDoctest(String fileNameString introduction) {
         if (this. == null) {
             this. = fileName;
             if (this. == null) {
                 this. = introduction;
             }
         }
     }
 
     public void endDocTest() throws Exception {
          = null;
          = null;
     }
 
     public void prepareDocTest() {
         getListItem().clear();
     }
 
     protected List<DocItemgetListItem() {
         return ;
     }
 
     public void say(String say) {
         .add(new TextDocItem(say));
     }
 
     public void sayNextSectionTitle(String sectionName) {
         .add(new SectionDocItem(sectionName));
     }

    
if apiRequest's uri is null, no documentation for this request/response will be created
    public void sayRequest(ApiRequest apiRequestString payloadList<StringheadersToShow)
            throws JSONException {
        if (apiRequest.uri != null) {
            .add(new RequestDocItem(apiRequest.httpMethod
                    .uriToString(apiRequest.uri), validateAndPrettifyJson(payload), 
                    .filter(apiRequest.headersheadersToShow)));
        }
    }

    
if apiRequest's uri is null, no documentation for this request/response will be created
    public void sayUploadRequest(ApiRequest apiRequestString fileNameString fileBody,
            long sizeString mimeTypeList<StringheadersToShow) {
        if (apiRequest.uri != null) {
            .add(new RequestUploadDocItem(apiRequest.httpMethod
                    .uriToString(apiRequest.uri), fileNamefileBodysizemimeType
                    .filter(apiRequest.headersheadersToShow)));
        }
    }

    
add new item for doctest and filter the headers from the ApiResponse
    public void sayResponse(ApiResponse responseList<StringheadersToShowthrows Exception {
        .add(new ResponseDocItem(responsevalidateAndPrettifyJson(response.payload),
                .filter(response.headersheadersToShow)));
    }
    public void sayVerify(String condition) {
        .add(new AssertDocItem(condition));
    }
    public void sayPreformatted(String preformattedText) {
        .add(new JsonDocItem(preformattedText));
    }

    
Checks whether the given java.lang.String is a valid Json. If the json is valid, it will be prettyfied.

Parameters:
payload
Returns:
    private String validateAndPrettifyJson(String payload) {
        String payloadToShow;
        if (.isJsonValid(payload)) {
            payloadToShow = .prettyPrintJson(payload);
        } else if (null == payload) {
            payloadToShow = "";
        } else {
            payloadToShow = payload;
        }
        return payloadToShow;
    }
    public void say(String sayString[] strings) {
        .add(new MultipleTextDocItem(saystrings));
    }
New to GrepCode? Check out our FAQ X