什么 - 在Junit中错过了While循环条件的所有2个分支

时间:2014-11-13 08:12:16

标签: java junit code-coverage

以下while循环错过了什么junit条件?

CompanyService.java:

    @GET
@Path("/services")
@Produces(MediaType.APPLICATION_JSON)
public Response getcompanyData(@QueryParam("comp") final String comp,
        @Context HttpServletRequest request) {
    Response response = null;
    String company= null;
    if (comp!= null && !comp.isEmpty()) {
        company= comp;
    } else {
        company= getCompanyReqHeader(request);
    }

    response = responseBuilder.getcompanyData(company); // here calls getCompanyData of ResponseBuilder class
    return response ;
}


   public static String getCompanyReqHeader(HttpServletRequest request) {  
   //  code to get the companyname from request header
   }

CompanyServiceTest.java

    private static final String SVC_URL=  "http://localhost:8080/services/getcompanyData?comp=xxx"
@Test
public void testCompanyService() throws IOException, MalformedURLException {
    BufferedReader br = null;       
    StringBuilder response = null;      
    Assert.assertNotNull(SVC_URL);
    URL url = new URL(SVC_URL);
    Assert.assertNotNull(url);
    HttpURLConnection conn = (HttpURLConnection) url.openConnection();      
    Assert.assertNotNull(conn);     
    Assert.assertSame(200, conn.getResponseCode());                 
    br = new BufferedReader(new InputStreamReader(conn.getInputStream()));      
    Assert.assertNotNull(br);
    response = new StringBuilder();             
    String inputLine = null;    

    while ((inputLine = br.readLine()) != null) {               
        response.append(inputLine);
    }               
    conn.disconnect();
}

“所有2个分支错过”标记显示在上面的循环条件。 任何人都可以建议Junit错过上述while循环的条件

0 个答案:

没有答案