@Test public void findsExpectedRef() { List<TrackedReference> trackedReferences = findTrackedReferences(ASYNC_TASK_M); assertThat(trackedReferences).hasSize(1); TrackedReference firstRef = trackedReferences.get(0); assertThat(firstRef.key).isEqualTo(ASYNC_TASK_M.referenceKey); assertThat(firstRef.className).isEqualTo("com.example.leakcanary.MainActivity"); }
@Test public void findsSeveralRefs() { List<TrackedReference> trackedReferences = findTrackedReferences(ASYNC_TASK_PRE_M); assertThat(trackedReferences).hasSize(2); }
private void verifyComponent(Component component, Component.Type type, @Nullable Integer componentRef, int size) { assertThat(component.getType()).isEqualTo(type); assertThat(component.getReportAttributes().getRef()).isEqualTo(componentRef); assertThat(component.getChildren()).hasSize(size); }
@Test public void shouldHandleAnnotation() { List<Statement> statements = chunk("" + "@Entity" + "@Table(name = \"properties\")" + "@Column(updatable = true, nullable = true)"); assertThat(statements).hasSize(3); assertThat(statements.get(0).getValue()).isEqualTo("@Entity"); assertThat(statements.get(1).getValue()).isEqualTo("@Table(name=$CHARS)"); assertThat(statements.get(2).getValue()).isEqualTo("@Column(updatable=true,nullable=true)"); }
@SuppressWarnings("unchecked") void assertInnerSubscriber(FluxZip.ZipCoordinator c) { FluxZip.ZipInner s = (FluxZip.ZipInner) c.inners() .iterator() .next(); assertThat(s.scan(Scannable.Attr.TERMINATED)).isFalse(); assertThat(s.scan(Scannable.Attr.PREFETCH)).isEqualTo(123); assertThat(c.inners()).hasSize(3); assertThat(s.scan(Scannable.Attr.CANCELLED)).isTrue(); }
@Test public void get_range_of_lines() { Optional<Iterable<DbFileSources.Line>> linesOpt = underTest.getLines(dbTester.getSession(), FILE_UUID, 5, 7); assertThat(linesOpt.isPresent()).isTrue(); List<DbFileSources.Line> lines = Lists.newArrayList(linesOpt.get()); assertThat(lines).hasSize(3); assertThat(lines.get(0).getLine()).isEqualTo(5); assertThat(lines.get(1).getLine()).isEqualTo(6); assertThat(lines.get(2).getLine()).isEqualTo(7); }
private void assertDuplication(Duplication d, int originStartLine, int originEndLine, int numDuplicates) { assertThat(d.getOriginPosition().getStartLine()).isEqualTo(originStartLine); assertThat(d.getOriginPosition().getEndLine()).isEqualTo(originEndLine); assertThat(d.getDuplicateList()).hasSize(numDuplicates); }
@Test public void overridden_rule() { List<Rule> rules = parseAnnotatedClass(OverridingRule.class); assertThat(rules).hasSize(1); Rule rule = rules.get(0); assertThat(rule.getKey()).isEqualTo("overriding_foo"); assertThat(rule.getName()).isEqualTo("Overriding Foo"); assertThat(rule.getDescription()).isNull(); assertThat(rule.getSeverity()).isEqualTo(RulePriority.MAJOR); assertThat(rule.getParams()).hasSize(2); }
private void assertDuplication(Duplication d, int originStartLine, int originEndLine, @Nullable Integer otherFileRef, int rangeStartLine, int rangeEndLine) { assertThat(d.getOriginPosition().getStartLine()).isEqualTo(originStartLine); assertThat(d.getOriginPosition().getEndLine()).isEqualTo(originEndLine); assertThat(d.getDuplicateList()).hasSize(1); if (otherFileRef != null) { assertThat(d.getDuplicate(0).getOtherFileRef()).isEqualTo(otherFileRef); } else { assertThat(d.getDuplicate(0).getOtherFileRef()).isEqualTo(0); } assertThat(d.getDuplicate(0).getRange().getStartLine()).isEqualTo(rangeStartLine); assertThat(d.getDuplicate(0).getRange().getEndLine()).isEqualTo(rangeEndLine); }
@Test public void getAtMostThreeActiveUsersForScmAccount_is_case_insensitive_for_scm_account() { UserDoc user = newUser("the_login", singletonList("John.Smith")); es.putDocuments(INDEX_TYPE_USER, user); assertThat(underTest.getAtMostThreeActiveUsersForScmAccount("John.Smith", ORGANIZATION_UUID)).hasSize(1); assertThat(underTest.getAtMostThreeActiveUsersForScmAccount("JOHN.SMIth", ORGANIZATION_UUID)).hasSize(1); assertThat(underTest.getAtMostThreeActiveUsersForScmAccount("JOHN.SMITH", ORGANIZATION_UUID)).hasSize(1); assertThat(underTest.getAtMostThreeActiveUsersForScmAccount("JOHN", ORGANIZATION_UUID)).isEmpty(); }
@Test public void overridden_class() { RulesDefinition.Repository repository = load(OverridingRule.class); assertThat(repository.rules()).hasSize(1); RulesDefinition.Rule rule = repository.rules().get(0); assertThat(rule.key()).isEqualTo("overriding_foo"); assertThat(rule.name()).isEqualTo("Overriding Foo"); assertThat(rule.severity()).isEqualTo(Severity.MAJOR); assertThat(rule.htmlDescription()).isEqualTo("Desc of Overriding Foo"); assertThat(rule.params()).hasSize(2); }
@Test public void should_convert_info_to_plugin_referential() { PluginInfo info = new PluginInfo("foo"); PluginReferential pluginReferential = PluginReferentialMetadataConverter.getInstalledPluginReferential(newArrayList(info)); assertThat(pluginReferential).isNotNull(); assertThat(pluginReferential.getPlugins()).hasSize(1); assertThat(pluginReferential.getPlugins().get(0).getKey()).isEqualTo("foo"); }
@Test public void rule_without_key() { List<Rule> rules = parseAnnotatedClass(RuleWithoutKey.class); assertThat(rules).hasSize(1); Rule rule = rules.get(0); assertThat(rule.getKey()).isEqualTo(RuleWithoutKey.class.getCanonicalName()); assertThat(rule.getName()).isEqualTo("foo"); assertThat(rule.getDescription()).isNull(); assertThat(rule.getSeverity()).isEqualTo(RulePriority.MAJOR); }
@Test public void read() throws IOException { assertThat(IOUtil.toString(ResourceUtil.asStream("test.txt"))).isEqualTo("ABCDEFG\nABC"); assertThat(IOUtil.toLines(ResourceUtil.asStream("test.txt"))).hasSize(2).containsExactly("ABCDEFG", "ABC"); }
@Test public void use_classname_when_missing_key() { RulesDefinition.Repository repository = load(RuleWithoutKey.class); assertThat(repository.rules()).hasSize(1); RulesDefinition.Rule rule = repository.rules().get(0); assertThat(rule.key()).isEqualTo(RuleWithoutKey.class.getCanonicalName()); assertThat(rule.name()).isEqualTo("foo"); }
@Test public void support_deprecated_format() { // the deprecated format uses some attributes instead of nodes InputStream input = getClass().getResourceAsStream("RulesDefinitionXmlLoaderTest/deprecated.xml"); RulesDefinition.Repository repository = load(input, StandardCharsets.UTF_8.name()); assertThat(repository.rules()).hasSize(1); RulesDefinition.Rule rule = repository.rules().get(0); assertThat(rule.key()).isEqualTo("org.sonar.it.checkstyle.MethodsCountCheck"); assertThat(rule.internalKey()).isEqualTo("Checker/TreeWalker/org.sonar.it.checkstyle.MethodsCountCheck"); assertThat(rule.severity()).isEqualTo(Severity.CRITICAL); assertThat(rule.htmlDescription()).isEqualTo("Count methods"); assertThat(rule.param("minMethodsCount")).isNotNull(); }
@Test public void getAtMostThreeActiveUsersForScmAccount_is_case_insensitive_for_email() { UserDoc user = newUser("the_login", "the_EMAIL@corp.com", singletonList("John.Smith")); es.putDocuments(INDEX_TYPE_USER, user); assertThat(underTest.getAtMostThreeActiveUsersForScmAccount("the_EMAIL@corp.com", ORGANIZATION_UUID)).hasSize(1); assertThat(underTest.getAtMostThreeActiveUsersForScmAccount("the_email@corp.com", ORGANIZATION_UUID)).hasSize(1); assertThat(underTest.getAtMostThreeActiveUsersForScmAccount("email", ORGANIZATION_UUID)).isEmpty(); }
@Test public void use_default_unit_when_no_unit() throws Exception { String xml = getFileContent("use_default_unit_when_no_unit.xml"); List<RuleDebt> results = underTest.importXML(xml, validationMessages); assertThat(results).hasSize(1); RuleDebt ruleDebt = results.get(0); assertThat(ruleDebt.function()).isEqualTo(DebtRemediationFunction.Type.LINEAR_OFFSET.name()); assertThat(ruleDebt.coefficient()).isEqualTo("3d"); assertThat(ruleDebt.offset()).isEqualTo("1d"); }
@Test public void return_public_project_with_only_AllowAnyone_true_when_no_permission_in_DB() { List<IndexPermissions> dtos = underTest.selectByUuids(dbClient, dbSession, singletonList(publicProject.uuid())); Assertions.assertThat(dtos).hasSize(1); IndexPermissions dto = dtos.get(0); assertThat(dto.getGroupIds()).isEmpty(); assertThat(dto.getUserIds()).isEmpty(); assertThat(dto.isAllowAnyone()).isTrue(); assertThat(dto.getProjectUuid()).isEqualTo(publicProject.uuid()); assertThat(dto.getQualifier()).isEqualTo(publicProject.qualifier()); }
@Test public void import_linear_with_offset() throws Exception { String xml = getFileContent("import_linear_with_offset.xml"); List<RuleDebt> results = underTest.importXML(xml, validationMessages); assertThat(results).hasSize(1); RuleDebt ruleDebt = results.get(0); assertThat(ruleDebt.function()).isEqualTo(DebtRemediationFunction.Type.LINEAR_OFFSET.name()); assertThat(ruleDebt.coefficient()).isEqualTo("3h"); assertThat(ruleDebt.offset()).isEqualTo("1min"); }