/** * Uses the given {@link Function}s to extract the values from the object under test into a list, this new list becoming * the object under test. * <p> * If the given {@link Function}s extract the id, name and email values then the list will contain the id, name and email values * of the object under test, you can then perform list assertions on the extracted values. * <p> * Example: * <pre><code class='java'> // Create frodo, setting its name, age and Race (Race having a name property) * TolkienCharacter frodo = new TolkienCharacter("Frodo", 33, HOBBIT); * * // let's verify Frodo's name, age and race name: * assertThat(frodo).extracting(TolkienCharacter::getName, * character -> character.age, // public field * character -> character.getRace().getName()) * .containsExactly("Frodo", 33, "Hobbit");</code></pre> * <p> * Note that the order of extracted values is consistent with the order of given extractor functions. * * @param extractors the extractor functions to extract values from the Object under test. * @return a new assertion object whose object under test is the list containing the extracted values */ @CheckReturnValue public AbstractListAssert<?, List<? extends Object>, Object, ObjectAssert<Object>> extracting(@SuppressWarnings("unchecked") Function<? super ACTUAL, Object>... extractors) { List<Object> values = Stream.of(extractors) .map(extractor -> extractor.apply(actual)) .collect(toList()); return newListAssertInstance(values).as(info.description()); }
/** * Uses the given {@link Function}s to extract the values from the object under test into a list, this new list becoming * the object under test. * <p> * If the given {@link Function}s extract the id, name and email values then the list will contain the id, name and email values * of the object under test, you can then perform list assertions on the extracted values. * <p> * Example: * <pre><code class='java'> // Create frodo, setting its name, age and Race (Race having a name property) * TolkienCharacter frodo = new TolkienCharacter("Frodo", 33, HOBBIT); * * // let's verify Frodo's name, age and race name: * assertThat(frodo).extracting(TolkienCharacter::getName, * character -> character.age, // public field * character -> character.getRace().getName()) * .containsExactly("Frodo", 33, "Hobbit");</code></pre> * <p> * Note that the order of extracted values is consistent with the order of given extractor functions. * * @param extractors the extractor functions to extract values from the Object under test. * @return a new assertion object whose object under test is the list containing the extracted values */ @CheckReturnValue public AbstractListAssert<?, List<? extends Object>, Object, ObjectAssert<Object>> extracting(@SuppressWarnings("unchecked") Function<? super ACTUAL, Object>... extractors) { List<Object> values = Stream.of(extractors) .map(extractor -> extractor.apply(actual)) .collect(toList()); return newListAssertInstance(values).as(info.description()); }
/** {@inheritDoc} */ @SuppressWarnings("unchecked") @Override @CheckReturnValue public AbstractListAssert<?, List<? extends Object>, Object, ObjectAssert<Object>> asList() { objects.assertIsInstanceOf(info, actual, List.class); return newListAssertInstance((List<Object>) actual).as(info.description()); }
/** * Use the given {@link Function} to extract a value from the {@link Map}'s entries. * The extracted values are stored in a new list becoming the object under test. * <p> * Let's take a look at an example to make things clearer : * <pre><code class='java'> // Build a Map that associates family roles and name of the Simpson familly * Map<String, CartoonCharacter> characters = new HashMap<>(); * characters.put("dad", new CartoonCharacter("Omer")); * characters.put("mom", new CartoonCharacter("Marge")); * characters.put("girl", new CartoonCharacter("Lisa")); * characters.put("boy", new CartoonCharacter("Bart")); * * assertThat(characters).extractingFromEntries(e -> e.getValue().getName()) * .containsOnly("Omer", "Marge", "Lisa", "Bart");</code></pre> * * @param extractor the extractor function to extract a value from an entry of the Map under test. * @return a new assertion object whose object under test is the list of values extracted * @since 3.12.0 */ @CheckReturnValue public AbstractListAssert<?, List<?>, Object, ObjectAssert<Object>> extractingFromEntries(Function<? super Map.Entry<K, V>, Object> extractor) { isNotNull(); List<Object> extractedObjects = actual.entrySet().stream() .map(extractor::apply) .collect(toList()); return newListAssertInstance(extractedObjects).as(info.description()); }
String extractedPropertiesOrFieldsDescription = extractedDescriptionOf(keys); String description = mostRelevantDescription(info.description(), extractedPropertiesOrFieldsDescription); return newListAssertInstance(extractedValues).as(description);
private void checkResponse(BulkChangeWsResponse response, long total, long success, long ignored, long failure) { assertThat(response) .extracting(BulkChangeWsResponse::getTotal, BulkChangeWsResponse::getSuccess, BulkChangeWsResponse::getIgnored, BulkChangeWsResponse::getFailures) .as("Total, success, ignored, failure") .containsExactly(total, success, ignored, failure); }
/** {@inheritDoc} */ @SuppressWarnings("unchecked") @Override @CheckReturnValue public AbstractListAssert<?, List<? extends Object>, Object, ObjectAssert<Object>> asList() { objects.assertIsInstanceOf(info, actual, List.class); return newListAssertInstance((List<Object>) actual).as(info.description()); }
String extractedPropertiesOrFieldsDescription = extractedDescriptionOf(keys); String description = mostRelevantDescription(info.description(), extractedPropertiesOrFieldsDescription); return newListAssertInstance(extractedValues).as(description);
String extractedDescription = extractedDescriptionOf(propertiesOrFields); String description = mostRelevantDescription(info.description(), extractedDescription); return newListAssertInstance(values).withAssertionState(myself).as(description);
String extractedDescription = extractedDescriptionOf(fieldOrProperty); String description = mostRelevantDescription(info.description(), extractedDescription); return newListAssertInstance(values).withAssertionState(myself).as(description);
String extractedDescription = extractedDescriptionOfMethod(method); String description = mostRelevantDescription(info.description(), extractedDescription); return newListAssertInstanceForMethodsChangingElementType(values).as(description);
String extractedDescription = extractedDescriptionOfMethod(method); String description = mostRelevantDescription(info.description(), extractedDescription); return newListAssertInstanceForMethodsChangingElementType(values).as(description);
@Test public void shouldGenerateDifferentHistoryIdForParameterizedTests() throws Exception { final String historyId1 = "56f15d234f8ad63b493afb25f7c26556"; final String historyId2 = "e374f6eb3cf497543291506c8c20353"; Set<TestResult> testResults = process( "allure1/suite-with-parameters.xml", generateTestSuiteXmlName() ).getResults(); assertThat(testResults) .extracting(TestResult::getHistoryId) .as("History ids for parameterized tests must be different") .containsExactlyInAnyOrder(historyId1, historyId2); }
String extractedPropertiesOrFieldsDescription = extractedDescriptionOf(propertiesOrFields); String description = mostRelevantDescription(info.description(), extractedPropertiesOrFieldsDescription); return newListAssertInstance(values.toList()).as(description);
String extractedDescription = extractedDescriptionOf(propertyOrField); String description = mostRelevantDescription(info.description(), extractedDescription); return newListAssertInstanceForMethodsChangingElementType(values).as(description);
String extractedDescription = extractedDescriptionOfMethod(method); String description = mostRelevantDescription(info.description(), extractedDescription); return newListAssertInstance(newArrayList(values)).withAssertionState(myself).as(description);
String extractedDescription = extractedDescriptionOfMethod(method); String description = mostRelevantDescription(info.description(), extractedDescription); return newListAssertInstance(newArrayList(values)).withAssertionState(myself).as(description);
String extractedDescription = extractedDescriptionOf(fieldOrProperty); String description = mostRelevantDescription(info.description(), extractedDescription); return newListAssertInstance(newArrayList(values)).withAssertionState(myself).as(description);
String extractedPropertiesOrFieldsDescription = extractedDescriptionOf(keys); String description = mostRelevantDescription(info.description(), extractedPropertiesOrFieldsDescription); return newListAssertInstance(valuesFlattened).as(description);
@Test public void shouldReadPropertiesFile() throws Exception { final String testName = "testFour"; final String link1 = "http://example.org/JIRA-1"; final String link2 = "http://example.org/JIRA-2"; final String link3 = "http://example.org/TMS-1"; Set<TestResult> testResults = process( "allure1/sample-testsuite.xml", generateTestSuiteXmlName(), "allure1/allure.properties", "allure.properties" ).getResults(); assertThat(testResults) .filteredOn(testResult -> testResult.getName().equals(testName)) .flatExtracting(TestResult::getLinks) .extracting(Link::getUrl) .as("Test links should contain patterns from allure.properties file") .containsExactlyInAnyOrder(link1, link2, link3); }