From 396647676f72a5fc7f6c15666332dd9518d72d62 Mon Sep 17 00:00:00 2001 From: Eric Hettiaratchi <35978114+Braavos96@users.noreply.github.com> Date: Wed, 17 Apr 2019 11:10:25 +0100 Subject: [PATCH] Add unit tests for me.zhengjie.utils.StringUtils These tests were written using Diffblue Cover. --- .../me/zhengjie/utils/StringUtilsTest.java | 49 +++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 eladmin-common/src/test/java/me/zhengjie/utils/StringUtilsTest.java diff --git a/eladmin-common/src/test/java/me/zhengjie/utils/StringUtilsTest.java b/eladmin-common/src/test/java/me/zhengjie/utils/StringUtilsTest.java new file mode 100644 index 00000000..4edb4c62 --- /dev/null +++ b/eladmin-common/src/test/java/me/zhengjie/utils/StringUtilsTest.java @@ -0,0 +1,49 @@ +package me.zhengjie.utils; + +import org.junit.Test; +import org.springframework.mock.web.MockHttpServletRequest; + +import java.text.SimpleDateFormat; +import java.util.*; + +import static me.zhengjie.utils.StringUtils.*; +import static org.junit.Assert.*; + +public class StringUtilsTest { + + @Test + public void testInString() { + assertTrue(inString("?", "?")); + assertFalse(inString("?", new String[]{})); + } + + @Test + public void testToCamelCase() { + assertNull(toCamelCase(null)); + } + + @Test + public void testToCapitalizeCamelCase() { + assertNull(StringUtils.toCapitalizeCamelCase(null)); + assertEquals("HelloWorld", toCapitalizeCamelCase("hello_world")); + } + + @Test + public void testToUnderScoreCase() { + assertNull(StringUtils.toUnderScoreCase(null)); + assertEquals("hello_world", toUnderScoreCase("helloWorld")); + assertEquals("\u0000\u0000", toUnderScoreCase("\u0000\u0000")); + assertEquals("\u0000_a", toUnderScoreCase("\u0000A")); + } + + @Test + public void testGetWeekDay() { + SimpleDateFormat simpleDateformat = new SimpleDateFormat("E"); + assertEquals(simpleDateformat.format(new Date()), getWeekDay()); + } + + @Test + public void testGetIP() { + assertEquals("127.0.0.1", getIP(new MockHttpServletRequest())); + } +}