package com.bonus.common.core.utils;

import org.junit.Test;

import static org.junit.Assert.*;

public class StringUtilsTest {

    @Test
    public void testIsEmpty() {
        assertTrue(StringUtils.isEmpty(""));
        assertFalse(StringUtils.isEmpty("abc"));
    }

    @Test
    public void testIsNotEmpty() {
        assertFalse(StringUtils.isNotEmpty(""));
        assertTrue(StringUtils.isNotEmpty("abc"));
    }

    @Test
    public void testIsBlank() {
        assertTrue(StringUtils.isBlank(null));
        assertTrue(StringUtils.isBlank(""));
        assertTrue(StringUtils.isBlank("  "));
        assertFalse(StringUtils.isBlank("abc"));
    }

    @Test
    public void testIsNotBlank() {
        assertFalse(StringUtils.isNotBlank(null));
        assertFalse(StringUtils.isNotBlank(""));
        assertFalse(StringUtils.isNotBlank("  "));
        assertTrue(StringUtils.isNotBlank("abc"));
    }

    @Test
    public void testTrim() {
        assertEquals("abc", StringUtils.trim("  abc  "));
    }

    @Test
    public void testToUpperCase() {
        assertNull(StringUtils.toUpperCase(null));
        assertEquals("ABC", StringUtils.toUpperCase("abc"));
    }

    @Test
    public void testToLowerCase() {
        assertNull(StringUtils.toLowerCase(null));
        assertEquals("abc", StringUtils.toLowerCase("ABC"));
    }

    @Test
    public void testIsNumeric() {
        assertFalse(StringUtils.isNumeric(null));
        assertFalse(StringUtils.isNumeric("abc"));
        assertTrue(StringUtils.isNumeric("123"));
    }

    @Test
    public void testIsAlphabetic() {
        assertFalse(StringUtils.isAlphabetic(null));
        assertFalse(StringUtils.isAlphabetic("123"));
        assertTrue(StringUtils.isAlphabetic("abc"));
    }

    @Test
    public void testIsAlphanumeric() {
        assertFalse(StringUtils.isAlphanumeric(null));
        assertFalse(StringUtils.isAlphanumeric("abc!"));
        assertTrue(StringUtils.isAlphanumeric("abc123"));
    }

    @Test
    public void testContains() {
        assertFalse(StringUtils.contains(null, "abc"));
        assertFalse(StringUtils.contains("abc", null));
        assertTrue(StringUtils.contains("abc", "a"));
    }

    @Test
    public void testReverse() {
        assertNull(StringUtils.reverse(null));
        assertEquals("cba", StringUtils.reverse("abc"));
    }

    @Test
    public void testReplace() {
        assertNull(StringUtils.replace(null, "a", "b"));
        assertEquals("bbc", StringUtils.replace("abc", "a", "b"));
    }

    @Test
    public void testRemoveWhitespace() {
        assertNull(StringUtils.removeWhitespace(null));
        assertEquals("abc", StringUtils.removeWhitespace(" a b c "));
    }

    @Test
    public void testSplit() {
        assertArrayEquals(new String[0], StringUtils.split(null, ","));
        assertArrayEquals(new String[]{"a", "b", "c"}, StringUtils.split("a,b,c", ","));
        assertArrayEquals(new String[]{"a", "b", "c"}, StringUtils.split("a.b.c", "\\."));
    }

    @Test
    public void testJoin() {
        assertEquals("a,b,c", StringUtils.join(new String[]{"a", "b", "c"}, ","));
    }

    @Test
    public void testCapitalize() {
        assertNull(StringUtils.capitalize(null));
        assertEquals("Abc", StringUtils.capitalize("abc"));
    }

    @Test
    public void testUncapitalize() {
        assertNull(StringUtils.uncapitalize(null));
        assertEquals("abc", StringUtils.uncapitalize("Abc"));
    }

    @Test
    public void testEncodeBase64() {
        assertNull(StringUtils.encodeBase64(null));
        assertEquals("YWJj", StringUtils.encodeBase64("abc"));
    }

    @Test
    public void testDecodeBase64() {
        assertNull(StringUtils.decodeBase64(null));
        assertEquals("abc", StringUtils.decodeBase64("YWJj"));
    }

    @Test
    public void testEndsWith() {
        assertFalse(StringUtils.endsWith(null, "c"));
        assertFalse(StringUtils.endsWith("abc", null));
        assertTrue(StringUtils.endsWith("abc", "c"));
    }

    @Test
    public void testStartsWith() {
        assertFalse(StringUtils.startsWith(null, "a"));
        assertFalse(StringUtils.startsWith("abc", null));
        assertTrue(StringUtils.startsWith("abc", "a"));
    }

    @Test
    public void testRemovePrefix() {
        assertNull(StringUtils.removePrefix(null, "a"));
        assertEquals("bc", StringUtils.removePrefix("abc", "a"));
    }

    @Test
    public void testRemoveSuffix() {
        assertNull(StringUtils.removeSuffix(null, "c"));
        assertEquals("ab", StringUtils.removeSuffix("abc", "c"));
    }

    @Test
    public void testEscapeHtml() {
        assertNull(StringUtils.escapeHtml(null));
        assertEquals("&lt;div&gt;", StringUtils.escapeHtml("<div>"));
    }

    @Test
    public void testRandomUUID() {
        assertNotNull(StringUtils.randomUUID());
        assertEquals(32, StringUtils.randomUUID().length());
    }
}
