From ac2cc7339de628feb9ae168219d8e0deff8d6194 Mon Sep 17 00:00:00 2001 From: Michael Hausegger Date: Fri, 3 May 2019 02:29:24 +0200 Subject: [PATCH] Added Unit Tests to increase code coverage (#2571) --- .../skywalking/apm/util/StringUtilTest.java | 15 ++++++++++++++- .../util/PropertyPlaceholderHelperTest.java | 13 +++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/apm-commons/apm-util/src/test/java/org/apache/skywalking/apm/util/StringUtilTest.java b/apm-commons/apm-util/src/test/java/org/apache/skywalking/apm/util/StringUtilTest.java index f4a0b8d06..b918e2e4b 100644 --- a/apm-commons/apm-util/src/test/java/org/apache/skywalking/apm/util/StringUtilTest.java +++ b/apm-commons/apm-util/src/test/java/org/apache/skywalking/apm/util/StringUtilTest.java @@ -39,5 +39,18 @@ public class StringUtilTest { Assert.assertNull(StringUtil.join('.')); Assert.assertEquals("Single part.", StringUtil.join('.', "Single part.")); Assert.assertEquals("part1.part2.p3", StringUtil.join('.', "part1", "part2", "p3")); + Assert.assertEquals("E", StringUtil.join('E', new String[2])); } -} + + @Test + public void testSubstringMatchReturningTrue() { + StringBuffer stringBuffer = new StringBuffer("ZP~>xz1;"); + Assert.assertTrue(StringUtil.substringMatch(stringBuffer, 0, stringBuffer)); + } + + @Test + public void testSubstringMatchWithPositive() { + Assert.assertFalse(StringUtil.substringMatch("", 4770, "")); + } + +} \ No newline at end of file diff --git a/oap-server/server-library/library-util/src/test/java/org/apache/skywalking/oap/server/library/util/PropertyPlaceholderHelperTest.java b/oap-server/server-library/library-util/src/test/java/org/apache/skywalking/oap/server/library/util/PropertyPlaceholderHelperTest.java index 53bcc55f1..0771e8f33 100644 --- a/oap-server/server-library/library-util/src/test/java/org/apache/skywalking/oap/server/library/util/PropertyPlaceholderHelperTest.java +++ b/oap-server/server-library/library-util/src/test/java/org/apache/skywalking/oap/server/library/util/PropertyPlaceholderHelperTest.java @@ -80,6 +80,19 @@ public class PropertyPlaceholderHelperTest { yaml.load(placeholderHelper.replacePlaceholders(properties.getProperty("restPort"), properties))); } + @Test + public void testReplacePlaceholders() { + PropertyPlaceholderHelper propertyPlaceholderHelper = PropertyPlaceholderHelper.INSTANCE; + Properties properties = new Properties(); + String resultString = propertyPlaceholderHelper.replacePlaceholders("&${[}7", properties); + + Assert.assertEquals(0, properties.size()); + Assert.assertTrue(properties.isEmpty()); + + Assert.assertNotNull(resultString); + Assert.assertEquals("&${[}7", resultString); + } + @After public void afterTest() { //revert environment variables changes after the test for safe.