org.assertj.core.api.AbstractByteArrayAssert类的使用及代码示例

x33g5p2x  于11个月前 转载在 其他  
字(10.4k)|赞(0)|评价(0)|浏览(27)

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

AbstractByteArrayAssert介绍

暂无

代码示例

代码示例来源:origin: square/wire

private void validate(OneOfMessage.Builder builder, Integer expectedFoo, String expectedBar,
   byte[] expectedBytes) throws IOException {
  // Check builder fields
  assertThat(builder.foo).isEqualTo(expectedFoo);
  assertThat(builder.bar).isEqualTo(expectedBar);

  // Check message fields.
  OneOfMessage message = builder.build();
  assertThat(message.foo).isEqualTo(expectedFoo);
  assertThat(message.bar).isEqualTo(expectedBar);

  // Check serialized bytes.
  byte[] bytes = adapter.encode(message);
  assertThat(expectedBytes).isEqualTo(bytes);

  // Check result of deserialization.
  OneOfMessage newMessage = adapter.decode(bytes);
  assertThat(newMessage.foo).isEqualTo(expectedFoo);
  assertThat(newMessage.bar).isEqualTo(expectedBar);
 }
}

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

@Test
public void subArray() {
  byte[] bytes = new byte[] { (byte) 0x01, (byte) 0xFF, (byte) 65, (byte) 66,
    (byte) 67, (byte) 0xC0, (byte) 0xC1, (byte) 0xC2 };
  byte[] two = new byte[] { (byte) 0xFF, (byte) 65, (byte) 66 };
  byte[] subArray = EncodingUtils.subArray(bytes, 1, 4);
  assertThat(subArray).hasSize(3);
  assertThat(Arrays.equals(two, subArray)).isTrue();
}

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

@Test
public void stronger() throws Exception {
  CryptoAssumptions.assumeGCMJCE();
  BytesEncryptor encryptor = Encryptors.stronger("password", "5c0744940b5c369b");
  byte[] result = encryptor.encrypt("text".getBytes("UTF-8"));
  assertThat(result).isNotNull();
  assertThat(new String(result).equals("text")).isFalse();
  assertThat(new String(encryptor.decrypt(result))).isEqualTo("text");
  assertThat(new String(result)).isNotEqualTo(
      new String(encryptor.encrypt("text".getBytes())));
}

代码示例来源:origin: SonarSource/sonarqube

@Test
public void getSecureMungedAddress() {
 byte[] address = MacAddressProvider.getSecureMungedAddress();
 assertThat(address).isNotEmpty();
 assertThat(address).hasSize(6);
}

代码示例来源:origin: apache/geode

@Test
public void testToByteArray() throws IOException {
 final byte[] expected = new byte[] {(byte) 0xCA, (byte) 0xFE, (byte) 0xBA, (byte) 0xBE};
 final byte[] actual = IOUtils.toByteArray(new ByteArrayInputStream(expected));
 assertThat(actual).isNotNull();
 assertThat(actual.length).isEqualTo(expected.length);
 assertThat(actual).isEqualTo(expected);
}

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

@Test
public void decodingOnlyProvidesAvailableBytes() {
  assertThat(BCrypt.decode_base64("", 1)).isEmpty();
  assertThat(BCrypt.decode_base64("......", 3)).hasSize(3);
  assertThat(BCrypt.decode_base64("......", 4)).hasSize(4);
  assertThat(BCrypt.decode_base64("......", 5)).hasSize(4);
}

代码示例来源: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: apache/geode

/**
 * final File expectedStatArchiveFile = new File(TestUtil.getResourcePath(getClass(),
 * "StatArchiveWriterReaderJUnitTest_" + this.testName.getMethodName() + "_expected.gfs"));
 */
public static void compareStatArchiveFiles(final File expectedStatArchiveFile,
  final File actualStatArchiveFile) throws IOException {
 assertThat(expectedStatArchiveFile).exists();
 assertThat(actualStatArchiveFile.length()).isEqualTo(expectedStatArchiveFile.length());
 assertThat(readBytes(actualStatArchiveFile)).isEqualTo(readBytes(expectedStatArchiveFile));
}

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

@Test
public void string() {
  StringKeyGenerator keyGenerator = KeyGenerators.string();
  String hexStringKey = keyGenerator.generateKey();
  assertThat(hexStringKey.length()).isEqualTo(16);
  assertThat(Hex.decode(hexStringKey)).hasSize(8);
  String hexStringKey2 = keyGenerator.generateKey();
  assertThat(hexStringKey.equals(hexStringKey2)).isFalse();
}

代码示例来源:origin: org.activiti.cloud.common/activiti-cloud-services-test

public AssertFileContent isFile() {
  assertThat(response).isNotNull();
  assertThat(response.getContentType()).isNotNull();
  assertThat(response.getContentAsByteArray()).isNotEmpty();
  assertThat(response.getHeader(CONTENT_DISPOSITION))
      .isNotEmpty()
      .startsWith(ATTACHMENT_CONTENT_DISPOSITION);
  String filename = response.getHeader(CONTENT_DISPOSITION)
      .substring(ATTACHMENT_CONTENT_DISPOSITION.length());
  return new AssertFileContent(new FileContent(filename,
                         response.getContentType(),
                         response.getContentAsByteArray()));
}

代码示例来源:origin: com.hubspot/Ringleader

@Test
public void itSendsEventWhenNodeIsDeleted() {
 watcher.start();
 waitForEvents();
 assertThat(curatorCounter.get()).isEqualTo(1);
 assertThat(events).hasSize(1);
 assertThat(events.get(0).getType()).isEqualTo(Type.NODE_UPDATED);
 assertThat(events.get(0).getStat().getVersion()).isEqualTo(0);
 assertThat(events.get(0).getData()).isEqualTo("0".getBytes());
 deleteData();
 waitForEvents();
 assertThat(curatorCounter.get()).isEqualTo(1);
 assertThat(events).hasSize(2);
 assertThat(events.get(1).getType()).isEqualTo(Type.NODE_DELETED);
 assertThat(events.get(1).getStat()).isNull();
 assertThat(events.get(1).getData()).isNull();
}

代码示例来源:origin: apache/geode

@Test
public void serializeToBlobWithNullReturnsBytesOfNull() throws Exception {
 byte[] bytes = serializeToBlob(null);
 assertThat(bytes).isNotNull().isEqualTo(this.bytesOfNull);
}

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

@Test
public void testReserializedNonTrusted() {
  DefaultKafkaHeaderMapper mapper = new DefaultKafkaHeaderMapper();
  Message<String> message = MessageBuilder.withPayload("foo")
      .setHeader("fix", new Foo())
      .build();
  RecordHeaders recordHeaders = new RecordHeaders();
  mapper.fromHeaders(message.getHeaders(), recordHeaders);
  assertThat(recordHeaders.toArray().length).isEqualTo(2); // 1 + json_types
  Map<String, Object> headers = new HashMap<>();
  mapper.toHeaders(recordHeaders, headers);
  assertThat(headers.get("fix")).isInstanceOf(NonTrustedHeaderType.class);
  NonTrustedHeaderType ntht = (NonTrustedHeaderType) headers.get("fix");
  assertThat(ntht.getHeaderValue()).isNotNull();
  assertThat(ntht.getUntrustedType()).isEqualTo(Foo.class.getName());
  assertThat(headers).hasSize(1);
  recordHeaders = new RecordHeaders();
  mapper.fromHeaders(new MessageHeaders(headers), recordHeaders);
  headers = new HashMap<>();
  mapper.toHeaders(recordHeaders, headers);
  assertThat(headers.get("fix")).isInstanceOf(NonTrustedHeaderType.class);
  ntht = (NonTrustedHeaderType) headers.get("fix");
  assertThat(ntht.getHeaderValue()).isNotNull();
  assertThat(ntht.getUntrustedType()).isEqualTo(Foo.class.getName());
  mapper.addTrustedPackages(getClass().getPackage().getName());
  headers = new HashMap<>();
  mapper.toHeaders(recordHeaders, headers);
  assertThat(headers.get("fix")).isInstanceOf(Foo.class);
}

代码示例来源:origin: SonarSource/sonarqube

@Test
public void select() {
 dbTester.prepareDbUnit(getClass(), "shared.xml");
 FileSourceDto fileSourceDto = underTest.selectByFileUuid(dbSession, "FILE1_UUID");
 assertThat(fileSourceDto.getBinaryData()).isNotEmpty();
 assertThat(fileSourceDto.getDataHash()).isEqualTo("hash");
 assertThat(fileSourceDto.getProjectUuid()).isEqualTo("PRJ_UUID");
 assertThat(fileSourceDto.getFileUuid()).isEqualTo("FILE1_UUID");
 assertThat(fileSourceDto.getCreatedAt()).isEqualTo(1500000000000L);
 assertThat(fileSourceDto.getUpdatedAt()).isEqualTo(1500000000000L);
 assertThat(fileSourceDto.getRevision()).isEqualTo("123456789");
 assertThat(fileSourceDto.getLineHashesVersion()).isEqualTo(0);
}

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

@Test
public void testAppend() {
  ByteBuffer buffer = new ByteBuffer();
  buffer.append((byte) 0);
  buffer.append(new byte[] { 1, 2 });
  buffer.append(new byte[] { 3, 4, 5 });
  assertThat(buffer.size()).isEqualTo(6);
  assertThat(buffer.bytes()).containsExactly(0, 1, 2, 3, 4, 5);
  assertThat(buffer.bytesReversed()).containsExactly(5, 4, 3, 2, 1, 0);
}

代码示例来源:origin: apache/geode

@Test
public void dataSerializes() throws Exception {
 PartitionRegionConfig config = new PartitionRegionConfig(prId, path, partitionAttributes, scope,
   evictionAttributes, regionIdleTimeout, regionTimeToLive, entryIdleTimeout, entryTimeToLive,
   gatewaySenderIds);
 byte[] bytes = BlobHelper.serializeToBlob(config);
 assertThat(bytes).isNotNull().isNotEmpty();
 assertThat(BlobHelper.deserializeBlob(bytes)).isNotSameAs(config)
   .isInstanceOf(PartitionRegionConfig.class);
}

代码示例来源:origin: springside/springside4

@Test
public void toBytes() {
  byte[] bytes = NumberUtil.toBytes(1);
  assertThat(bytes).hasSize(4).containsSequence((byte) 0, (byte) 0, (byte) 0, (byte) 1);
  bytes = NumberUtil.toBytes(257);
  assertThat(bytes).containsSequence((byte) 0, (byte) 0, (byte) 1, (byte) 1);
  assertThat(NumberUtil.toInt(bytes)).isEqualTo(257);
  // long
  byte[] bytes2 = NumberUtil.toBytes(1L);
  assertThat(bytes2).hasSize(8);
  bytes2 = NumberUtil.toBytes(257L);
  assertThat(bytes2).containsSequence((byte) 0, (byte) 0, (byte) 1, (byte) 1);
  assertThat(NumberUtil.toLong(bytes2)).isEqualTo(257L);
  // dobule
  byte[] bytes3 = NumberUtil.toBytes(1.123d);
  assertThat(NumberUtil.toDouble(bytes3)).isEqualTo(1.123d);
  // toInt32
  assertThat(NumberUtil.toInt32(123l)).isEqualTo(123);
  try {
    NumberUtil.toInt32(Long.valueOf(Integer.MAX_VALUE + 1l));
    fail("should fail here");
  } catch (Exception e) {
    assertThat(e).isInstanceOf(IllegalArgumentException.class);
  }
}

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

@Test
public void testServiceWithoutKeySelector() {
  final KafkaStructuredLoggingServiceExposed service =
      new KafkaStructuredLoggingServiceExposed(producer, null, false);
  final SimpleStructuredLog log = new SimpleStructuredLog("kawamuray");
  service.writeLog(null, log);
  verify(producer, times(1)).send(captor.capture(), any(Callback.class));
  final ProducerRecord<byte[], SimpleStructuredLog> record = captor.getValue();
  assertThat(record.key()).isNull();
  assertThat(record.value()).isEqualTo(log);
}

代码示例来源:origin: SonarSource/sonarqube

@Override
 public void consume(int lineIdx, @Nullable byte[] hash) {
  switch (lineIdx) {
   case 1:
    assertThat(hash).isNull();
    break;
   default:
    fail("Invalid line");
  }
 }
});

代码示例来源:origin: segmentio/analytics-android

@Test
public void testClearDoesNotCorrupt() throws IOException {
 QueueFile queue = new QueueFile(file);
 byte[] stuff = values[253];
 queue.add(stuff);
 queue.clear();
 queue = new QueueFile(file);
 assertThat(queue.isEmpty()).isTrue();
 assertThat(queue.peek()).isNull();
 queue.add(values[25]);
 assertThat(queue.peek()).isEqualTo(values[25]);
}

相关文章