1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.hadoop.hbase.util;
19
20 import org.apache.hadoop.hbase.testclassification.SmallTests;
21 import org.junit.Assert;
22 import org.junit.Rule;
23 import org.junit.Test;
24 import org.junit.experimental.categories.Category;
25 import org.junit.rules.ExpectedException;
26
27 @Category({SmallTests.class})
28 public class TestStrings {
29
30 @Rule
31 public final ExpectedException thrown = ExpectedException.none();
32
33 @Test
34 public void testAppendKeyValue() {
35 Assert.assertEquals("foo, bar=baz", Strings.appendKeyValue(
36 new StringBuilder("foo"), "bar", "baz").toString());
37 Assert.assertEquals("bar->baz", Strings.appendKeyValue(
38 new StringBuilder(), "bar", "baz", "->", "| ").toString());
39 Assert.assertEquals("foo, bar=baz", Strings.appendKeyValue(
40 new StringBuilder("foo"), "bar", "baz", "=", ", ").toString());
41 Assert.assertEquals("foo| bar->baz", Strings.appendKeyValue(
42 new StringBuilder("foo"), "bar", "baz", "->", "| ").toString());
43 }
44
45 @Test
46 public void testDomainNamePointerToHostName() {
47 Assert.assertNull(Strings.domainNamePointerToHostName(null));
48 Assert.assertEquals("foo",
49 Strings.domainNamePointerToHostName("foo"));
50 Assert.assertEquals("foo.com",
51 Strings.domainNamePointerToHostName("foo.com"));
52 Assert.assertEquals("foo.bar.com",
53 Strings.domainNamePointerToHostName("foo.bar.com"));
54 Assert.assertEquals("foo.bar.com",
55 Strings.domainNamePointerToHostName("foo.bar.com."));
56 }
57
58 @Test
59 public void testPadFront() {
60 Assert.assertEquals("ddfoo", Strings.padFront("foo", 'd', 5));
61
62 thrown.expect(IllegalArgumentException.class);
63 Strings.padFront("foo", 'd', 1);
64 }
65 }