001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018package org.apache.hadoop.hbase.filter; 019 020import org.apache.hadoop.hbase.HBaseClassTestRule; 021import org.apache.hadoop.hbase.testclassification.FilterTests; 022import org.apache.hadoop.hbase.testclassification.SmallTests; 023import org.junit.Assert; 024import org.junit.ClassRule; 025import org.junit.Test; 026import org.junit.experimental.categories.Category; 027 028@Category({ FilterTests.class, SmallTests.class }) 029public class TestNullComparator { 030 031 @ClassRule 032 public static final HBaseClassTestRule CLASS_RULE = 033 HBaseClassTestRule.forClass(TestNullComparator.class); 034 035 @Test 036 public void testNullValue() { 037 // given 038 byte[] value = null; 039 NullComparator comparator = new NullComparator(); 040 041 // when 042 int comp1 = comparator.compareTo(value); 043 int comp2 = comparator.compareTo(value, 5, 15); 044 045 // then 046 Assert.assertEquals(0, comp1); 047 Assert.assertEquals(0, comp2); 048 } 049 050 @Test 051 public void testNonNullValue() { 052 // given 053 byte[] value = new byte[] { 0, 1, 2, 3, 4, 5 }; 054 NullComparator comparator = new NullComparator(); 055 056 // when 057 int comp1 = comparator.compareTo(value); 058 int comp2 = comparator.compareTo(value, 1, 3); 059 060 // then 061 Assert.assertEquals(1, comp1); 062 Assert.assertEquals(1, comp2); 063 } 064 065 @Test 066 public void testEmptyValue() { 067 // given 068 byte[] value = new byte[] { 0 }; 069 NullComparator comparator = new NullComparator(); 070 071 // when 072 int comp1 = comparator.compareTo(value); 073 int comp2 = comparator.compareTo(value, 1, 3); 074 075 // then 076 Assert.assertEquals(1, comp1); 077 Assert.assertEquals(1, comp2); 078 } 079 080}