Java源码示例:org.assertj.core.api.ObjectAssert
示例1
@Test
void unixSocket() {
for (SslMode mode : SslMode.values()) {
if (mode.startSsl()) {
assertThatIllegalArgumentException().isThrownBy(() -> unixSocketSslMode(mode)).withMessageContaining("sslMode");
} else {
assertThat(unixSocketSslMode(SslMode.DISABLED)).isNotNull();
}
}
ObjectAssert<MySqlConnectionConfiguration> asserted = assertThat(MySqlConnectionConfiguration.builder()
.unixSocket(UNIX_SOCKET)
.user(USER)
.build());
asserted.extracting(MySqlConnectionConfiguration::getDomain).isEqualTo(UNIX_SOCKET);
asserted.extracting(MySqlConnectionConfiguration::getUser).isEqualTo(USER);
asserted.extracting(MySqlConnectionConfiguration::isHost).isEqualTo(false);
asserted.extracting(MySqlConnectionConfiguration::getSsl).extracting(MySqlSslConfiguration::getSslMode).isEqualTo(SslMode.DISABLED);
}
示例2
@Test
void hosted() {
for (SslMode mode : SslMode.values()) {
if (mode.verifyCertificate()) {
assertThatIllegalArgumentException().isThrownBy(() -> hostedSslMode(mode, null)).withMessageContaining("sslCa");
assertThat(hostedSslMode(mode, SSL_CA)).isNotNull();
} else {
assertThat(hostedSslMode(mode, null)).isNotNull();
}
}
ObjectAssert<MySqlConnectionConfiguration> asserted = assertThat(MySqlConnectionConfiguration.builder()
.host(HOST)
.user(USER)
.build());
asserted.extracting(MySqlConnectionConfiguration::getDomain).isEqualTo(HOST);
asserted.extracting(MySqlConnectionConfiguration::getUser).isEqualTo(USER);
asserted.extracting(MySqlConnectionConfiguration::isHost).isEqualTo(true);
asserted.extracting(MySqlConnectionConfiguration::getSsl).extracting(MySqlSslConfiguration::getSslMode).isEqualTo(SslMode.PREFERRED);
}
示例3
@Test
void assemblyHook() {
List<Object> publishers = new ArrayList<>();
Hooks.onEachOperator(objectPublisher -> {
publishers.add(objectPublisher);
return objectPublisher;
});
Iterator<Integer> items = createItems(5);
Flux<Integer> flux = Flux.fromIterable(() -> items);
flux.transform(OperatorUtils::discardOnCancel)
.as(StepVerifier::create)
.expectNextCount(5)
.verifyComplete();
ObjectAssert<?> element = assertThat(publishers).hasSize(2).element(1);
if (flux instanceof Fuseable) {
element.isExactlyInstanceOf(FluxDiscardOnCancelFuseable.class);
} else {
element.isExactlyInstanceOf(FluxDiscardOnCancel.class);
}
}
示例4
@Test
void unixSocket() {
for (SslMode mode : SslMode.values()) {
if (mode.startSsl()) {
assertThatIllegalArgumentException().isThrownBy(() -> unixSocketSslMode(mode)).withMessageContaining("sslMode");
} else {
assertThat(unixSocketSslMode(SslMode.DISABLED)).isNotNull();
}
}
ObjectAssert<MySqlConnectionConfiguration> asserted = assertThat(MySqlConnectionConfiguration.builder()
.unixSocket(UNIX_SOCKET)
.user(USER)
.build());
asserted.extracting(MySqlConnectionConfiguration::getDomain).isEqualTo(UNIX_SOCKET);
asserted.extracting(MySqlConnectionConfiguration::getUser).isEqualTo(USER);
asserted.extracting(MySqlConnectionConfiguration::isHost).isEqualTo(false);
asserted.extracting(MySqlConnectionConfiguration::getSsl).extracting(MySqlSslConfiguration::getSslMode).isEqualTo(SslMode.DISABLED);
}
示例5
@Test
void hosted() {
for (SslMode mode : SslMode.values()) {
if (mode.verifyCertificate()) {
assertThatIllegalArgumentException().isThrownBy(() -> hostedSslMode(mode, null)).withMessageContaining("sslCa");
assertThat(hostedSslMode(mode, SSL_CA)).isNotNull();
} else {
assertThat(hostedSslMode(mode, null)).isNotNull();
}
}
ObjectAssert<MySqlConnectionConfiguration> asserted = assertThat(MySqlConnectionConfiguration.builder()
.host(HOST)
.user(USER)
.build());
asserted.extracting(MySqlConnectionConfiguration::getDomain).isEqualTo(HOST);
asserted.extracting(MySqlConnectionConfiguration::getUser).isEqualTo(USER);
asserted.extracting(MySqlConnectionConfiguration::isHost).isEqualTo(true);
asserted.extracting(MySqlConnectionConfiguration::getSsl).extracting(MySqlSslConfiguration::getSslMode).isEqualTo(SslMode.PREFERRED);
}
示例6
@Test
void assemblyHook() {
List<Object> publishers = new ArrayList<>();
Hooks.onEachOperator(objectPublisher -> {
publishers.add(objectPublisher);
return objectPublisher;
});
Iterator<Integer> items = createItems(5);
Flux<Integer> flux = Flux.fromIterable(() -> items);
flux.transform(OperatorUtils::discardOnCancel)
.as(StepVerifier::create)
.expectNextCount(5)
.verifyComplete();
ObjectAssert<?> element = assertThat(publishers).hasSize(2).element(1);
if (flux instanceof Fuseable) {
element.isExactlyInstanceOf(FluxDiscardOnCancelFuseable.class);
} else {
element.isExactlyInstanceOf(FluxDiscardOnCancel.class);
}
}
示例7
@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));
}
示例8
private ObjectAssert<Filter> assertFilterMatches(Expression expression, String propName, FilterType type, Serializable value) {
return assertThat(expression)
.asInstanceOf(type(Filter.class))
.satisfies(filter -> {
assertThat(filter.getPropertyName()).isEqualTo(propName);
assertThat(filter.getFilterType()).isEqualTo(type);
assertThat(filter.getFilterValue()).isEqualTo(value.toString());
}
);
}
示例9
@Test
public void shouldGetMilestonesInfo() throws RemoteResourceException {
ArtifactClient client = new ArtifactClient(RestClientConfiguration.asAnonymous());
RemoteCollection<MilestoneInfo> milestonesInfo = client.getMilestonesInfo(artifactRest3.getId());
assertThat(milestonesInfo).hasSize(1).first().extracting(MilestoneInfo::isBuilt).isEqualTo(false);
RemoteCollection<MilestoneInfo> milestonesInfo2 = client.getMilestonesInfo(artifactRest1.getId());
ObjectAssert<MilestoneInfo> milestone = assertThat(milestonesInfo2).hasSize(1).first();
milestone.extracting(MilestoneInfo::isBuilt).isEqualTo(true);
milestone.extracting(MilestoneInfo::getProductName).isEqualTo("Project Newcastle Demo Product");
milestone.extracting(MilestoneInfo::getMilestoneVersion).isEqualTo("1.0.0.Build1");
}
示例10
/**
* 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);
}
示例11
private AbstractListAssert<?, List<?>, Object, ObjectAssert<Object>> assertThatDataSourceDecoratingChain(DataSource dataSource) {
return assertThat(((DecoratedDataSource) dataSource).getDecoratingChain()).extracting("dataSource").extracting("class");
}
示例12
@Override
protected ObjectAssert<ConditionEvent> toAssert(ConditionEvent value, String description) {
return new ObjectAssertFactory<ConditionEvent>().createAssert(value).as(description);
}
示例13
@Override
protected ObjectAssert<JavaClass> toAssert(JavaClass value, String description) {
return new ObjectAssertFactory<JavaClass>().createAssert(value).as(description);
}
示例14
@Override
protected ObjectAssert<ThrowsDeclaration<?>> toAssert(ThrowsDeclaration<?> value, String description) {
return new ObjectAssertFactory<ThrowsDeclaration<?>>().createAssert(value).as(description);
}
示例15
@Override
protected ObjectAssert<JsonField> toAssert(final JsonField jsonField, final String description) {
final AssertFactory<JsonField, ObjectAssert<JsonField>> objectAssertFactory = new ObjectAssertFactory<>();
return objectAssertFactory.createAssert(jsonField).as(description);
}
示例16
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);
}
示例17
static <T> ObjectAssert<T> assertFuture(CompletionStage<T> decisionFuture) {
return assertThat(decisionFuture.toCompletableFuture().join());
}
示例18
static ObjectAssert<Backoff> assertBackoff(CompletionStage<RetryDecision> future) {
return assertThat(future.toCompletableFuture().join().backoff());
}
示例19
static <T> AbstractObjectAssert<?, T> assertThat(T actual) {
return new ObjectAssert<>(actual);
}
示例20
public ObjectAssert<V> assertThatSuccess() {
return assertThat(join());
}