This is an automated email from the ASF dual-hosted git repository.

gongchao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hertzbeat.git


The following commit(s) were added to refs/heads/master by this push:
     new 38d466b7f [Improve] add common/util/StrUtil unit test (#2301)
38d466b7f is described below

commit 38d466b7f8681ea0100032a357d5ac749e61de5d
Author: YuLuo <[email protected]>
AuthorDate: Wed Jul 17 22:36:42 2024 +0800

    [Improve] add common/util/StrUtil unit test (#2301)
    
    Signed-off-by: yuluo-yx <[email protected]>
---
 .../org/apache/hertzbeat/common/util/StrUtil.java  |  5 +-
 .../apache/hertzbeat/common/util/TimeZoneUtil.java |  6 +-
 .../apache/hertzbeat/common/util/StrUtilTest.java  | 66 ++++++++++++++++++++++
 3 files changed, 75 insertions(+), 2 deletions(-)

diff --git a/common/src/main/java/org/apache/hertzbeat/common/util/StrUtil.java 
b/common/src/main/java/org/apache/hertzbeat/common/util/StrUtil.java
index b5acf8517..b6aaa53ee 100644
--- a/common/src/main/java/org/apache/hertzbeat/common/util/StrUtil.java
+++ b/common/src/main/java/org/apache/hertzbeat/common/util/StrUtil.java
@@ -26,7 +26,10 @@ import java.util.Objects;
 /**
  * String processing tools
  */
-public class StrUtil {
+public final class StrUtil {
+
+    private StrUtil() {
+    }
 
     /**
      * Handle Comma Separated Data
diff --git 
a/common/src/main/java/org/apache/hertzbeat/common/util/TimeZoneUtil.java 
b/common/src/main/java/org/apache/hertzbeat/common/util/TimeZoneUtil.java
index 6a9e157cd..577258153 100644
--- a/common/src/main/java/org/apache/hertzbeat/common/util/TimeZoneUtil.java
+++ b/common/src/main/java/org/apache/hertzbeat/common/util/TimeZoneUtil.java
@@ -25,7 +25,11 @@ import org.apache.hertzbeat.common.constants.CommonConstants;
 /**
  * timezone util
  */
-public class TimeZoneUtil {
+public final class TimeZoneUtil {
+
+    private TimeZoneUtil() {
+    }
+
     private static final Integer LANG_REGION_LENGTH = 2;
 
     public static void setTimeZoneAndLocale(String timeZoneId, String locale) {
diff --git 
a/common/src/test/java/org/apache/hertzbeat/common/util/StrUtilTest.java 
b/common/src/test/java/org/apache/hertzbeat/common/util/StrUtilTest.java
new file mode 100644
index 000000000..9f50eb1a5
--- /dev/null
+++ b/common/src/test/java/org/apache/hertzbeat/common/util/StrUtilTest.java
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hertzbeat.common.util;
+
+import java.util.List;
+
+import org.junit.jupiter.api.Test;
+
+import static org.apache.hertzbeat.common.util.StrUtil.analysisArgToList;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ * Test case for {@link StrUtil}
+ */
+class StrUtilTest {
+
+       @Test
+       void testAnalysisArgToList() {
+               List<String> result = analysisArgToList(null);
+               assertTrue(result.isEmpty());
+
+               result = analysisArgToList("");
+               assertEquals(1, result.size());
+               assertEquals("", result.get(0));
+
+               result = analysisArgToList("element");
+               assertEquals(1, result.size());
+               assertEquals("element", result.get(0));
+
+               result = analysisArgToList("one,two,three");
+               assertEquals(3, result.size());
+               assertEquals("one", result.get(0));
+               assertEquals("two", result.get(1));
+               assertEquals("three", result.get(2));
+
+               result = analysisArgToList(" one , two , three ");
+               assertEquals(3, result.size());
+               assertEquals("one", result.get(0).trim());
+               assertEquals("two", result.get(1).trim());
+               assertEquals("three", result.get(2).trim());
+
+               result = analysisArgToList(",one,two,three,");
+               assertEquals(4, result.size());
+               assertEquals("", result.get(0));
+               assertEquals("one", result.get(1));
+               assertEquals("two", result.get(2));
+               assertEquals("three", result.get(3));
+       }
+
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to