2017-05-04 1 views
1

우수한 PITest 프레임 워크를 사용하고 있습니다. PITest의 Sonars "// NOSONAR"에 해당하는 항목이 있는지 궁금 해서요. 특정 줄이 PITest 범위에서 제외되었으므로 (보고서에 빨간색이 표시되지 않습니다)? 메소드와 클래스가 제외 될 수 있다는 것을 알고 있습니다. 라인 레벨에서 좀 더 세밀한 것을 찾고 있습니다.PITest의 특정 코드 줄 제외

는 다음과 내가 가진 사용하는 경우와 같이 :

public enum FinancialStatementUserType { 
CONSUMER, BUSINESS, RETAILER; 

}

public static RecipientType toRecipientType(FinancialStatementUserType userType) { 
     Assert.notNull(userType, "userType is null"); 

     switch (userType) { 
      case BUSINESS: 
      case CONSUMER: 
       return RecipientType.CustomerPerson; 
      case RETAILER: 
      return RecipientType.Seller; 

     default: 
      throw new IllegalStateException(String.format("No RecipientType for financial statement user type: %s", userType)); 
    } 
} 

내가 가진 문제는 도달 할 수없는 '기본'절 모든 열거 현재 switch 문에 포함되어 있기 때문에 . 우리가 'detault'문을 추가 한 이유는 좋은 연습이라는 사실 외에도 미래에 enum이 확장되는 경우입니다.

아이디어가 있으십니까?

답변

1

이 코드는 컴파일 된 바이트 코드에서 작동하므로 코드에서 태그와 주석에 액세스 할 수 없으므로 컴파일 타임에 손실됩니다.

상자 밖에서 할 수있는 가장 미세한 제외 항목은 메소드 수준입니다.

특별한 경우에 대해 강조 할 수있는 옵션은 코딩 스타일을 변경하는 것입니다.

RecipientType 유형과 FinancialStatementUserType이 강하게 관련된 경우 관계를 명시 적으로 지정하여 논리가 새 FinancialStatementUserType의 추가를 중단하지 않도록 할 수 있습니다.

enum FinancialStatementUserType { 
    CONSUMER(RecipientType.CustomerPerson), 
    BUSINESS(RecipientType.CustomerPerson), 
    RETAILER(RecipientType.Seller); 

    private final RecipientType recipientType; 

    FinancialStatementUserType(String recipientType) { 
    this.recipientType = recipientType; 
    } 

    RecipientType recipientType() { 
    return recipientType; 
    } 

}