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 { 038 // given 039 byte[] value = null; 040 NullComparator comparator = new NullComparator(); 041 042 // when 043 int comp1 = comparator.compareTo(value); 044 int comp2 = comparator.compareTo(value, 5, 15); 045 046 // then 047 Assert.assertEquals(0, comp1); 048 Assert.assertEquals(0, comp2); 049 } 050 051 @Test 052 public void testNonNullValue() { 053 // given 054 byte[] value = new byte[] { 0, 1, 2, 3, 4, 5 }; 055 NullComparator comparator = new NullComparator(); 056 057 // when 058 int comp1 = comparator.compareTo(value); 059 int comp2 = comparator.compareTo(value, 1, 3); 060 061 // then 062 Assert.assertEquals(1, comp1); 063 Assert.assertEquals(1, comp2); 064 } 065 066 @Test 067 public void testEmptyValue() { 068 // given 069 byte[] value = new byte[] { 0 }; 070 NullComparator comparator = new NullComparator(); 071 072 // when 073 int comp1 = comparator.compareTo(value); 074 int comp2 = comparator.compareTo(value, 1, 3); 075 076 // then 077 Assert.assertEquals(1, comp1); 078 Assert.assertEquals(1, comp2); 079 } 080 081}