Merge pull request #15692 from hangga/securerandom-positive-long

BAEL-7491 - Generating Unique Positive Long using SecureRandom in Java
This commit is contained in:
Liam Williams 2024-02-06 10:52:46 +00:00 committed by GitHub
commit 28c39d25a0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 18 additions and 0 deletions

View File

@ -0,0 +1,18 @@
package com.baeldung.securerandompositivelong;
import org.junit.jupiter.api.Test;
import java.security.SecureRandom;
import static org.assertj.core.api.Assertions.assertThat;
public class SecureRandomPositiveLongUnitTest {
@Test
void whenGenerateRandomPositiveLong_thenGetPositiveValue() {
SecureRandom secureRandom = new SecureRandom();
long randomPositiveLong = Math.abs(secureRandom.nextLong());
assertThat(randomPositiveLong).isNotNegative();
}
}