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 static org.junit.jupiter.api.Assertions.assertEquals; 021 022import org.apache.hadoop.hbase.testclassification.FilterTests; 023import org.apache.hadoop.hbase.testclassification.SmallTests; 024import org.junit.jupiter.api.Tag; 025import org.junit.jupiter.api.Test; 026 027@Tag(FilterTests.TAG) 028@Tag(SmallTests.TAG) 029public class TestNullComparator { 030 031 @Test 032 public void testNullValue() { 033 // given 034 byte[] value = null; 035 NullComparator comparator = new NullComparator(); 036 037 // when 038 int comp1 = comparator.compareTo(value); 039 int comp2 = comparator.compareTo(value, 5, 15); 040 041 // then 042 assertEquals(0, comp1); 043 assertEquals(0, comp2); 044 } 045 046 @Test 047 public void testNonNullValue() { 048 // given 049 byte[] value = new byte[] { 0, 1, 2, 3, 4, 5 }; 050 NullComparator comparator = new NullComparator(); 051 052 // when 053 int comp1 = comparator.compareTo(value); 054 int comp2 = comparator.compareTo(value, 1, 3); 055 056 // then 057 assertEquals(1, comp1); 058 assertEquals(1, comp2); 059 } 060 061 @Test 062 public void testEmptyValue() { 063 // given 064 byte[] value = new byte[] { 0 }; 065 NullComparator comparator = new NullComparator(); 066 067 // when 068 int comp1 = comparator.compareTo(value); 069 int comp2 = comparator.compareTo(value, 1, 3); 070 071 // then 072 assertEquals(1, comp1); 073 assertEquals(1, comp2); 074 } 075 076}