New and updated hashcode tests
This commit is contained in:
parent
24a233db5c
commit
684cdc06ae
2 changed files with 23 additions and 2 deletions
|
@ -51,8 +51,13 @@ public class MaybeTest implements WithAssertions {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testHashCode() {
|
||||
assertThat(just(1).hashCode()).isEqualTo(Objects.hashCode(1));
|
||||
public void justHashCode() {
|
||||
assertThat(just(1).hashCode()).isNotEqualTo(just(2).hashCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nothingHashCode() {
|
||||
assertThat(nothing().hashCode()).isEqualTo(maybe(null).hashCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -18,6 +18,22 @@ public class ResultTest implements WithAssertions {
|
|||
assertThat(Result.ok(1).equals("1")).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void successHashCode() {
|
||||
assertThat(Result.ok(1).hashCode()).isNotEqualTo(Result.ok(2).hashCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void errorHashCode() {
|
||||
// despite having 'equivalent' exceptions, the exceptions are distinct instances, so should be considered unique
|
||||
final RuntimeException exception1 = new RuntimeException("message");
|
||||
final RuntimeException exception2 = new RuntimeException("message");
|
||||
assertThat(exception1.hashCode()).isNotEqualTo(exception2.hashCode());
|
||||
final Result<Object> error1 = Result.error(exception1);
|
||||
final Result<Object> error2 = Result.error(exception2);
|
||||
assertThat(error1.hashCode()).isNotEqualTo(error2.hashCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void createSuccess_isSuccess() {
|
||||
//when
|
||||
|
|
Loading…
Reference in a new issue