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

x33g5p2x  于10个月前 转载在 其他  
字(7.5k)|赞(0)|评价(0)|浏览(36)

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

AbstractByteArrayAssert.hasSize介绍

[英]Example:

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

[中]例子:

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

代码示例

代码示例来源: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 utf8EncodesAndDecodesCorrectly() throws Exception {
    byte[] bytes = Utf8.encode("6048b75ed560785c");
    assertThat(bytes).hasSize(16);
    assertThat(Arrays.equals("6048b75ed560785c".getBytes("UTF-8"), bytes)).isTrue();

    String decoded = Utf8.decode(bytes);

    assertThat(decoded).isEqualTo("6048b75ed560785c");
  }
}

代码示例来源: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: spring-projects/spring-security

@Test
public void generateKeyWhenDefaultConstructorThen32Bytes() {
  String result = new Base64StringKeyGenerator().generateKey();
  assertThat(Base64.getDecoder().decode(result.getBytes())).hasSize(32);
}

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

@Test
public void generateKeyWhenCustomKeySizeThen32Bytes() {
  int size = 40;
  String result = new Base64StringKeyGenerator(size).generateKey();
  assertThat(Base64.getDecoder().decode(result.getBytes())).hasSize(size);
}

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

@Test
public void mac() {
  String input = "foo message";
  // key可为任意字符串
  // byte[] key = "a foo key".getBytes();
  byte[] key = CryptoUtil.generateHmacSha1Key();
  assertThat(key).hasSize(20);
  byte[] macResult = CryptoUtil.hmacSha1(input.getBytes(), key);
  System.out.println("hmac-sha1 key in hex      :" + EncodeUtil.encodeHex(key));
  System.out.println("hmac-sha1 in hex result   :" + EncodeUtil.encodeHex(macResult));
  assertThat(CryptoUtil.isMacValid(macResult, input.getBytes(), key)).isTrue();
}

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

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

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

@Test
public void aes() {
  byte[] key = CryptoUtil.generateAesKey();
  assertThat(key).hasSize(16);
  String input = "foo message";
  byte[] encryptResult = CryptoUtil.aesEncrypt(input.getBytes(), key);
  String descryptResult = CryptoUtil.aesDecrypt(encryptResult, key);
  System.out.println("aes key in hex            :" + EncodeUtil.encodeHex(key));
  System.out.println("aes encrypt in hex result :" + EncodeUtil.encodeHex(encryptResult));
  assertThat(descryptResult).isEqualTo(input);
}

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

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

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

@Test
public void secureRandomCustomLength() {
  BytesKeyGenerator keyGenerator = KeyGenerators.secureRandom(21);
  assertThat(keyGenerator.getKeyLength()).isEqualTo(21);
  byte[] key = keyGenerator.generateKey();
  assertThat(key).hasSize(21);
  byte[] key2 = keyGenerator.generateKey();
  assertThat(Arrays.equals(key, key2)).isFalse();
}

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

@Test
  public void aesWithIV() {
    byte[] key = CryptoUtil.generateAesKey();
    byte[] iv = CryptoUtil.generateIV();
    assertThat(key).hasSize(16);
    assertThat(iv).hasSize(16);
    String input = "foo message";

    byte[] encryptResult = CryptoUtil.aesEncrypt(input.getBytes(), key, iv);
    String descryptResult = CryptoUtil.aesDecrypt(encryptResult, key, iv);

    System.out.println("aes key in hex            :" + EncodeUtil.encodeHex(key));
    System.out.println("iv in hex                 :" + EncodeUtil.encodeHex(iv));
    System.out.println("aes encrypt in hex result :" + EncodeUtil.encodeHex(encryptResult));
    assertThat(descryptResult).isEqualTo(input);
  }
}

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

@Test
public void secureRandom() {
  BytesKeyGenerator keyGenerator = KeyGenerators.secureRandom();
  assertThat(keyGenerator.getKeyLength()).isEqualTo(8);
  byte[] key = keyGenerator.generateKey();
  assertThat(key).hasSize(8);
  byte[] key2 = keyGenerator.generateKey();
  assertThat(Arrays.equals(key, key2)).isFalse();
}

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

@Test
public void shared() throws Exception {
  BytesKeyGenerator keyGenerator = KeyGenerators.shared(21);
  assertThat(keyGenerator.getKeyLength()).isEqualTo(21);
  byte[] key = keyGenerator.generateKey();
  assertThat(key).hasSize(21);
  byte[] key2 = keyGenerator.generateKey();
  assertThat(Arrays.equals(key, key2)).isTrue();
}

代码示例来源:origin: gocd/gocd

@Test
  public void shouldGenerateA16ByteIV() throws NoSuchAlgorithmException {
    ProductionIVProvider ivProvider = new ProductionIVProvider();

    byte[] iv = ivProvider.createIV();
    assertThat(iv).hasSize(16);
  }
}

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

@Test
  public void generateKeyWhenBase64AndCustomKeySizeThen32Bytes() {
    int size = 40;
    String result = new Base64StringKeyGenerator(Base64.getUrlEncoder(), size).generateKey();
    assertThat(Base64.getUrlDecoder().decode(result.getBytes())).hasSize(size);
  }
}

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

@Test public void serialize() {
 assertThat(ByteString.of(adapter.encode(THREE))).isEqualTo(BYTES);
 assertThat(adapter.encode(EMPTY)).hasSize(0);
}

代码示例来源: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: spring-projects/spring-security

@Test
public void decodingStopsWithFirstInvalidCharacter() {
  assertThat(BCrypt.decode_base64("....", 1)).hasSize(1);
  assertThat(BCrypt.decode_base64(" ....", 1)).isEmpty();
}

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

@Test
public void generateKeyWhenBase64Then32Bytes() {
  String result = new Base64StringKeyGenerator(Base64.getUrlEncoder()).generateKey();
  assertThat(Base64.getUrlDecoder().decode(result.getBytes())).hasSize(32);
}

相关文章