Skip to content

Commit 53a8c26

Browse files
EricHettipetersomogyi
authored andcommitted
HBASE-22669 Add unit tests for org.apache.hadoop.hbase.util.Strings (#363)
These tests were written using Diffblue Cover.
1 parent 9ac9505 commit 53a8c26

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
* <p>
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
* <p>
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
package org.apache.hadoop.hbase.util;
19+
20+
import org.apache.hadoop.hbase.HBaseClassTestRule;
21+
import org.apache.hadoop.hbase.testclassification.SmallTests;
22+
import org.junit.Assert;
23+
import org.junit.ClassRule;
24+
import org.junit.Rule;
25+
import org.junit.Test;
26+
import org.junit.experimental.categories.Category;
27+
import org.junit.rules.ExpectedException;
28+
29+
@Category({SmallTests.class})
30+
public class TestStrings {
31+
32+
@Rule
33+
public final ExpectedException thrown = ExpectedException.none();
34+
35+
@ClassRule
36+
public static final HBaseClassTestRule CLASS_RULE =
37+
HBaseClassTestRule.forClass(TestStrings.class);
38+
39+
@Test
40+
public void testAppendKeyValue() {
41+
Assert.assertEquals("foo, bar=baz", Strings.appendKeyValue(
42+
new StringBuilder("foo"), "bar", "baz").toString());
43+
Assert.assertEquals("bar->baz", Strings.appendKeyValue(
44+
new StringBuilder(), "bar", "baz", "->", "| ").toString());
45+
Assert.assertEquals("foo, bar=baz", Strings.appendKeyValue(
46+
new StringBuilder("foo"), "bar", "baz", "=", ", ").toString());
47+
Assert.assertEquals("foo| bar->baz", Strings.appendKeyValue(
48+
new StringBuilder("foo"), "bar", "baz", "->", "| ").toString());
49+
}
50+
51+
@Test
52+
public void testDomainNamePointerToHostName() {
53+
Assert.assertNull(Strings.domainNamePointerToHostName(null));
54+
Assert.assertEquals("foo",
55+
Strings.domainNamePointerToHostName("foo"));
56+
Assert.assertEquals("foo.com",
57+
Strings.domainNamePointerToHostName("foo.com"));
58+
Assert.assertEquals("foo.bar.com",
59+
Strings.domainNamePointerToHostName("foo.bar.com"));
60+
Assert.assertEquals("foo.bar.com",
61+
Strings.domainNamePointerToHostName("foo.bar.com."));
62+
}
63+
64+
@Test
65+
public void testPadFront() {
66+
Assert.assertEquals("ddfoo", Strings.padFront("foo", 'd', 5));
67+
68+
thrown.expect(IllegalArgumentException.class);
69+
Strings.padFront("foo", 'd', 1);
70+
}
71+
}

0 commit comments

Comments
 (0)