1 package org.apache.lucene.facet.index.params;
3 import org.apache.lucene.index.Term;
6 import org.apache.lucene.util.LuceneTestCase;
7 import org.apache.lucene.facet.index.params.CategoryListParams;
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed with
12 * this work for additional information regarding copyright ownership.
13 * The ASF licenses this file to You under the Apache License, Version 2.0
14 * (the "License"); you may not use this file except in compliance with
15 * the License. You may obtain a copy of the License at
17 * http://www.apache.org/licenses/LICENSE-2.0
19 * Unless required by applicable law or agreed to in writing, software
20 * distributed under the License is distributed on an "AS IS" BASIS,
21 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22 * See the License for the specific language governing permissions and
23 * limitations under the License.
26 public class CategoryListParamsTest extends LuceneTestCase {
29 public void testDefaultSettings() {
30 CategoryListParams clp = new CategoryListParams();
31 assertEquals("wrong default term", new Term("$facets", "$fulltree$"), clp.getTerm());
32 assertEquals("unexpected default encoder", "Sorting (Unique (DGap (VInt8)))", clp.createEncoder().toString());
33 assertEquals("unexpected default decoder", "DGap (VInt8)", clp.createEncoder().createMatchingDecoder().toString());
37 * Test that the {@link CategoryListParams#hashCode()} and
38 * {@link CategoryListParams#equals(Object)} are consistent.
41 public void testIdentity() {
42 CategoryListParams clParams1 = new CategoryListParams();
43 // Assert identity is correct - a CategoryListParams equals itself.
44 assertEquals("A CategoryListParams object does not equal itself.",
45 clParams1, clParams1);
46 // For completeness, the object's hashcode equals itself
47 assertEquals("A CategoryListParams object's hashCode does not equal itself.",
48 clParams1.hashCode(), clParams1.hashCode());
52 * Test that CategoryListParams behave correctly when compared against each
56 public void testIdentityConsistency() {
57 // Test 2 CategoryListParams with the default parameter
58 CategoryListParams clParams1 = new CategoryListParams();
59 CategoryListParams clParams2 = new CategoryListParams();
61 "2 CategoryListParams with the same default term should equal each other.",
62 clParams1, clParams2);
63 assertEquals("2 CategoryListParams with the same default term should have the same hashcode",
64 clParams1.hashCode(), clParams2.hashCode());
66 // Test 2 CategoryListParams with the same specified Term
67 clParams1 = new CategoryListParams(new Term("test"));
68 clParams2 = new CategoryListParams(new Term("test"));
70 "2 CategoryListParams with the same term should equal each other.",
71 clParams1, clParams2);
72 assertEquals("2 CategoryListParams with the same term should have the same hashcode",
73 clParams1.hashCode(), clParams2.hashCode());
75 // Test 2 CategoryListParams with DIFFERENT terms
76 clParams1 = new CategoryListParams(new Term("test1"));
77 clParams2 = new CategoryListParams(new Term("test2"));
79 "2 CategoryListParams with the different terms should NOT equal each other.",
80 clParams1.equals(clParams2));
82 "2 CategoryListParams with the different terms should NOT have the same hashcode.",
83 clParams1.hashCode() == clParams2.hashCode());