You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kylin.apache.org by ni...@apache.org on 2019/05/03 15:06:40 UTC

[kylin] branch master updated: Added Unit Tests (#625)

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

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


The following commit(s) were added to refs/heads/master by this push:
     new 2076e39  Added Unit Tests (#625)
2076e39 is described below

commit 2076e394240c8a093606046df8b2ad6c3400fd80
Author: Michael Hausegger <ha...@googlemail.com>
AuthorDate: Fri May 3 17:06:34 2019 +0200

    Added Unit Tests (#625)
    
    * Added Unit Tests to increase code coverage
    
    * Removed star imports
    
    * Removed remaining star import
---
 .../org/apache/kylin/common/KylinConfigTest.java   |  44 ++++++-
 .../apache/kylin/common/util/StringUtilTest.java   | 133 ++++++++++++++++++++-
 2 files changed, 169 insertions(+), 8 deletions(-)

diff --git a/core-common/src/test/java/org/apache/kylin/common/KylinConfigTest.java b/core-common/src/test/java/org/apache/kylin/common/KylinConfigTest.java
index fec3de5..5283b39 100644
--- a/core-common/src/test/java/org/apache/kylin/common/KylinConfigTest.java
+++ b/core-common/src/test/java/org/apache/kylin/common/KylinConfigTest.java
@@ -18,12 +18,6 @@
 
 package org.apache.kylin.common;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-
 import java.util.Map;
 import java.util.Properties;
 
@@ -32,6 +26,13 @@ import org.junit.Test;
 
 import com.google.common.collect.Maps;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+
 public class KylinConfigTest extends HotLoadKylinPropertiesTestCase {
 
     @Test
@@ -166,4 +167,35 @@ public class KylinConfigTest extends HotLoadKylinPropertiesTestCase {
         assertEquals("BRACKET", extras.getProperty("quoting"));
         assertEquals("DEFAULT", extras.getProperty("conformance"));
     }
+
+  @Test
+  public void testSetKylinConfigInEnvIfMissingTakingEmptyProperties() {
+      Properties properties = new Properties();
+      KylinConfig.setKylinConfigInEnvIfMissing(properties);
+
+      assertEquals(0, properties.size());
+      assertTrue(properties.isEmpty());
+
+      KylinConfig.setKylinConfigInEnvIfMissing(properties);
+
+      assertEquals(0, properties.size());
+      assertTrue(properties.isEmpty());
+  }
+
+  @Test(expected = IllegalStateException.class)
+  public void testCreateInstanceFromUriThrowsIllegalStateExceptionOne() {
+        KylinConfig.createInstanceFromUri("cb%MnlG]3:nav");
+  }
+
+  @Test(expected = RuntimeException.class)
+  public void testCreateInstanceFromUriThrowsRuntimeException() {
+      Properties properties = new Properties();
+      KylinConfig.setKylinConfigInEnvIfMissing(properties);
+
+      assertEquals(0, properties.size());
+      assertTrue(properties.isEmpty());
+
+      KylinConfig.createInstanceFromUri("dHy3K~m");
+  }
+
 }
diff --git a/core-common/src/test/java/org/apache/kylin/common/util/StringUtilTest.java b/core-common/src/test/java/org/apache/kylin/common/util/StringUtilTest.java
index 76ceed5..4af8566 100644
--- a/core-common/src/test/java/org/apache/kylin/common/util/StringUtilTest.java
+++ b/core-common/src/test/java/org/apache/kylin/common/util/StringUtilTest.java
@@ -22,7 +22,22 @@ import com.google.common.collect.Lists;
 import org.junit.Assert;
 import org.junit.Test;
 
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.LinkedHashSet;
 import java.util.List;
+import java.util.Locale;
+import java.util.Set;
+import java.util.Vector;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
 
 public class StringUtilTest {
     @Test
@@ -63,7 +78,7 @@ public class StringUtilTest {
         stringListNormal.add("bbb");
         stringListNormal.add("ccc");
         String joinedNormal = StringUtil.join(stringListNormal, ",");
-        Assert.assertEquals("aaa,bbb,ccc", joinedNormal);
+        assertEquals("aaa,bbb,ccc", joinedNormal);
 
         stringListEmpty.add("");
         stringListEmpty.add("aa");
@@ -71,6 +86,120 @@ public class StringUtilTest {
         stringListEmpty.add("bb");
         stringListEmpty.add("");
         String joinedEmpty = StringUtil.join(stringListEmpty, ",");
-        Assert.assertEquals(",aa,,bb,", joinedEmpty);
+        assertEquals(",aa,,bb,", joinedEmpty);
     }
+
+  @Test
+  public void testDropSuffixWithNonEmptyString() {
+      assertEquals("", StringUtil.dropSuffix("Oo}T^z88/U", "Oo}T^z88/U"));
+  }
+
+  @Test
+  public void testDropSuffixWithEmptyString() {
+      String string = StringUtil.dropSuffix("", "^Fahs");
+
+      assertEquals("", string);
+  }
+
+  @Test
+  public void testNoBlankWithNull() {
+      assertEquals("%W=U~)O|0'#?,zA", StringUtil.noBlank(null, "%W=U~)O|0'#?,zA"));
+  }
+
+  @Test
+  public void testNoBlankWithNonEmptyString() {
+      assertEquals("N(sg", StringUtil.noBlank("N(sg", "H=!Cp(Ed5gral0qzo"));
+  }
+
+  @Test
+  public void testToUpperCaseArrayWithNonEmptyArray() {
+      String[] stringArray = new String[7];
+      stringArray[0] = "org.apache.kylin.common.util.StringUtil";
+      StringUtil.toUpperCaseArray(stringArray, stringArray);
+
+      assertEquals(7, stringArray.length);
+      assertEquals("[ORG.APACHE.KYLIN.COMMON.UTIL.STRINGUTIL, null, null, null, null, null, null]",
+              Arrays.asList(stringArray).toString()
+      );
+  }
+
+  @Test
+  public void testJoinReturningNonEmptyString() {
+      List<String> arrayList = new ArrayList<String>();
+      LinkedHashSet<String> linkedHashSet = new LinkedHashSet<String>(arrayList);
+      linkedHashSet.add(")'<Mw@ZR0IYF_l%*>");
+      linkedHashSet.add(null);
+      String resultString = StringUtil.join(linkedHashSet, null);
+
+      assertNotNull(resultString);
+      assertEquals(")'<Mw@ZR0IYF_l%*>", resultString);
+
+  }
+
+  @Test
+  public void testJoinOne() {
+      Vector<String> vector = new Vector<>();
+      vector.add(null);
+      String resultString = StringUtil.join(vector, "PB");
+
+      assertNotNull(resultString);
+      assertEquals("", resultString);
+  }
+
+  @Test
+  public void testJoinTwo() {
+      Set<String> set = Locale.CHINESE.getUnicodeLocaleAttributes();
+      String resultString = StringUtil.join(set, "Op");
+
+      assertTrue(set.isEmpty());
+      assertEquals(0, set.size());
+
+      assertNotNull(resultString);
+      assertEquals("", resultString);
+  }
+
+  @Test
+  public void testJoinReturningNull() {
+      String string = StringUtil.join((Iterable<String>) null, ")Y>1v&V0GU6a");
+
+      assertNull(string);
+  }
+
+  @Test
+  public void testTrimSuffixWithEmptyString() {
+      String string = StringUtil.trimSuffix(" 8VKQ&I*pSVr", "");
+
+      assertEquals(" 8VKQ&I*pSVr", string);
+  }
+
+  @Test
+  public void testTrimSuffixWithNonEmptyString() {
+      String string = StringUtil.trimSuffix(",", "5I;.t0F*5HV4");
+
+      assertEquals(",", string);
+  }
+
+  @Test
+  public void testFilterSystemArgsThrowsIllegalArgumentException() {
+      String[] stringArray = new String[4];
+      stringArray[0] = "-D";
+      try {
+        StringUtil.filterSystemArgs(stringArray);
+        fail("Expecting exception: IllegalArgumentException");
+
+      } catch(IllegalArgumentException e) {
+      }
+  }
+
+  @Test
+  public void testFilterSystemArgs() {
+      String[] stringArray = new String[1];
+      stringArray[0] = "J";
+      String[] stringArrayTwo = StringUtil.filterSystemArgs(stringArray);
+
+      assertFalse(stringArrayTwo.equals(stringArray));
+      assertEquals(1, stringArrayTwo.length);
+      assertEquals("J", stringArrayTwo[0]);
+  }
+
 }