Fix handling of cyrillic characters in AsciiBytes hashCode method

Closes gh-7202
This commit is contained in:
Andy Wilkinson
2016-10-24 11:44:01 +01:00
parent 713fd51f9c
commit be597d7ce9
2 changed files with 45 additions and 19 deletions

View File

@@ -26,6 +26,7 @@ import static org.assertj.core.api.Assertions.assertThat;
* Tests for {@link AsciiBytes}.
*
* @author Phillip Webb
* @author Andy Wilkinson
*/
public class AsciiBytesTests {
@@ -140,16 +141,26 @@ public class AsciiBytesTests {
@Test
public void hashCodeSameAsString() throws Exception {
String s = "abcABC123xyz!";
AsciiBytes a = new AsciiBytes(s);
assertThat(s.hashCode()).isEqualTo(a.hashCode());
hashCodeSameAsString("abcABC123xyz!");
}
@Test
public void hashCodeSameAsStringWithSpecial() throws Exception {
String s = "special/\u00EB.dat";
AsciiBytes a = new AsciiBytes(s);
assertThat(s.hashCode()).isEqualTo(a.hashCode());
hashCodeSameAsString("special/\u00EB.dat");
}
@Test
public void hashCodeSameAsStringWithCyrillicCharacters() throws Exception {
hashCodeSameAsString("\u0432\u0435\u0441\u043D\u0430");
}
@Test
public void hashCodeSameAsStringWithEmoji() throws Exception {
hashCodeSameAsString("\ud83d\udca9");
}
private void hashCodeSameAsString(String input) {
assertThat(new AsciiBytes(input).hashCode()).isEqualTo(input.hashCode());
}
}