Skip to content

Commit 6f0496f

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

2 files changed

Lines changed: 133 additions & 0 deletions

File tree

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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.Assert;
26+
import org.junit.ClassRule;
27+
import org.junit.Test;
28+
import org.junit.experimental.categories.Category;
29+
30+
@Category({SmallTests.class})
31+
public class TestByteRangeUtils {
32+
33+
@ClassRule
34+
public static final HBaseClassTestRule CLASS_RULE =
35+
HBaseClassTestRule.forClass(TestByteRangeUtils.class);
36+
37+
@Test
38+
public void testNumEqualPrefixBytes() {
39+
Assert.assertEquals(0, ByteRangeUtils.numEqualPrefixBytes(
40+
new SimpleByteRange(new byte[]{1, 2, 3}),
41+
new SimpleByteRange(new byte[]{4, 5, 6}), 1));
42+
Assert.assertEquals(2, ByteRangeUtils.numEqualPrefixBytes(
43+
new SimpleByteRange(new byte[]{1, 2, 3}),
44+
new SimpleByteRange(new byte[]{0, 1, 2}), 1));
45+
}
46+
47+
@Test
48+
public void testCopyToNewArrays() {
49+
Assert.assertEquals(new ArrayList<>(),
50+
ByteRangeUtils.copyToNewArrays(null));
51+
Assert.assertArrayEquals(new byte[]{1, 2, 3},
52+
ByteRangeUtils.copyToNewArrays(new ArrayList<>(Arrays.asList(
53+
new SimpleByteRange(new byte[]{1, 2, 3}),
54+
new SimpleByteRange(new byte[]{4, 5, 6})))).get(0));
55+
Assert.assertArrayEquals(new byte[]{4, 5, 6},
56+
ByteRangeUtils.copyToNewArrays(new ArrayList<>(Arrays.asList(
57+
new SimpleByteRange(new byte[]{1, 2, 3}),
58+
new SimpleByteRange(new byte[]{4, 5, 6})))).get(1));
59+
}
60+
61+
@Test
62+
public void testFromArrays() {
63+
Assert.assertEquals(new ArrayList<>(), ByteRangeUtils.fromArrays(null));
64+
Assert.assertEquals(new ArrayList<>(Arrays.asList(
65+
new SimpleMutableByteRange(new byte[]{1, 2, 3}),
66+
new SimpleMutableByteRange(new byte[]{4, 5, 6}))),
67+
ByteRangeUtils.fromArrays(new ArrayList<>(
68+
Arrays.asList(new byte[]{1, 2, 3}, new byte[]{4, 5, 6}))));
69+
}
70+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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.Assert;
25+
import org.junit.ClassRule;
26+
import org.junit.Rule;
27+
import org.junit.Test;
28+
import org.junit.experimental.categories.Category;
29+
import org.junit.rules.ExpectedException;
30+
31+
@Category({SmallTests.class})
32+
public class TestClasses {
33+
34+
@Rule
35+
public final ExpectedException thrown = ExpectedException.none();
36+
37+
@ClassRule
38+
public static final HBaseClassTestRule CLASS_RULE =
39+
HBaseClassTestRule.forClass(TestClasses.class);
40+
41+
@Test
42+
public void testExtendedForName() throws ClassNotFoundException {
43+
Assert.assertEquals(int.class, Classes.extendedForName("int"));
44+
Assert.assertEquals(long.class, Classes.extendedForName("long"));
45+
Assert.assertEquals(char.class, Classes.extendedForName("char"));
46+
Assert.assertEquals(byte.class, Classes.extendedForName("byte"));
47+
Assert.assertEquals(short.class, Classes.extendedForName("short"));
48+
Assert.assertEquals(float.class, Classes.extendedForName("float"));
49+
Assert.assertEquals(double.class, Classes.extendedForName("double"));
50+
Assert.assertEquals(boolean.class, Classes.extendedForName("boolean"));
51+
52+
thrown.expect(ClassNotFoundException.class);
53+
Classes.extendedForName("foo");
54+
}
55+
56+
@Test
57+
public void testStringify() {
58+
Assert.assertEquals("", Classes.stringify(new Class[0]));
59+
Assert.assertEquals("NULL", Classes.stringify(null));
60+
Assert.assertEquals("java.lang.String,java.lang.Integer",
61+
Classes.stringify(new Class[]{String.class, Integer.class}));
62+
}
63+
}

0 commit comments

Comments
 (0)