Java源码示例:org.assertj.core.api.AbstractListAssert
示例1
@SuppressWarnings("unchecked")
@Test
void deletesShouldCallEventDispatcher() throws Exception {
givenUnlimitedQuota();
MessageId messageId1 = testingData.persist(mailbox1.getMailboxId(), messageUid1, FLAGS, session);
MessageId messageId2 = testingData.persist(mailbox1.getMailboxId(), messageUid2, FLAGS, session);
MessageResult messageResult1 = messageIdManager.getMessage(messageId1, FetchGroup.MINIMAL, session).get(0);
MessageMetaData simpleMessageMetaData1 = messageResult1.messageMetaData();
MessageResult messageResult2 = messageIdManager.getMessage(messageId2, FetchGroup.MINIMAL, session).get(0);
MessageMetaData simpleMessageMetaData2 = messageResult2.messageMetaData();
eventBus.register(eventCollector);
messageIdManager.delete(ImmutableList.of(messageId1, messageId2), session);
AbstractListAssert<?, List<? extends MailboxListener.Expunged>, MailboxListener.Expunged, ObjectAssert<MailboxListener.Expunged>> events =
assertThat(eventCollector.getEvents())
.filteredOn(event -> event instanceof MailboxListener.Expunged)
.hasSize(2)
.extracting(event -> (MailboxListener.Expunged) event);
events.extracting(MailboxListener.MailboxEvent::getMailboxId).containsOnly(mailbox1.getMailboxId(), mailbox1.getMailboxId());
events.extracting(MailboxListener.Expunged::getExpunged)
.containsOnly(ImmutableSortedMap.of(simpleMessageMetaData1.getUid(), simpleMessageMetaData1),
ImmutableSortedMap.of(simpleMessageMetaData2.getUid(), simpleMessageMetaData2));
}
示例2
/**
* Extracting values of given node's attribute.
* If a node doesn't have the attribute then {@code null} value is return.
*
* @throws AssertionError if the actual nodes iterable is {@code null}.
* @since XMLUnit 2.6.4
*/
public AbstractListAssert<?, List<? extends String>, String, ObjectAssert<String>> extractingAttribute(String attribute) {
isNotNull();
List<String> values = new ArrayList<>();
for (Node node : actual) {
values.add(NodeUtils.attributeValue(node, attribute));
}
String extractedDescription = String.format("Extracted attribute: %s", attribute);
String description = Description.mostRelevantDescription(this.info.description(), extractedDescription);
return newListAssertInstance(values).as(description);
}
示例3
private AbstractListAssert<?, List<?>, Object, ObjectAssert<Object>> assertThatDataSourceDecoratingChain(DataSource dataSource) {
return assertThat(((DecoratedDataSource) dataSource).getDecoratingChain()).extracting("dataSource").extracting("class");
}
示例4
static AbstractListAssert<?, List<? extends String>, String, ObjectAssert<String>> assertThatFieldNamesToTag(
AssertableApplicationContext context) {
return assertThat(context.getBean(SpanHandler.class))
.isInstanceOf(BaggageTagSpanHandler.class).extracting("fieldsToTag")
.asInstanceOf(array(BaggageField[].class)).extracting(BaggageField::name);
}
示例5
@Test
public void listOfValuesEmittedReturnsValidAssertion() {
AbstractListAssert<?, ?, ?> listAssert = new BlockingObservableAssert<>(Observable.just("a", "b").toBlocking())
.listOfValuesEmitted();
assertThat(listAssert).isNotNull();
}
示例6
/**
* Allows performing Assertj assertions over the list of values emitted onNext()
*
* @return an instance of @{link ListAssert} initialized with the values received onNext()
*/
public AbstractListAssert<?, ? extends List<? extends T>, T> listOfValuesEmitted() {
isNotNull();
return assertThat(getBlockingObservableExecutor().getValuesEmitted());
}