Skip to content

Commit 28c39d2

Browse files
authored
Merge pull request #15692 from hangga/securerandom-positive-long
BAEL-7491 - Generating Unique Positive Long using SecureRandom in Java
2 parents bb998a3 + 8a136fb commit 28c39d2

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.baeldung.securerandompositivelong;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import java.security.SecureRandom;
6+
7+
import static org.assertj.core.api.Assertions.assertThat;
8+
9+
public class SecureRandomPositiveLongUnitTest {
10+
11+
@Test
12+
void whenGenerateRandomPositiveLong_thenGetPositiveValue() {
13+
SecureRandom secureRandom = new SecureRandom();
14+
long randomPositiveLong = Math.abs(secureRandom.nextLong());
15+
16+
assertThat(randomPositiveLong).isNotNegative();
17+
}
18+
}

0 commit comments

Comments
 (0)