本文整理汇总了Java中org.assertj.core.api.iterable.Extractor类的典型用法代码示例。如果您正苦于以下问题:Java Extractor类的具体用法?Java Extractor怎么用?Java Extractor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Extractor类属于org.assertj.core.api.iterable包,在下文中一共展示了Extractor类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: lastUriPart
import org.assertj.core.api.iterable.Extractor; //导入依赖的package包/类
private static Extractor<Location, String> lastUriPart() {
return new Extractor<Location, String>() {
@Override
public String extract(Location input) {
return input.asURI().toString()
.replaceAll("/$", "")
.replaceAll(".*/", "");
}
};
}
开发者ID:TNG,项目名称:ArchUnit,代码行数:11,代码来源:LocationsTest.java
示例2: memberIdentifier
import org.assertj.core.api.iterable.Extractor; //导入依赖的package包/类
private Extractor<JavaMember, String> memberIdentifier() {
return new Extractor<JavaMember, String>() {
@Override
public String extract(JavaMember input) {
return input.getOwner().getSimpleName() + "#" + input.getName();
}
};
}
开发者ID:TNG,项目名称:ArchUnit,代码行数:9,代码来源:JavaClassTest.java
示例3: patternToOptionalOfString
import org.assertj.core.api.iterable.Extractor; //导入依赖的package包/类
private Extractor<PathParameter, Optional<String>> patternToOptionalOfString() {
return new Extractor<PathParameter, Optional<String>>() {
@Override
public Optional<String> extract(PathParameter pathParameter) {
return pathParameter.getRegex().isPresent()?
Optional.of(pathParameter.getRegex().get().pattern()):
Optional.<String>absent();
}
};
}
开发者ID:vidal-community,项目名称:jax-rs-linker,代码行数:11,代码来源:ApiPathsTest.java
示例4: extract
import org.assertj.core.api.iterable.Extractor; //导入依赖的package包/类
/**
* Behavior is described in {@link AbstractIterableAssert#extracting(Extractor)}
* @param <F> type of elements to extract a value from
* @param <T> the extracted value type
* @param objects the elements to extract a value from
* @param extractor the extractor function
* @return the extracted values
*/
public static <F, T> List<T> extract(Iterable<? extends F> objects, Extractor<? super F, T> extractor) {
checkObjectToExtractFromIsNotNull(objects);
List<T> result = newArrayList();
for (F object : objects) {
final T newValue = extractor.extract(object);
result.add(newValue);
}
return result;
}
开发者ID:joel-costigliola,项目名称:assertj-core,代码行数:20,代码来源:FieldsOrPropertiesExtractor.java
示例5: extract
import org.assertj.core.api.iterable.Extractor; //导入依赖的package包/类
@Override
public Tuple extract(T input) {
checkArgument(fieldsOrProperties != null, "The names of the fields/properties to read should not be null");
checkArgument(fieldsOrProperties.length > 0, "The names of the fields/properties to read should not be empty");
checkArgument(input != null, "The object to extract fields/properties from should not be null");
List<Extractor<T, Object>> extractors = buildExtractors();
List<Object> values = extractValues(input, extractors);
return new Tuple(values.toArray());
}
开发者ID:joel-costigliola,项目名称:assertj-core,代码行数:12,代码来源:ByNameMultipleExtractor.java
示例6: extractValues
import org.assertj.core.api.iterable.Extractor; //导入依赖的package包/类
private List<Object> extractValues(T input, List<Extractor<T, Object>> singleExtractors) {
List<Object> values = new ArrayList<>();
for (Extractor<T, Object> extractor : singleExtractors) {
values.add(extractor.extract(input));
}
return values;
}
开发者ID:joel-costigliola,项目名称:assertj-core,代码行数:9,代码来源:ByNameMultipleExtractor.java
示例7: buildExtractors
import org.assertj.core.api.iterable.Extractor; //导入依赖的package包/类
private List<Extractor<T, Object>> buildExtractors() {
List<Extractor<T, Object>> result = new ArrayList<>();
for (String name : fieldsOrProperties) {
result.add(new ByNameSingleExtractor<T>(name));
}
return result;
}
开发者ID:joel-costigliola,项目名称:assertj-core,代码行数:10,代码来源:ByNameMultipleExtractor.java
示例8: doFlatExtracting
import org.assertj.core.api.iterable.Extractor; //导入依赖的package包/类
private <V> AbstractListAssert<?, List<? extends V>, V, ObjectAssert<V>> doFlatExtracting(Extractor<? super ELEMENT, ? extends Collection<V>> extractor) {
List<V> result = newArrayList();
final List<? extends Collection<V>> extractedValues = FieldsOrPropertiesExtractor.extract(actual, extractor);
for (Collection<? extends V> iterable : extractedValues) {
result.addAll(iterable);
}
return newListAssertInstance(result);
}
开发者ID:joel-costigliola,项目名称:assertj-core,代码行数:11,代码来源:AbstractIterableAssert.java
示例9: doFlatExtracting
import org.assertj.core.api.iterable.Extractor; //导入依赖的package包/类
private <V, C extends Collection<V>> AbstractListAssert<?, List<? extends V>, V, ObjectAssert<V>> doFlatExtracting(Extractor<? super ELEMENT, C> extractor) {
final List<C> extractedValues = FieldsOrPropertiesExtractor.extract(Arrays.asList(actual), extractor);
final List<V> result = newArrayList();
for (C e : extractedValues) {
result.addAll(e);
}
return newListAssertInstance(result);
}
开发者ID:joel-costigliola,项目名称:assertj-core,代码行数:11,代码来源:AbstractObjectArrayAssert.java
示例10: doFlatExtracting
import org.assertj.core.api.iterable.Extractor; //导入依赖的package包/类
private <U, C extends Collection<U>> ObjectArrayAssert<U> doFlatExtracting(Extractor<? super T, C> extractor) {
final List<C> extractedValues = FieldsOrPropertiesExtractor.extract(Arrays.asList(array), extractor);
final List<U> result = newArrayList();
for (C e : extractedValues) {
result.addAll(e);
}
return new ObjectArrayAssert<>(IterableUtil.toArray(result));
}
开发者ID:joel-costigliola,项目名称:assertj-core,代码行数:11,代码来源:AtomicReferenceArrayAssert.java
示例11: should_extract_tuples_from_fields_or_properties
import org.assertj.core.api.iterable.Extractor; //导入依赖的package包/类
@Test
public void should_extract_tuples_from_fields_or_properties() {
Extractor<Employee, Tuple> extractor = new ByNameMultipleExtractor<>("id", "age");
Tuple extractedValue = extractor.extract(yoda);
assertThat(extractedValue).isEqualTo(tuple(1L, 800));
}
开发者ID:joel-costigliola,项目名称:assertj-core,代码行数:8,代码来源:ByNameMultipleExtractorTest.java
示例12: should_extract_tuples_with_consistent_iteration_order
import org.assertj.core.api.iterable.Extractor; //导入依赖的package包/类
@Test
public void should_extract_tuples_with_consistent_iteration_order() {
Extractor<Employee, Tuple> extractor = new ByNameMultipleExtractor<>("id", "name.first", "age");
Tuple extractedValues = extractor.extract(yoda);
assertThat(extractedValues).isEqualTo(tuple(1L, "Yoda", 800));
}
开发者ID:joel-costigliola,项目名称:assertj-core,代码行数:8,代码来源:ByNameMultipleExtractorTest.java
示例13: should_let_anonymous_class_extractor_runtime_exception_bubble_up
import org.assertj.core.api.iterable.Extractor; //导入依赖的package包/类
@Test
public void should_let_anonymous_class_extractor_runtime_exception_bubble_up() {
thrown.expect(RuntimeException.class, "age > 100");
assertThat(employees).extracting(new Extractor<Employee, String>() {
@Override
public String extract(Employee employee) {
if (employee.getAge() > 100) throw new RuntimeException("age > 100");
return employee.getName().getFirst();
}
});
}
开发者ID:joel-costigliola,项目名称:assertj-core,代码行数:12,代码来源:AtomicReferenceArrayAssert_extracting_Test.java
示例14: should_allow_assertions_on_extractor_assertions_extracted_from_given_array_compatibility
import org.assertj.core.api.iterable.Extractor; //导入依赖的package包/类
@Test
public void should_allow_assertions_on_extractor_assertions_extracted_from_given_array_compatibility() {
assertThat(employees).extracting(new Extractor<Employee, String>() {
@Override
public String extract(Employee input) {
return input.getName().getFirst();
}
}).containsOnly("Yoda", "Luke");
}
开发者ID:joel-costigliola,项目名称:assertj-core,代码行数:10,代码来源:ObjectArrayAssert_extracting_Test.java
示例15: assertThat
import org.assertj.core.api.iterable.Extractor; //导入依赖的package包/类
@Test
public void should_allow_assertions_on_extractor_assertions_extracted_from_given_array_compatibility_runtimeexception() {
thrown.expect(RuntimeException.class);
assertThat(employees).extracting(new Extractor<Employee, String>() {
@Override
public String extract(Employee input) {
if (input.getAge() > 100) {
throw new RuntimeException("age > 100");
}
return input.getName().getFirst();
}
});
}
开发者ID:joel-costigliola,项目名称:assertj-core,代码行数:14,代码来源:ObjectArrayAssert_extracting_Test.java
示例16: flatExtracting
import org.assertj.core.api.iterable.Extractor; //导入依赖的package包/类
@Override
@SafeVarargs
public final AbstractListAssert<?, List<? extends Object>, Object, ObjectAssert<Object>> flatExtracting(Extractor<? super ELEMENT, ?>... extractors) {
return super.flatExtracting(extractors);
}
开发者ID:joel-costigliola,项目名称:assertj-core,代码行数:6,代码来源:IterableAssert.java
示例17: flatExtracting
import org.assertj.core.api.iterable.Extractor; //导入依赖的package包/类
/**
* Extract multiple values from each {@code Iterable}'s element according to the given {@code Extractor}s
* and concatenate/flatten the extracted values in a list that is used as the new object under test.
* <p>
* If extracted values were not flattened, instead of a simple list like (given 2 extractors) :
* <pre>element1.value1, element1.value2, element2.value1, element2.value2, ... </pre>
* we would get a list of list like :
* <pre>list(element1.value1, element1.value2), list(element2.value1, element2.value2), ... </pre>
* <p>
* Code example:
* <pre><code class='java'> // fellowshipOfTheRing is a List<TolkienCharacter>
*
* // values are extracted in order and flattened : age1, name1, age2, name2, age3 ...
* assertThat(fellowshipOfTheRing).flatExtracting(TolkienCharacter::getAge,
* TolkienCharacter::getName)
* .contains(33 ,"Frodo",
* 1000, "Legolas",
* 87, "Aragorn");</code></pre>
*
* The resulting extracted values list is ordered by {@code Iterable}'s element first and then extracted values,
* this is why is in the example that age values come before names.
*
* @param extractors all the extractors to apply on each actual {@code Iterable}'s elements
* @return a new assertion object whose object under test is a flattened list of all extracted values.
*/
@CheckReturnValue
public AbstractListAssert<?, List<? extends Object>, Object, ObjectAssert<Object>> flatExtracting(@SuppressWarnings("unchecked") Extractor<? super ELEMENT, ?>... extractors) {
Stream<? extends ELEMENT> actualStream = stream(actual.spliterator(), false);
List<Object> result = actualStream.flatMap(element -> Stream.of(extractors)
.map(extractor -> extractor.extract(element)))
.collect(Collectors.toList());
return newListAssertInstance(result);
}
开发者ID:joel-costigliola,项目名称:assertj-core,代码行数:34,代码来源:AbstractIterableAssert.java
示例18: extracting
import org.assertj.core.api.iterable.Extractor; //导入依赖的package包/类
/**
* Extract the values from the array's elements by applying an extracting function on them. The returned
* array becomes a new object under test.
* <p>
* It allows to test values from the elements in safer way than by using {@link #extracting(String)}, as it
* doesn't utilize introspection.
* <p>
* Let's take a look an example:
* <pre><code class='java'> // Build a list of TolkienCharacter, a TolkienCharacter has a name, and age and a Race (a specific class)
* // they can be public field or properties, both can be extracted.
* AtomicReferenceArray<TolkienCharacter> fellowshipOfTheRing = new AtomicReferenceArray<>(new TolkienCharacter[]{
* new TolkienCharacter("Frodo", 33, HOBBIT),
* new TolkienCharacter("Sam", 38, HOBBIT),
* new TolkienCharacter("Gandalf", 2020, MAIA),
* new TolkienCharacter("Legolas", 1000, ELF),
* new TolkienCharacter("Pippin", 28, HOBBIT),
* new TolkienCharacter("Gimli", 139, DWARF),
* new TolkienCharacter("Aragorn", 87, MAN,
* new TolkienCharacter("Boromir", 37, MAN)
* };
*
*
* // this extracts the race
* Extractor<TolkienCharacter, Race> race = new Extractor<TolkienCharacter, Race>() {
* {@literal @}Override
* public Race extract(TolkienCharacter input) {
* return input.getRace();
* }
* }
*
* // fellowship has hobbits, right, my presioussss?
* assertThat(fellowshipOfTheRing).extracting(race).contains(HOBBIT);</code></pre>
*
* Note that the order of extracted property/field values is consistent with the iteration order of the Iterable under
* test, for example if it's a {@link HashSet}, you won't be able to make any assumptions on the extracted values
* order.
*
* @param <U> the extracted values type
* @param extractor the object transforming input object to desired one
* @return a new assertion object whose object under test is the list of values extracted
* @since 2.7.0 / 3.7.0
*/
@CheckReturnValue
public <U> ObjectArrayAssert<U> extracting(Extractor<? super T, U> extractor) {
U[] extracted = FieldsOrPropertiesExtractor.extract(array, extractor);
return new ObjectArrayAssert<>(extracted);
}
开发者ID:joel-costigliola,项目名称:assertj-core,代码行数:49,代码来源:AtomicReferenceArrayAssert.java
示例19: linkText
import org.assertj.core.api.iterable.Extractor; //导入依赖的package包/类
/**
* Get selenium extractor.
*
* @return {@code Extractor<WebElement, String>}
*/
public static Extractor<WebElement, String> linkText() {
return new SeleniumExtractor();
}
开发者ID:Stratio,项目名称:bdt,代码行数:9,代码来源:SeleniumExtractor.java
示例20: toStringMethod
import org.assertj.core.api.iterable.Extractor; //导入依赖的package包/类
/**
* Provides extractor for extracting {@link java.lang.Object#toString} from any object
* @return the built {@link Extractor}
*/
public static Extractor<Object, String> toStringMethod() {
return new ToStringExtractor();
}
开发者ID:joel-costigliola,项目名称:assertj-core,代码行数:8,代码来源:Extractors.java
注:本文中的org.assertj.core.api.iterable.Extractor类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论