本文整理了Java中org.assertj.core.api.AbstractListAssert.extracting()
方法的一些代码示例,展示了AbstractListAssert.extracting()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。AbstractListAssert.extracting()
方法的具体详情如下:
包路径:org.assertj.core.api.AbstractListAssert
类名称:AbstractListAssert
方法名:extracting
暂无
代码示例来源:origin: json-path/JsonPath
@Test
public void issue_131() {
String json = "[\n" +
" {\n" +
" \"foo\": \"1\"\n" +
" },\n" +
" {\n" +
" \"foo\": null\n" +
" },\n" +
" {\n" +
" \"xxx\": null\n" +
" }\n" +
"]";
List<Map<String, String>> result = read(json, "$[?(@.foo)]");
assertThat(result).extracting("foo").containsExactly("1", null);
}
代码示例来源:origin: json-path/JsonPath
@Test
public void test_type_ref() throws IOException {
TypeRef<List<FooBarBaz<Sub>>> typeRef = new TypeRef<List<FooBarBaz<Sub>>>() {};
assertThat(using(conf).parse(JSON).read("$", typeRef)).extracting("foo").containsExactly("foo0", "foo1", "foo2");
}
代码示例来源:origin: SonarSource/sonarqube
protected ListAssert<String> assertSearch(SuggestionQuery query) {
return (ListAssert<String>)assertThat(index.searchSuggestions(query, features.get()).getQualifiers())
.flatExtracting(ComponentHitsPerQualifier::getHits)
.extracting(ComponentHit::getUuid);
}
代码示例来源:origin: SonarSource/sonarqube
private void assertHighlighting(String fileName, String search, String expectedHighlighting) {
indexFile(fileName);
SuggestionQuery query = SuggestionQuery.builder()
.setQuery(search)
.setQualifiers(Collections.singletonList(Qualifiers.FILE))
.build();
Stream<ComponentHitsPerQualifier> results = index.searchSuggestions(query, features.get()).getQualifiers();
assertThat(results).flatExtracting(ComponentHitsPerQualifier::getHits)
.extracting(ComponentHit::getHighlightedText)
.extracting(Optional::get)
.containsExactly(expectedHighlighting);
}
}
代码示例来源:origin: SonarSource/sonarqube
@Test
public void event_contains_newQualityGate_computed_by_LiveQualityGateComputer() {
markProjectAsAnalyzed(project);
db.measures().insertLiveMeasure(project, alertStatusMetric, m -> m.setData(Metric.Level.ERROR.name()));
db.measures().insertLiveMeasure(project, intMetric, m -> m.setVariation(42.0).setValue(null));
BranchDto branch = db.getDbClient().branchDao().selectByBranchKey(db.getSession(), project.projectUuid(), "master")
.orElseThrow(() -> new IllegalStateException("Can't find master branch"));
List<QGChangeEvent> result = run(file1, newQualifierBasedIntLeakFormula());
assertThat(result)
.extracting(QGChangeEvent::getQualityGateSupplier)
.extracting(Supplier::get)
.containsExactly(Optional.of(newQualityGate));
verify(qGateComputer).loadQualityGate(any(DbSession.class), eq(organization), eq(project), eq(branch));
verify(qGateComputer).getMetricsRelatedTo(qualityGate);
verify(qGateComputer).refreshGateStatus(eq(project), same(qualityGate), any(MeasureMatrix.class));
}
代码示例来源:origin: allure-framework/allure2
@Test
public void shouldAddTestResultFormatLabel() throws Exception {
Set<TestResult> testResults = process(
"allure1/sample-testsuite.xml", generateTestSuiteXmlName()
).getResults();
assertThat(testResults)
.extracting(result -> result.findOneLabel(LabelName.RESULT_FORMAT))
.extracting(Optional::get)
.containsOnly(Allure1Plugin.ALLURE1_RESULTS_FORMAT);
}
代码示例来源:origin: allure-framework/allure2
@Test
public void shouldGetSuiteTitleIfExists() throws Exception {
Set<TestResult> testCases = process(
"allure1/sample-testsuite.json", generateTestSuiteJsonName()
).getResults();
assertThat(testCases)
.hasSize(1)
.extracting(testResult -> testResult.findOneLabel(LabelName.SUITE))
.extracting(Optional::get)
.containsExactly("Passing test");
}
代码示例来源:origin: allure-framework/allure2
@Test
public void shouldUseTestClassLabelForPackage() throws Exception {
Set<TestResult> testResults = process(
"allure1/packages-testsuite.xml", generateTestSuiteXmlName()
).getResults();
assertThat(testResults)
.hasSize(1)
.extracting(result -> result.findOneLabel(LabelName.PACKAGE))
.extracting(Optional::get)
.containsExactly("my.company.package.subpackage.MyClass");
}
代码示例来源:origin: allure-framework/allure2
@Test
public void shouldNotFailIfSuiteTitleNotExists() throws Exception {
Set<TestResult> testCases = process(
"allure1/suite-with-attachments.xml", generateTestSuiteXmlName()
).getResults();
assertThat(testCases)
.hasSize(1)
.extracting(testResult -> testResult.findOneLabel(LabelName.SUITE))
.extracting(Optional::get)
.containsExactly("my.company.AlwaysPassingTest");
}
代码示例来源:origin: SonarSource/sonarqube
@Test
public void initialize_matches_Sonar_Way_default_with_case_sensitivity() {
String sonarWayInOtherCase = SONAR_WAY_QP_NAME.toUpperCase();
BuiltInQProfileRepository underTest = new BuiltInQProfileRepositoryImpl(
dbClient, new Languages(FOO_LANGUAGE),
new DummyProfileDefinition("foo", "goo", false), new DummyProfileDefinition("foo", sonarWayInOtherCase, false));
underTest.initialize();
assertThat(underTest.get())
.filteredOn(b -> FOO_LANGUAGE.getKey().equals(b.getLanguage()))
.filteredOn(BuiltInQProfile::isDefault)
.extracting(BuiltInQProfile::getName)
.containsExactly("goo");
}
代码示例来源:origin: allure-framework/allure2
@Test
public void shouldAddTestResultFormatLabel() throws Exception {
Set<TestResult> testResults = process(
"allure2/simple-testcase.json", generateTestResultName(),
"allure2/first-testgroup.json", generateTestResultContainerName(),
"allure2/second-testgroup.json", generateTestResultContainerName()
).getResults();
assertThat(testResults)
.extracting(result -> result.findOneLabel(LabelName.RESULT_FORMAT))
.extracting(Optional::get)
.containsOnly(Allure2Plugin.ALLURE2_RESULTS_FORMAT);
}
代码示例来源:origin: SonarSource/sonarqube
@Test
public void initialize_does_not_create_Sonar_Way_as_default_if_other_profile_is_defined_as_default() {
BuiltInQProfileRepository underTest = new BuiltInQProfileRepositoryImpl(
dbClient, new Languages(FOO_LANGUAGE),
new DummyProfileDefinition("foo", SONAR_WAY_QP_NAME, false), new DummyProfileDefinition("foo", "goo", true));
underTest.initialize();
assertThat(underTest.get())
.filteredOn(b -> FOO_LANGUAGE.getKey().equals(b.getLanguage()))
.filteredOn(BuiltInQProfile::isDefault)
.extracting(BuiltInQProfile::getName)
.containsExactly("goo");
}
代码示例来源:origin: SonarSource/sonarqube
@Test
public void should_warn_about_short_inputs_but_return_results_based_on_other_terms() {
ComponentDto project = db.components().insertComponent(newPrivateProjectDto(organization).setName("SonarQube"));
componentIndexer.indexOnStartup(null);
authorizationIndexerTester.allowOnlyAnyone(project);
SuggestionsWsResponse response = ws.newRequest()
.setMethod("POST")
.setParam(PARAM_QUERY, "Sonar Q")
.executeProtobuf(SuggestionsWsResponse.class);
assertThat(response.getResultsList())
.flatExtracting(Category::getItemsList)
.extracting(Suggestion::getKey)
.contains(project.getDbKey());
assertThat(response.getWarning()).contains(SHORT_INPUT_WARNING);
}
代码示例来源:origin: SonarSource/sonarqube
@Test
public void suggestions_without_query_should_not_contain_matches_that_are_neither_favorites_nor_recently_browsed() {
ComponentDto project = db.components().insertComponent(newPrivateProjectDto(organization));
componentIndexer.indexOnStartup(null);
userSessionRule.addProjectPermission(USER, project);
SuggestionsWsResponse response = ws.newRequest()
.setMethod("POST")
.executeProtobuf(SuggestionsWsResponse.class);
// assert match in qualifier "TRK"
assertThat(response.getResultsList())
.filteredOn(q -> q.getItemsCount() > 0)
.extracting(Category::getQ)
.isEmpty();
}
代码示例来源:origin: SonarSource/sonarqube
@Test
public void does_not_return_branches() {
ComponentDto project = db.components().insertMainBranch();
authorizationIndexerTester.allowOnlyAnyone(project);
ComponentDto branch = db.components().insertProjectBranch(project);
componentIndexer.indexOnStartup(null);
authorizationIndexerTester.allowOnlyAnyone(project);
SuggestionsWsResponse response = ws.newRequest()
.setMethod("POST")
.setParam(PARAM_QUERY, project.name())
.executeProtobuf(SuggestionsWsResponse.class);
assertThat(response.getResultsList())
.filteredOn(c -> "TRK".equals(c.getQ()))
.extracting(Category::getItemsList)
.hasSize(1);
}
代码示例来源:origin: SonarSource/sonarqube
@Test
public void initialize_creates_profile_Sonar_Way_as_default_if_none_other_is_defined_default_for_a_given_language() {
BuiltInQProfileRepository underTest = new BuiltInQProfileRepositoryImpl(
dbClient, new Languages(FOO_LANGUAGE),
new DummyProfileDefinition("foo", "doh", false), new DummyProfileDefinition("foo", "boo", false),
new DummyProfileDefinition("foo", SONAR_WAY_QP_NAME, false), new DummyProfileDefinition("foo", "goo", false));
underTest.initialize();
assertThat(underTest.get())
.filteredOn(b -> FOO_LANGUAGE.getKey().equals(b.getLanguage()))
.filteredOn(BuiltInQProfile::isDefault)
.extracting(BuiltInQProfile::getName)
.containsExactly(SONAR_WAY_QP_NAME);
}
代码示例来源:origin: SonarSource/sonarqube
@Test
public void should_mark_favorite_items() {
ComponentDto favouriteProject = db.components().insertComponent(newPrivateProjectDto(organization).setName("Project1"));
ComponentDto nonFavouriteProject = db.components().insertComponent(newPublicProjectDto(organization).setName("Project2"));
doReturn(singletonList(favouriteProject)).when(favoriteFinder).list();
componentIndexer.indexOnAnalysis(favouriteProject.projectUuid());
componentIndexer.indexOnAnalysis(nonFavouriteProject.projectUuid());
authorizationIndexerTester.allowOnlyAnyone(favouriteProject, nonFavouriteProject);
SuggestionsWsResponse response = ws.newRequest()
.setMethod("POST")
.setParam(PARAM_QUERY, "Project")
.executeProtobuf(SuggestionsWsResponse.class);
assertThat(response.getResultsList())
.flatExtracting(Category::getItemsList)
.extracting(Suggestion::getKey, Suggestion::getIsFavorite)
.containsExactly(tuple(favouriteProject.getDbKey(), true), tuple(nonFavouriteProject.getDbKey(), false));
}
代码示例来源:origin: SonarSource/sonarqube
@Test
public void should_mark_recently_browsed_items() {
ComponentDto project = db.components().insertComponent(newPrivateProjectDto(organization).setName("ProjectModule"));
ComponentDto module1 = newModuleDto(project).setName("Module1");
db.components().insertComponent(module1);
ComponentDto module2 = newModuleDto(project).setName("Module2");
db.components().insertComponent(module2);
componentIndexer.indexOnAnalysis(project.projectUuid());
authorizationIndexerTester.allowOnlyAnyone(project);
SuggestionsWsResponse response = ws.newRequest()
.setMethod("POST")
.setParam(PARAM_QUERY, "Module")
.setParam(PARAM_RECENTLY_BROWSED, Stream.of(module1.getDbKey(), project.getDbKey()).collect(joining(",")))
.executeProtobuf(SuggestionsWsResponse.class);
assertThat(response.getResultsList())
.flatExtracting(Category::getItemsList)
.extracting(Suggestion::getIsRecentlyBrowsed)
.containsExactly(true);
}
代码示例来源:origin: SonarSource/sonarqube
@Test
public void should_contain_component_names() {
OrganizationDto organization1 = db.organizations().insert(o -> o.setKey("org-1").setName("Organization One"));
ComponentDto project1 = db.components().insertComponent(newPrivateProjectDto(organization1).setName("Project1"));
componentIndexer.indexOnAnalysis(project1.projectUuid());
authorizationIndexerTester.allowOnlyAnyone(project1);
SuggestionsWsResponse response = ws.newRequest()
.setMethod("POST")
.setParam(PARAM_QUERY, "Project")
.executeProtobuf(SuggestionsWsResponse.class);
assertThat(response.getResultsList())
.flatExtracting(Category::getItemsList)
.extracting(Suggestion::getKey, Suggestion::getName)
.containsExactlyInAnyOrder(tuple(project1.getDbKey(), project1.name()));
}
代码示例来源:origin: SonarSource/sonarqube
@Test
public void should_not_return_modules() {
ComponentDto project = db.components().insertComponent(newPrivateProjectDto(organization).setName("ProjectWithModules"));
db.components().insertComponent(newModuleDto(project).setName("Module1"));
db.components().insertComponent(newModuleDto(project).setName("Module2"));
componentIndexer.indexOnAnalysis(project.projectUuid());
authorizationIndexerTester.allowOnlyAnyone(project);
SuggestionsWsResponse response = ws.newRequest()
.setMethod("POST")
.setParam(PARAM_QUERY, "Module")
.executeProtobuf(SuggestionsWsResponse.class);
assertThat(response.getResultsList())
.flatExtracting(Category::getItemsList)
.extracting(Suggestion::getKey)
.containsOnly(project.getDbKey());
}
内容来源于网络,如有侵权,请联系作者删除!