StringUtilsTest.java 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package me.zhengjie.utils;
  2. import org.junit.jupiter.api.Test;
  3. import org.springframework.mock.web.MockHttpServletRequest;
  4. import java.text.SimpleDateFormat;
  5. import java.util.Date;
  6. import static me.zhengjie.utils.StringUtils.getIp;
  7. import static me.zhengjie.utils.StringUtils.getWeekDay;
  8. import static me.zhengjie.utils.StringUtils.toCamelCase;
  9. import static me.zhengjie.utils.StringUtils.toCapitalizeCamelCase;
  10. import static me.zhengjie.utils.StringUtils.toUnderScoreCase;
  11. import static org.junit.jupiter.api.Assertions.assertEquals;
  12. import static org.junit.jupiter.api.Assertions.assertNull;
  13. public class StringUtilsTest {
  14. @Test
  15. public void testToCamelCase() {
  16. assertNull(toCamelCase(null));
  17. }
  18. @Test
  19. public void testToCapitalizeCamelCase() {
  20. assertNull(StringUtils.toCapitalizeCamelCase(null));
  21. assertEquals("HelloWorld", toCapitalizeCamelCase("hello_world"));
  22. }
  23. @Test
  24. public void testToUnderScoreCase() {
  25. assertNull(StringUtils.toUnderScoreCase(null));
  26. assertEquals("hello_world", toUnderScoreCase("helloWorld"));
  27. assertEquals("\u0000\u0000", toUnderScoreCase("\u0000\u0000"));
  28. assertEquals("\u0000_a", toUnderScoreCase("\u0000A"));
  29. }
  30. @Test
  31. public void testGetWeekDay() {
  32. SimpleDateFormat simpleDateformat = new SimpleDateFormat("E");
  33. assertEquals(simpleDateformat.format(new Date()), getWeekDay());
  34. }
  35. @Test
  36. public void testGetIP() {
  37. assertEquals("127.0.0.1", getIp(new MockHttpServletRequest()));
  38. }
  39. }