BAEL-3928 Comparing Long values in Java

This commit is contained in:
Antonio Moreno 2020-03-24 23:43:49 +00:00
parent 060557608c
commit 2ba09756f7
1 changed files with 53 additions and 0 deletions

View File

@ -0,0 +1,53 @@
package com.baeldung.comparelong;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Test;
public class CompareLongUnitTest {
@Test
public void givenLongValuesLessThan128_whenUsingReferenceComparater_thenSuccess() {
Long l1 = 127L;
Long l2 = 127L;
assertThat(l1 == l2).isTrue();
}
@Test
public void givenLongValuesGreaterOrEqualsThan128_whenUsingReferenceComparater_thenFails() {
Long l1 = 128L;
Long l2 = 128L;
assertThat(l1 == l2).isFalse();
}
@Test
public void givenLongValuesGreaterOrEqualsThan128_whenUsingEquals_thenSuccess() {
Long l1 = 128L;
Long l2 = 128L;
assertThat(l1.equals(l2)).isTrue();
}
@Test
public void givenLongValuesGreaterOrEqualsThan128_whenUsingComparisonOperator_andLongValue_thenSuccess() {
Long l1 = 128L;
Long l2 = 128L;
assertThat(l1.longValue() == l2.longValue()).isTrue();
}
@Test
public void givenLongValuesGreaterOrEqualsThan128_whenUsingCasting_thenSuccess() {
Long l1 = 128L;
Long l2 = 128L;
assertThat((long) l1 == (long) l2).isTrue();
}
}