-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HBASE-22669 Add unit tests for org.apache.hadoop.hbase.util.Strings (#…
…363) These tests were written using Diffblue Cover.
- Loading branch information
1 parent
9ac9505
commit 53a8c26
Showing
1 changed file
with
71 additions
and
0 deletions.
There are no files selected for viewing
71 changes: 71 additions & 0 deletions
71
hbase-common/src/test/java/org/apache/hadoop/hbase/util/TestStrings.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/** | ||
* 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.HBaseClassTestRule; | ||
import org.apache.hadoop.hbase.testclassification.SmallTests; | ||
import org.junit.Assert; | ||
import org.junit.ClassRule; | ||
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(); | ||
|
||
@ClassRule | ||
public static final HBaseClassTestRule CLASS_RULE = | ||
HBaseClassTestRule.forClass(TestStrings.class); | ||
|
||
@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); | ||
} | ||
} |