package org.apereo.cas.util;

import lombok.val;
import org.apache.commons.lang3.StringUtils;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.*;

/**
 * This is {@link RandomUtilsTests}.
 *
 * @author Misagh Moayyed
 * @since 6.0.0
 */
@Tag("Utility")
public class RandomUtilsTests {

    @BeforeEach
    public void beforeEach() {
        System.setProperty(RandomUtils.SYSTEM_PROPERTY_SECURE_RANDOM_ALG, StringUtils.EMPTY);
    }
    
    @Test
    public void verifyUnknownAlg() {
        System.setProperty(RandomUtils.SYSTEM_PROPERTY_SECURE_RANDOM_ALG, "bad-algorithm");
        assertNotNull(RandomUtils.getNativeInstance());
    }

    @Test
    public void verifyOperation() {
        val value = RandomUtils.generateSecureRandomId();
        assertNotNull(value);
    }

    @Test
    public void verifyAlphaNumeric() {
        val value = RandomUtils.randomAlphanumeric(4, 8);
        assertNotNull(value);
    }

    @Test
    public void verifyRandomAlphabetic() {
        val value = RandomUtils.randomAlphabetic(4, 8);
        assertNotNull(value);
    }

    @Test
    public void verifyInt() {
        var value = RandomUtils.nextInt();
        assertNotNull(value);

        value = RandomUtils.nextInt(5, 5);
        assertNotNull(value);
    }

    @Test
    public void verifyLong() {
        var value = RandomUtils.nextLong(3, 3);
        assertEquals(3, value);
    }

    @Test
    public void verifyDouble() {
        var value = RandomUtils.nextDouble();
        assertNotNull(value);

        value = RandomUtils.nextDouble(5, 5);
        assertNotNull(value);
    }

    @Test
    public void verifyValidation() {
        assertThrows(IllegalArgumentException.class, () -> RandomUtils.nextDouble(10, 1));
        assertThrows(IllegalArgumentException.class, () ->RandomUtils.nextDouble(-1, -1));

        assertThrows(IllegalArgumentException.class, () ->RandomUtils.nextInt(10, 1));
        assertThrows(IllegalArgumentException.class, () ->RandomUtils.nextInt(-1, -1));

        assertThrows(IllegalArgumentException.class, () ->RandomUtils.nextLong(10, 1));
        assertThrows(IllegalArgumentException.class, () ->RandomUtils.nextLong(-1, -1));
    }
}

@@ -535,20 +535,16 @@
 ;%0A    %7D%0A
-    
 %0A    @Te
@@ -1882,32 +1882,33 @@
 ion.class, () -%3E
+ 
 RandomUtils.next
@@ -1975,32 +1975,33 @@
 ion.class, () -%3E
+ 
 RandomUtils.next
@@ -2063,32 +2063,33 @@
 ion.class, () -%3E
+ 
 RandomUtils.next
@@ -2153,32 +2153,33 @@
 ion.class, () -%3E
+ 
 RandomUtils.next
@@ -2250,16 +2250,17 @@
 s, () -%3E
+ 
 RandomUt

fix checkstyle