View Javadoc

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,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  
20  package org.apache.hadoop.hbase.filter;
21  
22  import org.apache.hadoop.hbase.testclassification.SmallTests;
23  import org.junit.Assert;
24  import org.junit.Test;
25  import org.junit.experimental.categories.Category;
26  
27  @Category(SmallTests.class)
28  public class TestNullComparator {
29  
30    @Test
31    public void testNullValue()
32    {
33      // given
34      byte[] value = null;
35      NullComparator comparator = new NullComparator();
36  
37      // when
38      int comp1 = comparator.compareTo(value);
39      int comp2 = comparator.compareTo(value, 5, 15);
40  
41      // then
42      Assert.assertEquals(0, comp1);
43      Assert.assertEquals(0, comp2);
44    }
45  
46    @Test
47    public void testNonNullValue() {
48      // given
49      byte[] value = new byte[] { 0, 1, 2, 3, 4, 5 };
50      NullComparator comparator = new NullComparator();
51  
52      // when
53      int comp1 = comparator.compareTo(value);
54      int comp2 = comparator.compareTo(value, 1, 3);
55  
56      // then
57      Assert.assertEquals(1, comp1);
58      Assert.assertEquals(1, comp2);
59    }
60  
61    @Test
62    public void testEmptyValue() {
63      // given
64      byte[] value = new byte[] { 0 };
65      NullComparator comparator = new NullComparator();
66  
67      // when
68      int comp1 = comparator.compareTo(value);
69      int comp2 = comparator.compareTo(value, 1, 3);
70  
71      // then
72      Assert.assertEquals(1, comp1);
73      Assert.assertEquals(1, comp2);
74    }
75  
76  }