org.assertj.core.api.AbstractByteArrayAssert.contains()方法的使用及代码示例

x33g5p2x  于2022-01-15 转载在 其他  
字(8.4k)|赞(0)|评价(0)|浏览(90)

本文整理了Java中org.assertj.core.api.AbstractByteArrayAssert.contains()方法的一些代码示例,展示了AbstractByteArrayAssert.contains()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。AbstractByteArrayAssert.contains()方法的具体详情如下:
包路径:org.assertj.core.api.AbstractByteArrayAssert
类名称:AbstractByteArrayAssert
方法名:contains

AbstractByteArrayAssert.contains介绍

[英]Verifies that the actual array contains the given value at the given index.

Example:

// assertion will pass 
assertThat(new byte[] { 1, 2, 3 }).contains((byte) 1, atIndex(O)); 
assertThat(new byte[] { 1, 2, 3 }).contains((byte) 3, atIndex(2)); 
// assertion will fail 
assertThat(new byte[] { 1, 2, 3 }).contains((byte) 1, atIndex(1)); 
assertThat(new byte[] { 1, 2, 3 }).contains((byte) 4, atIndex(2));

[中]验证实际数组是否包含给定索引处的给定值。
例子:

// assertion will pass 
assertThat(new byte[] { 1, 2, 3 }).contains((byte) 1, atIndex(O)); 
assertThat(new byte[] { 1, 2, 3 }).contains((byte) 3, atIndex(2)); 
// assertion will fail 
assertThat(new byte[] { 1, 2, 3 }).contains((byte) 1, atIndex(1)); 
assertThat(new byte[] { 1, 2, 3 }).contains((byte) 4, atIndex(2));

代码示例

代码示例来源:origin: palantir/atlasdb

@Test
public void tableReferencesAreCaseSensitiveForPutAndGet() {
  createTablesIgnoringException();
  kvs.put(UPPER_UPPER, ImmutableMap.of(CELL, BYTE_ARRAY), 1);
  kvs.put(LOWER_LOWER, ImmutableMap.of(CELL, SECOND_BYTE_ARRAY), 1);
  assertThat(kvs.get(UPPER_UPPER, ImmutableMap.of(CELL, 2L)).get(CELL).getContents()).contains(BYTE_ARRAY);
  assertThat(kvs.get(LOWER_UPPER, ImmutableMap.of(CELL, 2L))).doesNotContainKey(CELL);
  assertThat(kvs.get(LOWER_LOWER, ImmutableMap.of(CELL, 2L)).get(CELL).getContents()).contains(SECOND_BYTE_ARRAY);
}

代码示例来源:origin: palantir/atlasdb

@Test
public void getMetadataReturnsResultFromNewMetadataCellOnConflict() {
  kvs.createTable(LOWER_UPPER, ORIGINAL_METADATA);
  insertGenericMetadataIntoLegacyCell(kvs, LOWER_UPPER);
  assertThat(kvs.getMetadataForTables().get(LOWER_UPPER)).contains(ORIGINAL_METADATA);
  assertThat(kvs.getMetadataForTable(LOWER_UPPER)).contains(ORIGINAL_METADATA);
}

代码示例来源:origin: palantir/atlasdb

@Test
public void tableCreationAppearsToSucceedButIsNoop() {
  kvs.createTable(UPPER_UPPER, AtlasDbConstants.GENERIC_TABLE_METADATA);
  kvs.createTable(LOWER_LOWER, AtlasDbConstants.GENERIC_TABLE_METADATA);
  kvs.put(UPPER_UPPER, ImmutableMap.of(CELL, BYTE_ARRAY), 1);
  assertThat(kvs.get(UPPER_UPPER, ImmutableMap.of(CELL, 2L)).get(CELL).getContents()).contains(BYTE_ARRAY);
  assertThatThrownBy(() -> kvs.get(LOWER_LOWER, ImmutableMap.of(CELL, 2L)))
      .isInstanceOf(RetryLimitReachedException.class);
  assertThatThrownBy(() -> kvs.put(LOWER_LOWER, ImmutableMap.of(CELL, SECOND_BYTE_ARRAY), 1))
      .isInstanceOf(RetryLimitReachedException.class);
}

代码示例来源:origin: palantir/atlasdb

@Test
public void nonExistentTablesWithMetadataReturnMetadata() {
  insertMetadataIntoNewCell(LOWER_UPPER);
  assertThat(kvs.getMetadataForTable(LOWER_UPPER)).contains(AtlasDbConstants.GENERIC_TABLE_METADATA);
}

代码示例来源:origin: palantir/atlasdb

@Test
public void tableReferencesAreCaseSensitiveForDrop() {
  kvs.createTable(LOWER_UPPER, AtlasDbConstants.GENERIC_TABLE_METADATA);
  kvs.dropTable(LOWER_LOWER);
  assertThat(kvs.getAllTableNames()).containsExactly(LOWER_UPPER);
  assertThat(kvs.getMetadataForTable(LOWER_UPPER)).contains(AtlasDbConstants.GENERIC_TABLE_METADATA);
}

代码示例来源:origin: zeebe-io/zeebe

/**
 * Verifies that the actual DeploymentResource's resource contains the given byte elements.
 * @param resource the given elements that should be contained in actual DeploymentResource's resource.
 * @return this assertion object.
 * @throws AssertionError if the actual DeploymentResource's resource does not contain all given byte elements.
 */
public S hasResource(byte... resource) {
 // check that actual DeploymentResource we want to make assertions on is not null.
 isNotNull();
 // check that given byte varargs is not null.
 if (resource == null) failWithMessage("Expecting resource parameter not to be null.");
 // check with standard error message (use overridingErrorMessage before contains to set your own message).
 Assertions.assertThat(actual.getResource()).contains(resource);
 // return the current assertion for method chaining
 return myself;
}

代码示例来源:origin: allegro/hermes

@Test
@SuppressWarnings("unchecked")
public void shouldWrappedMessageContainsMetadata() throws IOException {
  // when
  byte[] wrappedMessage = avroMessageContentWrapper.wrapContent(content, id, timestamp, avroUser.getSchema(), Collections.emptyMap());
  // then
  GenericRecord messageWithMetadata = bytesToRecord(wrappedMessage, avroUser.getSchema());
  Map<Utf8, Utf8> metadata = (Map<Utf8, Utf8>) messageWithMetadata.get(METADATA_MARKER);
  assertThat(metadata.get(METADATA_MESSAGE_ID_KEY).toString()).isEqualTo(id);
  assertThat(valueOf(metadata.get(METADATA_TIMESTAMP_KEY).toString())).isEqualTo(timestamp);
  assertThat(wrappedMessage).contains(content);
}

代码示例来源:origin: bonitasoft/bonita-engine

/**
 * Verifies that the actual BonitaConfiguration's resourceContent contains the given byte elements.
 * @param resourceContent the given elements that should be contained in actual BonitaConfiguration's resourceContent.
 * @return this assertion object.
 * @throws AssertionError if the actual BonitaConfiguration's resourceContent does not contain all given byte elements.
 */
public BonitaConfigurationAssert hasResourceContent(byte... resourceContent) {
 // check that actual BonitaConfiguration we want to make assertions on is not null.
 isNotNull();
 // check that given byte varargs is not null.
 if (resourceContent == null) failWithMessage("Expecting resourceContent parameter not to be null.");
 
 // check with standard error message (use overridingErrorMessage before contains to set your own message).
 Assertions.assertThat(actual.getResourceContent()).contains(resourceContent);
 // return the current assertion for method chaining
 return this;
}

代码示例来源:origin: allegro/hermes

@Test
public void shouldWrapAndUnwrapAvroMessageWithMetadata() throws IOException {
  // when
  byte [] wrappedMessage = avroMessageContentWrapper.wrapContent(content, id, timestamp, avroUser.getSchema(), Collections.emptyMap());
  UnwrappedMessageContent unwrappedMessageContent = avroMessageContentWrapper.unwrapContent(wrappedMessage, avroUser.getCompiledSchema());
  // then
  assertThat(unwrappedMessageContent.getMessageMetadata().getId()).isEqualTo(id);
  assertThat(unwrappedMessageContent.getMessageMetadata().getTimestamp()).isEqualTo(timestamp);
  assertThat(unwrappedMessageContent.getContent()).contains(content);
}

代码示例来源:origin: allegro/hermes

public void shouldUnwrapMessageWrappedWithSchemaAtVersion(MessageContentWrapper wrapper, int schemaVersion, boolean wrapWithSchemaVersionAwarePayload,
                             boolean unwrapWithSchemaVersionAwarePayload, int missedSchemaVersionInPayload,
                             int errorsForPayloadWithSchemaVersion, int errorsForAnySchemaVersion,
                             int errorsForAnyOnlineSchemaVersion) {
  // given
  SchemaVersion version = SchemaVersion.valueOf(schemaVersion);
  Topic topicToWrap = createTopic("group", "topic", wrapWithSchemaVersionAwarePayload);
  Topic topicToUnwrap = createTopic("group", "topic", unwrapWithSchemaVersionAwarePayload);
  CompiledSchema<Schema> schema = schemaRepository.getKnownAvroSchemaVersion(topicToWrap, version);
  AvroUser user = new AvroUser(schema, "Bob", 15, "blue");
  byte[] wrapped = wrapper.wrapAvro(user.asBytes(), "uniqueId", 1234, topicToWrap, schema, new HashedMap<>());
  // when
  UnwrappedMessageContent unwrappedMessageContent = wrapper.unwrapAvro(wrapped, topicToUnwrap);
  // then
  assertThat(unwrappedMessageContent.getContent()).contains(user.asBytes());
  assertThat(unwrappedMessageContent.getSchema().get().getVersion()).isEqualTo(version);
  assertThat(unwrappedMessageContent.getMessageMetadata().getId()).isEqualTo("uniqueId");
  assertThat(unwrappedMessageContent.getMessageMetadata().getTimestamp()).isEqualTo(1234);
  assertThat(metrics.missedSchemaVersionInPayload().getCount()).isEqualTo(missedSchemaVersionInPayload);
  assertThat(metrics.errorsForSchemaVersionAwarePayload().getCount()).isEqualTo(errorsForPayloadWithSchemaVersion);
  assertThat(metrics.errorsForAnySchemaVersion().getCount()).isEqualTo(errorsForAnySchemaVersion);
  assertThat(metrics.errorsForAnyOnlineSchemaVersion().getCount()).isEqualTo(errorsForAnyOnlineSchemaVersion);
}

代码示例来源:origin: allegro/hermes

@Test
public void shouldUnwrapAvroMessageAndSetEmptyMessageIdWhenNotGivenInMetadata() throws Throwable {
  // given
  byte [] wrappedMessage = wrapContentWithoutMessageIdInMetadata(content, avroUser.getSchema());
  //when
  UnwrappedMessageContent unwrappedMessage = avroMessageContentWrapper.unwrapContent(wrappedMessage, avroUser.getCompiledSchema());
  // then
  assertThat(unwrappedMessage.getMessageMetadata().getId()).isEmpty();
  assertThat(unwrappedMessage.getMessageMetadata().getTimestamp()).isNotNull();
  assertThat(unwrappedMessage.getContent()).contains(content);
}

相关文章