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

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

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

AbstractByteArrayAssert.containsExactly介绍

[英]Verifies that the actual group contains only the given values and nothing else, in order.

Example :

// assertion will pass 
assertThat(new byte[] { 1, 2, 3 }).containsExactly((byte) 1, (byte) 2, (byte) 3); 
// assertion will fail as actual and expected order differ 
assertThat(new byte[] { 1, 2, 3 }).containsExactly((byte) 2, (byte) 1, (byte) 3);

[中]按顺序验证实际组是否仅包含给定值而不包含其他值。
例子:

// assertion will pass 
assertThat(new byte[] { 1, 2, 3 }).containsExactly((byte) 1, (byte) 2, (byte) 3); 
// assertion will fail as actual and expected order differ 
assertThat(new byte[] { 1, 2, 3 }).containsExactly((byte) 2, (byte) 1, (byte) 3);

代码示例

代码示例来源:origin: line/armeria

@Test
public void serializeResponse() throws Exception {
  final ByteBuf serialized = marshaller.serializeResponse(GrpcTestUtil.RESPONSE_MESSAGE);
  assertThat(ByteBufUtil.getBytes(serialized))
      .containsExactly(GrpcTestUtil.RESPONSE_MESSAGE.toByteArray());
  serialized.release();
}

代码示例来源:origin: line/armeria

@Test
public void serializeRequest() throws Exception {
  final ByteBuf serialized = marshaller.serializeRequest(GrpcTestUtil.REQUEST_MESSAGE);
  assertThat(ByteBufUtil.getBytes(serialized))
      .containsExactly(GrpcTestUtil.REQUEST_MESSAGE.toByteArray());
  serialized.release();
}

代码示例来源:origin: line/armeria

@Test
public void grpcWeb() throws Exception {
  final HttpClient client = HttpClient.of(server.httpUri("/"));
  final AggregatedHttpMessage response = client.execute(
      HttpHeaders.of(HttpMethod.POST,
              UnitTestServiceGrpc.getStaticUnaryCallMethod().getFullMethodName())
            .set(HttpHeaderNames.CONTENT_TYPE, "application/grpc-web"),
      GrpcTestUtil.uncompressedFrame(GrpcTestUtil.requestByteBuf())).aggregate().get();
  final byte[] serializedStatusHeader = "grpc-status: 0\r\n".getBytes(StandardCharsets.US_ASCII);
  final byte[] serializedTrailers = Bytes.concat(
      new byte[] { ArmeriaServerCall.TRAILERS_FRAME_HEADER },
      Ints.toByteArray(serializedStatusHeader.length),
      serializedStatusHeader);
  assertThat(response.content().array()).containsExactly(
      Bytes.concat(
          GrpcTestUtil.uncompressedFrame(
              GrpcTestUtil.protoByteBuf(RESPONSE_MESSAGE)),
          serializedTrailers));
  checkRequestLog((rpcReq, rpcRes, grpcStatus) -> {
    assertThat(rpcReq.method()).isEqualTo("armeria.grpc.testing.UnitTestService/StaticUnaryCall");
    assertThat(rpcReq.params()).containsExactly(REQUEST_MESSAGE);
    assertThat(rpcRes.get()).isEqualTo(RESPONSE_MESSAGE);
  });
}

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

@Test
public void migrateRevertsUncommittedWritesAndMigratesMostRecentlyCommitted() {
  fromKvs.createTables(TEST_AND_CHECKPOINT_TABLES);
  fromTxManager.runTaskWithRetry(tx -> {
    tx.put(TEST_TABLE, ImmutableMap.of(TEST_CELL, TEST_VALUE1));
    return tx.getTimestamp();
  });
  long uncommittedTs = fromServices.getTimestampService().getFreshTimestamp();
  fromKvs.put(TEST_TABLE, ImmutableMap.of(TEST_CELL, TEST_VALUE2), uncommittedTs);
  KeyValueServiceMigrator migrator = KeyValueServiceMigrators.setupMigrator(migratorSpec);
  migrator.setup();
  migrator.migrate();
  assertThat(fromServices.getTransactionService().get(uncommittedTs))
      .isEqualTo(TransactionConstants.FAILED_COMMIT_TS);
  assertThat(toKvs.get(TEST_TABLE, ImmutableMap.of(TEST_CELL, Long.MAX_VALUE)).get(TEST_CELL).getContents())
      .containsExactly(TEST_VALUE1);
}

代码示例来源:origin: spring-projects/spring-restdocs

@Test
public void multipartUpload() throws Exception {
  MultiValueMap<String, Object> multipartData = new LinkedMultiValueMap<>();
  multipartData.add("file", new byte[] { 1, 2, 3, 4 });
  ExchangeResult result = WebTestClient
      .bindToRouterFunction(RouterFunctions.route(POST("/foo"), (req) -> {
        req.body(BodyExtractors.toMultipartData()).block();
        return null;
      })).configureClient().baseUrl("http://localhost").build().post()
      .uri("/foo").body(BodyInserters.fromMultipartData(multipartData))
      .exchange().expectBody().returnResult();
  OperationRequest request = this.converter.convert(result);
  assertThat(request.getUri()).isEqualTo(URI.create("http://localhost/foo"));
  assertThat(request.getMethod()).isEqualTo(HttpMethod.POST);
  assertThat(request.getParts()).hasSize(1);
  OperationRequestPart part = request.getParts().iterator().next();
  assertThat(part.getName()).isEqualTo("file");
  assertThat(part.getSubmittedFileName()).isNull();
  assertThat(part.getHeaders()).hasSize(2);
  assertThat(part.getHeaders().getContentLength()).isEqualTo(4L);
  assertThat(part.getHeaders().getContentDisposition().getName()).isEqualTo("file");
  assertThat(part.getContent()).containsExactly(1, 2, 3, 4);
}

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

@Test
public void tablesDelegatedToSourceKvsGetDroppedFromSourceKvsIfMigratable() {
  fromKvs.createTable(FAKE_ATOMIC_TABLE, AtlasDbConstants.GENERIC_TABLE_METADATA);
  fromKvs.putUnlessExists(FAKE_ATOMIC_TABLE, ImmutableMap.of(TEST_CELL, TEST_VALUE1));
  KeyValueService toTableSplittingKvs = TableSplittingKeyValueService.create(
      ImmutableList.of(new InMemoryKeyValueService(false), fromKvs),
      ImmutableMap.of(FAKE_ATOMIC_TABLE, fromKvs));
  AtlasDbServices toSplittingServices = createMock(toTableSplittingKvs);
  ImmutableMigratorSpec spec  = ImmutableMigratorSpec.builder()
      .fromServices(fromServices)
      .toServices(toSplittingServices)
      .build();
  assertThat(toSplittingServices.getKeyValueService()
      .get(FAKE_ATOMIC_TABLE, ImmutableMap.of(TEST_CELL, 1L)).get(TEST_CELL).getContents())
      .containsExactly(TEST_VALUE1);
  KeyValueServiceMigrator migrator = KeyValueServiceMigrators.setupMigrator(spec);
  migrator.setup();
  assertThat(fromKvs.getAllTableNames()).doesNotContain(FAKE_ATOMIC_TABLE);
}

代码示例来源:origin: spring-projects/spring-restdocs

assertThat(contentDisposition.getFilename()).isEqualTo("image.png");
assertThat(part.getHeaders().getContentType()).isEqualTo(MediaType.IMAGE_PNG);
assertThat(part.getContent()).containsExactly(1, 2, 3, 4);

代码示例来源:origin: aafomin/gerbera

@Test
  public void testBytesAlignedAlignOddStringLength() {
    byte[] bytes = HexUtils.asBytesAligned("10203", 4);
    assertThat(bytes).containsExactly(0x00, 0x01, 0x02, 0x03);
  }
}

代码示例来源:origin: aafomin/gerbera

@Test
public void testLeadingZero() {
  byte[] decoded = Base58CheckUtils.decode("15sPzhL1ouhNBTAtdT");
  assertThat(decoded).containsExactly(0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
}

代码示例来源:origin: aafomin/gerbera

@Test
public void testMultipleLeadingZeros() {
  byte[] decoded = Base58CheckUtils.decode("111kdY9bfye13qL4rbC4");
  assertThat(decoded).containsExactly(0, 0, 0, 9, 8, 7, 6, 5, 4, 3, 2, 1);
}

代码示例来源:origin: aafomin/gerbera

@Test
public void testOneByteZero() {
  byte[] decoded = Base58CheckUtils.decode("1Wh4bh");
  assertThat(decoded).containsExactly(0);
}

代码示例来源:origin: org.apache.james/apache-james-mailbox-jpa

/**
 * Even though there should never be a null body, it does happen. See JAMES-2384
 */
@Test
public void getFullContentShouldReturnOriginalContentWhenBodyFieldIsNull() throws Exception {
  // Prepare the message
  byte[] content = "Subject: the null message".getBytes(StandardCharsets.UTF_8);
  JPAMailboxMessage message = new JPAMailboxMessage(content, null);
  // Get and check
  assertThat(IOUtils.toByteArray(message.getFullContent())).containsExactly(content);
}

代码示例来源:origin: aafomin/gerbera

@Test
public void testThreeByteVarInt() {
  VarInt varIntMin = VarInt.of(0xFDL);
  assertThat(varIntMin.toString()).isEqualTo("fdfd00");
  assertThat(varIntMin.asLitEndBytes()).containsExactly(0xFD, 0xFD, 0x00);
  VarInt varInt1000 = VarInt.of(0x3E8L);
  assertThat(varInt1000.toString()).isEqualTo("fde803");
  assertThat(varInt1000.asLitEndBytes()).containsExactly(0xFD, 0xE8, 0x03);
  VarInt varIntMax = VarInt.of(0xFFFFL);
  assertThat(varIntMax.toString()).isEqualTo("fdffff");
  assertThat(varIntMax.asLitEndBytes()).containsExactly(0xFD, 0xFF, 0xFF);
}

代码示例来源:origin: aafomin/gerbera

@Test
public void testFiveByteVarInt() {
  VarInt varIntMin = VarInt.of(0x10000L);
  assertThat(varIntMin.toString()).isEqualTo("fe00000100");
  assertThat(varIntMin.asLitEndBytes()).containsExactly(0xFE, 0x00, 0x00, 0x01, 0x00);
  VarInt varIntAllBytes = VarInt.of(0xAABBCCDDL);
  assertThat(varIntAllBytes.toString()).isEqualTo("feddccbbaa");
  assertThat(varIntAllBytes.asLitEndBytes()).containsExactly(0xFE, 0xDD, 0xCC, 0xBB, 0xAA);
  VarInt varIntMax = VarInt.of(0xFFFFFFFFL);
  assertThat(varIntMax.toString()).isEqualTo("feffffffff");
  assertThat(varIntMax.asLitEndBytes()).containsExactly(0xFE, 0xFF, 0xFF, 0xFF, 0xFF);
}

代码示例来源:origin: serj-lotutovici/moshi-lazy-adapters

@Test public void serializesOnlyNonEmptyByteArray() throws Exception {
 JsonAdapter<Data1> adapter = moshi.adapter(Data1.class);
 Data1 fromJson = adapter.fromJson("{\n"
   + "\"byteArray\": [1]\n"
   + "}");
 assertThat(fromJson.byteArray).containsExactly((byte) 1);
 fromJson.byteArray = new byte[0];
 assertThat(adapter.toJson(fromJson)).isEqualTo("{}");
 fromJson.byteArray = new byte[] { 5 };
 assertThat(adapter.toJson(fromJson)).isEqualTo("{\"byteArray\":[5]}");
}

代码示例来源:origin: aafomin/gerbera

@Test
public void testMinValue() {
  ULong value = ULong.of(0);
  assertThat(value.toString()).isEqualTo("0000000000000000");
  assertThat(value.asLitEndBytes()).containsExactly(0, 0, 0, 0, 0, 0, 0, 0);
}

代码示例来源:origin: aafomin/gerbera

@Test
public void testMaxValue() {
  ULong value = ULong.of(0xFFFFFFFFFFFFFFFFL);
  assertThat(value.toString()).isEqualTo("ffffffffffffffff");
  assertThat(value.asLitEndBytes()).containsExactly(0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF);
}

代码示例来源:origin: aafomin/gerbera

@Test
  public void testDiffBytes() {
    ULong value = ULong.of(0x1122334455667788L);
    assertThat(value.toString()).isEqualTo("8877665544332211");
    assertThat(value.asLitEndBytes()).containsExactly(0x88, 0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11);
  }
}

代码示例来源:origin: line/line-bot-sdk-java

@Test
public void parseBytesOrNullTestForValidValue() throws Exception {
  // Do
  byte[] bytes = BeaconContentUtil.parseBytesOrNull("0123");
  // Verify
  assertThat(bytes).containsExactly(0x01, 0x23);
}

代码示例来源:origin: org.apache.james/james-server-jmap-integration-testing

public void checkBlobContent(String blobId, byte[] rawBytes) {
  byte[] attachmentBytes = with()
    .header("Authorization", accessToken.serialize())
    .get("/download/" + blobId)
  .then()
    .extract()
    .body()
    .asByteArray();
  assertThat(attachmentBytes).containsExactly(rawBytes);
}

相关文章