@Test public void test_new_reliability_rating() { withNoIssues().assertThatLeakValueIs(CoreMetrics.NEW_RELIABILITY_RATING, Rating.A); with( newGroup(RuleType.BUG).setSeverity(Severity.INFO).setCount(3).setInLeak(true), newGroup(RuleType.BUG).setSeverity(Severity.MINOR).setCount(1).setInLeak(true), // not in leak newGroup(RuleType.BUG).setSeverity(Severity.BLOCKER).setInLeak(false), // not bug newGroup(RuleType.CODE_SMELL).setSeverity(Severity.BLOCKER).setInLeak(true), // exclude resolved newResolvedGroup(RuleType.BUG).setSeverity(Severity.BLOCKER).setInLeak(true)) // highest severity of bugs on leak period is minor -> B .assertThatLeakValueIs(CoreMetrics.NEW_RELIABILITY_RATING, Rating.B); }
@Test public void test_new_security_rating() { withNoIssues().assertThatLeakValueIs(CoreMetrics.NEW_SECURITY_RATING, Rating.A); with( newGroup(RuleType.VULNERABILITY).setSeverity(Severity.INFO).setCount(3).setInLeak(true), newGroup(RuleType.VULNERABILITY).setSeverity(Severity.MINOR).setCount(1).setInLeak(true), // not in leak newGroup(RuleType.VULNERABILITY).setSeverity(Severity.BLOCKER).setInLeak(false), // not vulnerability newGroup(RuleType.CODE_SMELL).setSeverity(Severity.BLOCKER).setInLeak(true), // exclude resolved newResolvedGroup(RuleType.VULNERABILITY).setSeverity(Severity.BLOCKER).setInLeak(true)) // highest severity of bugs on leak period is minor -> B .assertThatLeakValueIs(CoreMetrics.NEW_SECURITY_RATING, Rating.B); }
@Test public void test_reliability_rating() { withNoIssues() .assertThatValueIs(CoreMetrics.RELIABILITY_RATING, Rating.A); with( newGroup(RuleType.BUG).setSeverity(Severity.CRITICAL).setCount(1), newGroup(RuleType.BUG).setSeverity(Severity.MINOR).setCount(5), // excluded, not a bug newGroup(RuleType.CODE_SMELL).setSeverity(Severity.BLOCKER).setCount(3)) // highest severity of bugs is CRITICAL --> D .assertThatValueIs(CoreMetrics.RELIABILITY_RATING, Rating.D); with( newGroup(RuleType.CODE_SMELL).setSeverity(Severity.MAJOR).setCount(3), newGroup(RuleType.VULNERABILITY).setSeverity(Severity.CRITICAL).setCount(5)) // no bugs --> A .assertThatValueIs(CoreMetrics.RELIABILITY_RATING, Rating.A); }
@Test public void test_security_rating() { withNoIssues() .assertThatValueIs(CoreMetrics.SECURITY_RATING, Rating.A); with( newGroup(RuleType.VULNERABILITY).setSeverity(Severity.CRITICAL).setCount(1), newGroup(RuleType.VULNERABILITY).setSeverity(Severity.MINOR).setCount(5), // excluded, not a vulnerability newGroup(RuleType.CODE_SMELL).setSeverity(Severity.BLOCKER).setCount(3)) // highest severity of vulnerabilities is CRITICAL --> D .assertThatValueIs(CoreMetrics.SECURITY_RATING, Rating.D); with( newGroup(RuleType.CODE_SMELL).setSeverity(Severity.MAJOR).setCount(3), newGroup(RuleType.BUG).setSeverity(Severity.CRITICAL).setCount(5)) // no vulnerabilities --> A .assertThatValueIs(CoreMetrics.SECURITY_RATING, Rating.A); }
@Test public void test_new_critical_violations() { withNoIssues() .assertThatLeakValueIs(CoreMetrics.NEW_CRITICAL_VIOLATIONS, 0.0); with( newGroup(RuleType.CODE_SMELL).setSeverity(Severity.CRITICAL).setInLeak(true).setCount(3), newGroup(RuleType.BUG).setSeverity(Severity.CRITICAL).setInLeak(true).setCount(5), newGroup(RuleType.VULNERABILITY).setSeverity(Severity.CRITICAL).setInLeak(true).setCount(7), // not CRITICAL newGroup(RuleType.CODE_SMELL).setSeverity(Severity.MAJOR).setInLeak(true).setCount(9), // not in leak newGroup(RuleType.CODE_SMELL).setSeverity(Severity.CRITICAL).setInLeak(false).setCount(11), newGroup(RuleType.BUG).setSeverity(Severity.CRITICAL).setInLeak(false).setCount(13)) .assertThatLeakValueIs(CoreMetrics.NEW_CRITICAL_VIOLATIONS, 3 + 5 + 7); }
@Test public void test_new_minor_violations() { withNoIssues() .assertThatLeakValueIs(CoreMetrics.NEW_MINOR_VIOLATIONS, 0.0); with( newGroup(RuleType.CODE_SMELL).setSeverity(Severity.MINOR).setInLeak(true).setCount(3), newGroup(RuleType.BUG).setSeverity(Severity.MINOR).setInLeak(true).setCount(5), newGroup(RuleType.VULNERABILITY).setSeverity(Severity.MINOR).setInLeak(true).setCount(7), // not MINOR newGroup(RuleType.CODE_SMELL).setSeverity(Severity.CRITICAL).setInLeak(true).setCount(9), // not in leak newGroup(RuleType.CODE_SMELL).setSeverity(Severity.MINOR).setInLeak(false).setCount(11), newGroup(RuleType.BUG).setSeverity(Severity.MINOR).setInLeak(false).setCount(13)) .assertThatLeakValueIs(CoreMetrics.NEW_MINOR_VIOLATIONS, 3 + 5 + 7); }
@Test public void test_new_blocker_violations() { withNoIssues() .assertThatLeakValueIs(CoreMetrics.NEW_BLOCKER_VIOLATIONS, 0.0); with( newGroup(RuleType.CODE_SMELL).setSeverity(Severity.BLOCKER).setInLeak(true).setCount(3), newGroup(RuleType.BUG).setSeverity(Severity.BLOCKER).setInLeak(true).setCount(5), newGroup(RuleType.VULNERABILITY).setSeverity(Severity.BLOCKER).setInLeak(true).setCount(7), // not blocker newGroup(RuleType.CODE_SMELL).setSeverity(Severity.CRITICAL).setInLeak(true).setCount(9), // not in leak newGroup(RuleType.CODE_SMELL).setSeverity(Severity.BLOCKER).setInLeak(false).setCount(11), newGroup(RuleType.BUG).setSeverity(Severity.BLOCKER).setInLeak(false).setCount(13)) .assertThatLeakValueIs(CoreMetrics.NEW_BLOCKER_VIOLATIONS, 3 + 5 + 7); }
@Test public void test_new_major_violations() { withNoIssues() .assertThatLeakValueIs(CoreMetrics.NEW_MAJOR_VIOLATIONS, 0.0); with( newGroup(RuleType.CODE_SMELL).setSeverity(Severity.MAJOR).setInLeak(true).setCount(3), newGroup(RuleType.BUG).setSeverity(Severity.MAJOR).setInLeak(true).setCount(5), newGroup(RuleType.VULNERABILITY).setSeverity(Severity.MAJOR).setInLeak(true).setCount(7), // not MAJOR newGroup(RuleType.CODE_SMELL).setSeverity(Severity.CRITICAL).setInLeak(true).setCount(9), // not in leak newGroup(RuleType.CODE_SMELL).setSeverity(Severity.MAJOR).setInLeak(false).setCount(11), newGroup(RuleType.BUG).setSeverity(Severity.MAJOR).setInLeak(false).setCount(13)) .assertThatLeakValueIs(CoreMetrics.NEW_MAJOR_VIOLATIONS, 3 + 5 + 7); }
@Test public void test_new_info_violations() { withNoIssues() .assertThatLeakValueIs(CoreMetrics.NEW_INFO_VIOLATIONS, 0.0); with( newGroup(RuleType.CODE_SMELL).setSeverity(Severity.INFO).setInLeak(true).setCount(3), newGroup(RuleType.BUG).setSeverity(Severity.INFO).setInLeak(true).setCount(5), newGroup(RuleType.VULNERABILITY).setSeverity(Severity.INFO).setInLeak(true).setCount(7), // not INFO newGroup(RuleType.CODE_SMELL).setSeverity(Severity.CRITICAL).setInLeak(true).setCount(9), // not in leak newGroup(RuleType.CODE_SMELL).setSeverity(Severity.INFO).setInLeak(false).setCount(11), newGroup(RuleType.BUG).setSeverity(Severity.INFO).setInLeak(false).setCount(13)) .assertThatLeakValueIs(CoreMetrics.NEW_INFO_VIOLATIONS, 3 + 5 + 7); }
@Test public void test_bugs() { withNoIssues().assertThatValueIs(CoreMetrics.BUGS, 0); with( newGroup(RuleType.BUG).setSeverity(Severity.MAJOR).setCount(3), newGroup(RuleType.BUG).setSeverity(Severity.CRITICAL).setCount(5), // exclude resolved newResolvedGroup(RuleType.BUG).setCount(7), // not bugs newGroup(RuleType.CODE_SMELL).setCount(11)) .assertThatValueIs(CoreMetrics.BUGS, 3 + 5); }
@Test public void test_vulnerabilities() { withNoIssues().assertThatValueIs(CoreMetrics.VULNERABILITIES, 0); with( newGroup(RuleType.VULNERABILITY).setSeverity(Severity.MAJOR).setCount(3), newGroup(RuleType.VULNERABILITY).setSeverity(Severity.CRITICAL).setCount(5), // exclude resolved newResolvedGroup(RuleType.VULNERABILITY).setCount(7), // not vulnerabilities newGroup(RuleType.BUG).setCount(11)) .assertThatValueIs(CoreMetrics.VULNERABILITIES, 3 + 5); }
@Test public void test_code_smells() { withNoIssues().assertThatValueIs(CoreMetrics.CODE_SMELLS, 0); with( newGroup(RuleType.CODE_SMELL).setSeverity(Severity.MAJOR).setCount(3), newGroup(RuleType.CODE_SMELL).setSeverity(Severity.CRITICAL).setCount(5), // exclude resolved newResolvedGroup(RuleType.CODE_SMELL).setCount(7), // not code smells newGroup(RuleType.BUG).setCount(11)) .assertThatValueIs(CoreMetrics.CODE_SMELLS, 3 + 5); }
@Test public void test_new_vulnerabilities() { withNoIssues().assertThatLeakValueIs(CoreMetrics.NEW_VULNERABILITIES, 0.0); with( newGroup(RuleType.VULNERABILITY).setInLeak(false).setSeverity(Severity.MAJOR).setCount(3), newGroup(RuleType.VULNERABILITY).setInLeak(true).setSeverity(Severity.CRITICAL).setCount(5), newGroup(RuleType.VULNERABILITY).setInLeak(true).setSeverity(Severity.MINOR).setCount(7), // not vulnerabilities newGroup(RuleType.BUG).setInLeak(true).setCount(9), newGroup(RuleType.CODE_SMELL).setInLeak(true).setCount(11)) .assertThatLeakValueIs(CoreMetrics.NEW_VULNERABILITIES, 5 + 7); }
@Test public void test_new_bugs() { withNoIssues().assertThatLeakValueIs(CoreMetrics.NEW_BUGS, 0.0); with( newGroup(RuleType.BUG).setInLeak(false).setSeverity(Severity.MAJOR).setCount(3), newGroup(RuleType.BUG).setInLeak(true).setSeverity(Severity.CRITICAL).setCount(5), newGroup(RuleType.BUG).setInLeak(true).setSeverity(Severity.MINOR).setCount(7), // not bugs newGroup(RuleType.CODE_SMELL).setInLeak(true).setCount(9), newGroup(RuleType.VULNERABILITY).setInLeak(true).setCount(11)) .assertThatLeakValueIs(CoreMetrics.NEW_BUGS, 5 + 7); }
@Test public void test_new_code_smells() { withNoIssues().assertThatLeakValueIs(CoreMetrics.NEW_CODE_SMELLS, 0.0); with( newGroup(RuleType.CODE_SMELL).setInLeak(false).setSeverity(Severity.MAJOR).setCount(3), newGroup(RuleType.CODE_SMELL).setInLeak(true).setSeverity(Severity.CRITICAL).setCount(5), newGroup(RuleType.CODE_SMELL).setInLeak(true).setSeverity(Severity.MINOR).setCount(7), // not code smells newGroup(RuleType.BUG).setInLeak(true).setCount(9), newGroup(RuleType.VULNERABILITY).setInLeak(true).setCount(11)) .assertThatLeakValueIs(CoreMetrics.NEW_CODE_SMELLS, 5 + 7); }
private static IssueGroupDto newGroup(RuleType ruleType) { IssueGroupDto dto = new IssueGroupDto(); // set non-null fields dto.setRuleType(ruleType.getDbConstant()); dto.setCount(1); dto.setEffort(0.0); dto.setSeverity(Severity.INFO); dto.setStatus(Issue.STATUS_OPEN); dto.setInLeak(false); return dto; }
@Test public void test_security_remediation_effort() { withNoIssues().assertThatValueIs(CoreMetrics.SECURITY_REMEDIATION_EFFORT, 0); with( newGroup(RuleType.VULNERABILITY).setEffort(3.0), newGroup(RuleType.VULNERABILITY).setEffort(5.0).setSeverity(Severity.BLOCKER), // not vulnerability newGroup(RuleType.CODE_SMELL).setEffort(7.0), // exclude resolved newResolvedGroup(RuleType.VULNERABILITY).setEffort(17.0)) .assertThatValueIs(CoreMetrics.SECURITY_REMEDIATION_EFFORT, 3.0 + 5.0); }
@Test public void test_reliability_remediation_effort() { withNoIssues().assertThatValueIs(CoreMetrics.RELIABILITY_REMEDIATION_EFFORT, 0); with( newGroup(RuleType.BUG).setEffort(3.0), newGroup(RuleType.BUG).setEffort(5.0).setSeverity(Severity.BLOCKER), // not bugs newGroup(RuleType.CODE_SMELL).setEffort(7.0), // exclude resolved newResolvedGroup(RuleType.BUG).setEffort(17.0)) .assertThatValueIs(CoreMetrics.RELIABILITY_REMEDIATION_EFFORT, 3.0 + 5.0); }
@Test public void count_resolved() { withNoIssues() .assertThatValueIs(CoreMetrics.FALSE_POSITIVE_ISSUES, 0) .assertThatValueIs(CoreMetrics.WONT_FIX_ISSUES, 0); with( newResolvedGroup(Issue.RESOLUTION_FIXED, Issue.STATUS_RESOLVED).setCount(3), newResolvedGroup(Issue.RESOLUTION_FALSE_POSITIVE, Issue.STATUS_CLOSED).setCount(5), newResolvedGroup(Issue.RESOLUTION_WONT_FIX, Issue.STATUS_CLOSED).setSeverity(Severity.MAJOR).setCount(7), newResolvedGroup(Issue.RESOLUTION_WONT_FIX, Issue.STATUS_CLOSED).setSeverity(Severity.BLOCKER).setCount(11), newResolvedGroup(Issue.RESOLUTION_REMOVED, Issue.STATUS_CLOSED).setCount(13), // exclude security hotspot newResolvedGroup(Issue.RESOLUTION_WONT_FIX, Issue.STATUS_RESOLVED).setCount(15).setRuleType(RuleType.SECURITY_HOTSPOT.getDbConstant()), // exclude unresolved newGroup(RuleType.VULNERABILITY).setCount(17), newGroup(RuleType.BUG).setCount(19)) .assertThatValueIs(CoreMetrics.FALSE_POSITIVE_ISSUES, 5) .assertThatValueIs(CoreMetrics.WONT_FIX_ISSUES, 7 + 11); }
@Test public void count_by_status() { withNoIssues() .assertThatValueIs(CoreMetrics.CONFIRMED_ISSUES, 0) .assertThatValueIs(CoreMetrics.OPEN_ISSUES, 0) .assertThatValueIs(CoreMetrics.REOPENED_ISSUES, 0); with( newGroup().setStatus(Issue.STATUS_CONFIRMED).setSeverity(Severity.BLOCKER).setCount(3), newGroup().setStatus(Issue.STATUS_CONFIRMED).setSeverity(Severity.INFO).setCount(5), newGroup().setStatus(Issue.STATUS_REOPENED).setCount(7), newGroup(RuleType.CODE_SMELL).setStatus(Issue.STATUS_OPEN).setCount(9), newGroup(RuleType.BUG).setStatus(Issue.STATUS_OPEN).setCount(11), // exclude security hotspot newGroup(RuleType.SECURITY_HOTSPOT).setStatus(Issue.STATUS_OPEN).setCount(12), newResolvedGroup(Issue.RESOLUTION_FALSE_POSITIVE, Issue.STATUS_CLOSED).setCount(13)) .assertThatValueIs(CoreMetrics.CONFIRMED_ISSUES, 3 + 5) .assertThatValueIs(CoreMetrics.OPEN_ISSUES, 9 + 11) .assertThatValueIs(CoreMetrics.REOPENED_ISSUES, 7); }