package core.framework.util;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

/**
 * @author neo
 */
class StringsTest {
    @Test
    void stringEquals() {
        assertTrue(Strings.equals(null, null));
        assertFalse(Strings.equals(null, ""));
        assertFalse(Strings.equals("", null));
        assertTrue(Strings.equals("", ""));
    }

    @Test
    void compare() {
        assertEquals(-1, Strings.compare(null, ""));
        assertEquals(1, Strings.compare("b", "a"));
        assertEquals(0, Strings.compare(null, null));
    }

    @Test
    void truncate() {
        assertNull(Strings.truncate(null, 10));
        assertEquals("value", Strings.truncate("value", 10));
        assertEquals("1234567890", Strings.truncate("123456789012345", 10));
    }

    @Test
    void isEmpty() {
        assertTrue(Strings.isEmpty(""));
        assertTrue(Strings.isEmpty(" "));

        assertFalse(Strings.isEmpty("1"));
        assertFalse(Strings.isEmpty(" 1"));
    }

    @Test
    void split() {
        assertArrayEquals(new String[]{""}, Strings.split("", '/'));
        assertArrayEquals(new String[]{"", ""}, Strings.split("/", '/'));
        assertArrayEquals(new String[]{"", "", ""}, Strings.split("//", '/'));
        assertArrayEquals(new String[]{"", "1"}, Strings.split("/1", '/'));
        assertArrayEquals(new String[]{"", "1", ""}, Strings.split("/1/", '/'));
        assertArrayEquals(new String[]{"1", ""}, Strings.split("1/", '/'));
        assertArrayEquals(new String[]{"1", "2"}, Strings.split("1/2", '/'));
        assertArrayEquals(new String[]{"1", "2", "", "3"}, Strings.split("1/2//3", '/'));
        assertArrayEquals(new String[]{"1", "2", "3"}, Strings.split("1/2/3", '/'));
    }
}

@@ -59,16 +59,74 @@
 .Test;%0A%0A
+import static org.assertj.core.api.Assertions.assertThat;%0A
 import s
@@ -509,35 +509,35 @@
 %0A        assertT
-rue
+hat
 (Strings.equals(
@@ -540,32 +540,41 @@
 als(null, null))
+.isTrue()
 ;%0A        assert
@@ -565,37 +565,36 @@
 ;%0A        assert
-False
+That
 (Strings.equals(
@@ -595,32 +595,42 @@
 quals(null, %22%22))
+.isFalse()
 ;%0A        assert
@@ -621,37 +621,36 @@
 ;%0A        assert
-False
+That
 (Strings.equals(
@@ -655,24 +655,34 @@
 s(%22%22, null))
+.isFalse()
 ;%0A        as
@@ -678,35 +678,35 @@
 %0A        assertT
-rue
+hat
 (Strings.equals(
@@ -709,24 +709,33 @@
 als(%22%22, %22%22))
+.isTrue()
 ;%0A    %7D%0A%0A   
@@ -780,19 +780,13 @@
 sert
-Equals(-1, 
+That(
 Stri
@@ -803,24 +803,38 @@
 e(null, %22%22))
+.isEqualTo(-1)
 ;%0A        as
@@ -841,18 +841,13 @@
 sert
-Equals(1, 
+That(
 Stri
@@ -868,16 +868,29 @@
 %22, %22a%22))
+.isEqualTo(1)
 ;%0A      
@@ -901,18 +901,13 @@
 sert
-Equals(0, 
+That(
 Stri
@@ -930,16 +930,25 @@
 , null))
+.isZero()
 ;%0A    %7D%0A

update test to workaround pmd false positive check