Skip to content

Commit 6bd6e08

Browse files
committed
HBASE-22677 Add unit tests for org.apache.hadoop.hbase.util.ByteRange.Utils and Classes
These tests were written using Diffblue Cover.
1 parent 53a8c26 commit 6bd6e08

File tree

2 files changed

+136
-0
lines changed

2 files changed

+136
-0
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
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 java.util.ArrayList;
21+
import java.util.Arrays;
22+
23+
import org.apache.hadoop.hbase.HBaseClassTestRule;
24+
import org.apache.hadoop.hbase.testclassification.SmallTests;
25+
import org.junit.ClassRule;
26+
import org.junit.Test;
27+
import org.junit.experimental.categories.Category;
28+
29+
import static org.junit.Assert.assertArrayEquals;
30+
import static org.junit.Assert.assertEquals;
31+
32+
@Category({SmallTests.class})
33+
public class TestByteRangeUtils {
34+
35+
@ClassRule
36+
public static final HBaseClassTestRule CLASS_RULE =
37+
HBaseClassTestRule.forClass(TestByteRangeUtils.class);
38+
39+
@Test
40+
public void testNumEqualPrefixBytes() {
41+
assertEquals(0, ByteRangeUtils.numEqualPrefixBytes(
42+
new SimpleByteRange(new byte[]{1, 2, 3}),
43+
new SimpleByteRange(new byte[]{4, 5, 6}), 1));
44+
assertEquals(2, ByteRangeUtils.numEqualPrefixBytes(
45+
new SimpleByteRange(new byte[]{1, 2, 3}),
46+
new SimpleByteRange(new byte[]{0, 1, 2}), 1));
47+
}
48+
49+
@Test
50+
public void testCopyToNewArrays() {
51+
assertEquals(new ArrayList<>(),
52+
ByteRangeUtils.copyToNewArrays(null));
53+
assertArrayEquals(new byte[]{1, 2, 3},
54+
ByteRangeUtils.copyToNewArrays(new ArrayList<>(Arrays.asList(
55+
new SimpleByteRange(new byte[]{1, 2, 3}),
56+
new SimpleByteRange(new byte[]{4, 5, 6})))).get(0));
57+
assertArrayEquals(new byte[]{4, 5, 6},
58+
ByteRangeUtils.copyToNewArrays(new ArrayList<>(Arrays.asList(
59+
new SimpleByteRange(new byte[]{1, 2, 3}),
60+
new SimpleByteRange(new byte[]{4, 5, 6})))).get(1));
61+
}
62+
63+
@Test
64+
public void testFromArrays() {
65+
assertEquals(new ArrayList<>(), ByteRangeUtils.fromArrays(null));
66+
assertEquals(new ArrayList<>(Arrays.asList(
67+
new SimpleMutableByteRange(new byte[]{1, 2, 3}),
68+
new SimpleMutableByteRange(new byte[]{4, 5, 6}))),
69+
ByteRangeUtils.fromArrays(new ArrayList<>(
70+
Arrays.asList(new byte[]{1, 2, 3}, new byte[]{4, 5, 6}))));
71+
}
72+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* Copyright The Apache Software Foundation
3+
*
4+
* Licensed to the Apache Software Foundation (ASF) under one
5+
* or more contributor license agreements. See the NOTICE file
6+
* distributed with this work for additional information
7+
* regarding copyright ownership. The ASF licenses this file
8+
* to you under the Apache License, Version 2.0 (the
9+
* "License"); you may not use this file except in compliance
10+
* with the License. You may obtain a copy of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing, software
15+
* distributed under the License is distributed on an "AS IS" BASIS,
16+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
* See the License for the specific language governing permissions and
18+
* limitations under the License.
19+
*/
20+
package org.apache.hadoop.hbase.util;
21+
22+
import org.apache.hadoop.hbase.HBaseClassTestRule;
23+
import org.apache.hadoop.hbase.testclassification.SmallTests;
24+
import org.junit.ClassRule;
25+
import org.junit.Rule;
26+
import org.junit.Test;
27+
import org.junit.experimental.categories.Category;
28+
import org.junit.rules.ExpectedException;
29+
30+
import static org.junit.Assert.assertEquals;
31+
32+
@Category({SmallTests.class})
33+
public class TestClasses {
34+
35+
@Rule
36+
public final ExpectedException thrown = ExpectedException.none();
37+
38+
@ClassRule
39+
public static final HBaseClassTestRule CLASS_RULE =
40+
HBaseClassTestRule.forClass(TestClasses.class);
41+
42+
@Test
43+
public void testExtendedForName() throws ClassNotFoundException {
44+
assertEquals(int.class, Classes.extendedForName("int"));
45+
assertEquals(long.class, Classes.extendedForName("long"));
46+
assertEquals(char.class, Classes.extendedForName("char"));
47+
assertEquals(byte.class, Classes.extendedForName("byte"));
48+
assertEquals(short.class, Classes.extendedForName("short"));
49+
assertEquals(float.class, Classes.extendedForName("float"));
50+
assertEquals(double.class, Classes.extendedForName("double"));
51+
assertEquals(boolean.class, Classes.extendedForName("boolean"));
52+
53+
thrown.expect(ClassNotFoundException.class);
54+
Classes.extendedForName("foo");
55+
}
56+
57+
@Test
58+
public void testStringify() {
59+
assertEquals("", Classes.stringify(new Class[0]));
60+
assertEquals("NULL", Classes.stringify(null));
61+
assertEquals("java.lang.String,java.lang.Integer",
62+
Classes.stringify(new Class[]{String.class, Integer.class}));
63+
}
64+
}

0 commit comments

Comments
 (0)