BAEL-3978: Add code samples for Objects.equals() (#9033)
This commit is contained in:
parent
95a4beda32
commit
8c5dfc6f17
|
@ -1,8 +1,12 @@
|
||||||
package com.baeldung.comparelong;
|
package com.baeldung.comparelong;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.assertj.core.api.Assertions.assertThatCode;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
public class CompareLongUnitTest {
|
public class CompareLongUnitTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -32,6 +36,33 @@ public class CompareLongUnitTest {
|
||||||
assertThat(l1.equals(l2)).isTrue();
|
assertThat(l1.equals(l2)).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenLongValuesLessThan128_whenUsingObjectsEquals_thenSuccess() {
|
||||||
|
|
||||||
|
Long l1 = 127L;
|
||||||
|
Long l2 = 127L;
|
||||||
|
|
||||||
|
assertThat(Objects.equals(l1, l2)).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenLongValuesGreaterOrEqualsThan128_whenUsingObjectsEquals_thenSuccess() {
|
||||||
|
|
||||||
|
Long l1 = 128L;
|
||||||
|
Long l2 = 128L;
|
||||||
|
|
||||||
|
assertThat(Objects.equals(l1, l2)).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenNullReference_whenUsingObjectsEquals_thenNoException() {
|
||||||
|
|
||||||
|
Long l1 = null;
|
||||||
|
Long l2 = 128L;
|
||||||
|
|
||||||
|
assertThatCode(() -> Objects.equals(l1, l2)).doesNotThrowAnyException();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenLongValuesGreaterOrEqualsThan128_whenUsingComparisonOperator_andLongValue_thenSuccess() {
|
public void givenLongValuesGreaterOrEqualsThan128_whenUsingComparisonOperator_andLongValue_thenSuccess() {
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue