From aec68abc8abbda15dcca499f986f8892bc6cca53 Mon Sep 17 00:00:00 2001 From: zjz1993 <1429595365@qq.com> Date: Wed, 21 Aug 2019 16:11:24 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E5=AF=B9stringkit=E8=BF=9B=E8=A1=8C?= =?UTF-8?q?=E6=96=B9=E6=B3=95=E7=9A=84=E8=A1=A5=E5=85=85=EF=BC=8C=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E7=9B=B8=E5=BA=94=E7=9A=84=E5=8D=95=E6=B5=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/fanruan/api/util/StringKit.java | 9 +++++++++ src/test/java/com/fanruan/api/util/StringKitTest.java | 10 ++++++++++ 2 files changed, 19 insertions(+) diff --git a/src/main/java/com/fanruan/api/util/StringKit.java b/src/main/java/com/fanruan/api/util/StringKit.java index f3e47df..e79d263 100644 --- a/src/main/java/com/fanruan/api/util/StringKit.java +++ b/src/main/java/com/fanruan/api/util/StringKit.java @@ -85,5 +85,14 @@ public class StringKit { public static boolean isNotBlank(String text) { return StringUtils.isNotBlank(text); } + /** + * 对字符串做trim操作 + * + * @param string 源字符串 + * @return 返回操作后的字符串 + */ + public static String trim(String string) { + return StringUtils.trim(string); + } } diff --git a/src/test/java/com/fanruan/api/util/StringKitTest.java b/src/test/java/com/fanruan/api/util/StringKitTest.java index be66448..3e07b43 100644 --- a/src/test/java/com/fanruan/api/util/StringKitTest.java +++ b/src/test/java/com/fanruan/api/util/StringKitTest.java @@ -1,5 +1,6 @@ package com.fanruan.api.util; +import org.junit.Assert; import org.junit.Test; import static org.junit.Assert.*; @@ -26,4 +27,13 @@ public class StringKitTest { @Test public void isNotBlank() { } + @Test + public void trim(){ + String stringHaveBlank = " abc "; + String stringWithoutBlank = "abc"; + String blankString = " "; + Assert.assertEquals(StringKit.trim(stringHaveBlank), "abc"); + Assert.assertEquals(StringKit.trim(stringWithoutBlank), "abc"); + Assert.assertEquals(StringKit.trim(blankString), ""); + } } \ No newline at end of file