public void testFromStringFailsWithOddLengthInput() { try { HashCode.fromString("7f8"); fail(); } catch (IllegalArgumentException expected) { } }
public void testWriteBytesToUndersizedArray() { byte[] dest = new byte[3]; try { HASH_ABCD.writeBytesTo(dest, 0, 4); fail(); } catch (IndexOutOfBoundsException expected) { } }
public void testFromStringFailsWithInvalidHexChar() { try { HashCode.fromString("7f8005ff0z"); fail(); } catch (IllegalArgumentException expected) { } }
public void testWriteBytesToUndersizedArrayLongMaxLength() { byte[] dest = new byte[3]; try { HASH_ABCD.writeBytesTo(dest, 0, 5); fail(); } catch (IndexOutOfBoundsException expected) { } }
public void testFromStringFailsWithUpperCaseString() { String string = Hashing.sha1().hashString("foo", Charsets.US_ASCII).toString().toUpperCase(); try { HashCode.fromString(string); fail(); } catch (IllegalArgumentException expected) { } }
private static void assertExpectedHashCode(ExpectedHashCode expectedHashCode, HashCode hash) { assertTrue(Arrays.equals(expectedHashCode.bytes, hash.asBytes())); byte[] bb = new byte[hash.bits() / 8]; hash.writeBytesTo(bb, 0, bb.length); assertTrue(Arrays.equals(expectedHashCode.bytes, bb)); assertEquals(expectedHashCode.asInt, hash.asInt()); if (expectedHashCode.asLong == null) { try { hash.asLong(); fail(); } catch (IllegalStateException expected) { } } else { assertEquals(expectedHashCode.asLong.longValue(), hash.asLong()); } assertEquals(expectedHashCode.toString, hash.toString()); assertSideEffectFree(hash); assertReadableBytes(hash); }
public void testWriteBytesToUndersizedArray() { byte[] dest = new byte[3]; try { HASH_ABCD.writeBytesTo(dest, 0, 4); fail(); } catch (IndexOutOfBoundsException expected) { } }
public void testWriteBytesToUndersizedArrayLongMaxLength() { byte[] dest = new byte[3]; try { HASH_ABCD.writeBytesTo(dest, 0, 5); fail(); } catch (IndexOutOfBoundsException expected) { } }
public void testFromStringFailsWithInvalidHexChar() { try { HashCode.fromString("7f8005ff0z"); fail(); } catch (IllegalArgumentException expected) { } }
public void testFromStringFailsWithOddLengthInput() { try { HashCode.fromString("7f8"); fail(); } catch (IllegalArgumentException expected) { } }
public void testFromStringFailsWithUpperCaseString() { String string = Hashing.sha1().hashString("foo", Charsets.US_ASCII).toString().toUpperCase(); try { HashCode.fromString(string); fail(); } catch (IllegalArgumentException expected) { } }
private static void assertExpectedHashCode(ExpectedHashCode expectedHashCode, HashCode hash) { assertTrue(Arrays.equals(expectedHashCode.bytes, hash.asBytes())); byte[] bb = new byte[hash.bits() / 8]; hash.writeBytesTo(bb, 0, bb.length); assertTrue(Arrays.equals(expectedHashCode.bytes, bb)); assertEquals(expectedHashCode.asInt, hash.asInt()); if (expectedHashCode.asLong == null) { try { hash.asLong(); fail(); } catch (IllegalStateException expected) {} } else { assertEquals(expectedHashCode.asLong.longValue(), hash.asLong()); } assertEquals(expectedHashCode.toString, hash.toString()); assertSideEffectFree(hash); assertReadableBytes(hash); }