View Javadoc

1   /**
2    * 
3    *  Licensed under the Apache License, Version 2.0 (the "License");
4    *  you may not use this file except in compliance with the License.
5    *  You may obtain a copy of the License at
6    * 
7    *       http://www.apache.org/licenses/LICENSE-2.0
8    * 
9    *  Unless required by applicable law or agreed to in writing, software
10   *  distributed under the License is distributed on an "AS IS" BASIS,
11   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12   *  See the License for the specific language governing permissions and
13   *  limitations under the License.
14   *  under the License.
15   */
16  
17  package org.apache.hadoop.hbase.filter;
18  
19  import org.apache.hadoop.hbase.SmallTests;
20  import org.junit.Assert;
21  import org.junit.Test;
22  import org.junit.experimental.categories.Category;
23  
24  @Category(SmallTests.class)
25  public class TestNullComparator {
26  
27    @Test
28    public void testNullValue()
29    {
30      // given
31      byte[] value = null;
32      NullComparator comparator = new NullComparator();
33  
34      // when
35      int comp1 = comparator.compareTo(value);
36      int comp2 = comparator.compareTo(value, 5, 15);
37  
38      // then
39      Assert.assertEquals(0, comp1);
40      Assert.assertEquals(0, comp2);
41    }
42  
43    @Test
44    public void testNonNullValue() {
45      // given
46      byte[] value = new byte[] { 0, 1, 2, 3, 4, 5 };
47      NullComparator comparator = new NullComparator();
48  
49      // when
50      int comp1 = comparator.compareTo(value);
51      int comp2 = comparator.compareTo(value, 1, 3);
52  
53      // then
54      Assert.assertEquals(1, comp1);
55      Assert.assertEquals(1, comp2);
56    }
57  
58    @Test
59    public void testEmptyValue() {
60      // given
61      byte[] value = new byte[] { 0 };
62      NullComparator comparator = new NullComparator();
63  
64      // when
65      int comp1 = comparator.compareTo(value);
66      int comp2 = comparator.compareTo(value, 1, 3);
67  
68      // then
69      Assert.assertEquals(1, comp1);
70      Assert.assertEquals(1, comp2);
71    }
72  
73  }