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

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

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

AbstractByteArrayAssert.containsSequence介绍

[英]Verifies that the actual array contains the given sequence, without any other values between them.

Example:

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

[中]验证实际数组是否包含给定的序列,它们之间是否没有任何其他值。
例子:

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

代码示例

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

@Test
public void hexEncode() {
  String input = "haha,i am a very long message";
  String result = EncodeUtil.encodeHex(input.getBytes());
  assertThat(new String(EncodeUtil.decodeHex(result), Charsets.UTF_8)).isEqualTo(input);
  byte[] bytes = new byte[] { 1, 2, 15, 17 };
  result = EncodeUtil.encodeHex(bytes);
  assertThat(result).isEqualTo("01020F11");
  input = "01020F11";
  assertThat(EncodeUtil.decodeHex(input)).hasSize(4).containsSequence((byte) 1, (byte) 2, (byte) 15, (byte) 17);
  try {
    input = "01020G11";
    EncodeUtil.decodeHex(input);
    fail("should throw exception before");
  } catch (Throwable t) {
    assertThat(t).isInstanceOf(IllegalArgumentException.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: com.datastax.dse/dse-java-driver-core

static Object serializeAndDeserialize(Geometry geometry)
   throws IOException, ClassNotFoundException {
  ByteArrayOutputStream baos = new ByteArrayOutputStream();
  ObjectOutputStream out = new ObjectOutputStream(baos);

  out.writeObject(geometry);

  byte[] bytes = baos.toByteArray();

  if (!(geometry instanceof Distance)) {
   byte[] wkb = Bytes.getArray(geometry.asWellKnownBinary());
   assertThat(bytes).containsSequence(wkb);
  }

  ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(bytes));
  return in.readObject();
 }
}

相关文章