You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by ps...@apache.org on 2019/07/10 08:33:44 UTC

[hbase] branch branch-1 updated: HBASE-22669 Add unit tests for org.apache.hadoop.hbase.util.Strings (#363)

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

psomogyi pushed a commit to branch branch-1
in repository https://gitbox.apache.org/repos/asf/hbase.git


The following commit(s) were added to refs/heads/branch-1 by this push:
     new a3dc5bc  HBASE-22669 Add unit tests for org.apache.hadoop.hbase.util.Strings (#363)
a3dc5bc is described below

commit a3dc5bcde16929fd9c4674313da560d7e51838b3
Author: Braavos <35...@users.noreply.github.com>
AuthorDate: Wed Jul 10 09:07:55 2019 +0100

    HBASE-22669 Add unit tests for org.apache.hadoop.hbase.util.Strings (#363)
    
    These tests were written using Diffblue Cover.
---
 .../org/apache/hadoop/hbase/util/TestStrings.java  | 65 ++++++++++++++++++++++
 1 file changed, 65 insertions(+)

diff --git a/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestStrings.java b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestStrings.java
new file mode 100644
index 0000000..c0722f7
--- /dev/null
+++ b/hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestStrings.java
@@ -0,0 +1,65 @@
+/**
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.hadoop.hbase.util;
+
+import org.apache.hadoop.hbase.testclassification.SmallTests;
+import org.junit.Assert;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.rules.ExpectedException;
+
+@Category({SmallTests.class})
+public class TestStrings {
+
+  @Rule
+  public final ExpectedException thrown = ExpectedException.none();
+
+  @Test
+  public void testAppendKeyValue() {
+    Assert.assertEquals("foo, bar=baz", Strings.appendKeyValue(
+            new StringBuilder("foo"), "bar", "baz").toString());
+    Assert.assertEquals("bar->baz", Strings.appendKeyValue(
+            new StringBuilder(), "bar", "baz", "->", "| ").toString());
+    Assert.assertEquals("foo, bar=baz", Strings.appendKeyValue(
+            new StringBuilder("foo"), "bar", "baz", "=", ", ").toString());
+    Assert.assertEquals("foo| bar->baz", Strings.appendKeyValue(
+            new StringBuilder("foo"), "bar", "baz", "->", "| ").toString());
+  }
+
+  @Test
+  public void testDomainNamePointerToHostName() {
+    Assert.assertNull(Strings.domainNamePointerToHostName(null));
+    Assert.assertEquals("foo",
+            Strings.domainNamePointerToHostName("foo"));
+    Assert.assertEquals("foo.com",
+            Strings.domainNamePointerToHostName("foo.com"));
+    Assert.assertEquals("foo.bar.com",
+            Strings.domainNamePointerToHostName("foo.bar.com"));
+    Assert.assertEquals("foo.bar.com",
+            Strings.domainNamePointerToHostName("foo.bar.com."));
+  }
+
+  @Test
+  public void testPadFront() {
+    Assert.assertEquals("ddfoo", Strings.padFront("foo", 'd', 5));
+
+    thrown.expect(IllegalArgumentException.class);
+    Strings.padFront("foo", 'd', 1);
+  }
+}