pylucene 3.5.0-3
[pylucene.git] / lucene-java-3.5.0 / lucene / contrib / facet / src / test / org / apache / lucene / facet / index / params / CategoryListParamsTest.java
1 package org.apache.lucene.facet.index.params;
2
3 import org.apache.lucene.index.Term;
4 import org.junit.Test;
5
6 import org.apache.lucene.util.LuceneTestCase;
7 import org.apache.lucene.facet.index.params.CategoryListParams;
8
9 /**
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
16  *
17  *     http://www.apache.org/licenses/LICENSE-2.0
18  *
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.
24  */
25
26 public class CategoryListParamsTest extends LuceneTestCase {
27
28   @Test
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());
34   }
35   
36   /**
37    * Test that the {@link CategoryListParams#hashCode()} and
38    * {@link CategoryListParams#equals(Object)} are consistent.
39    */
40   @Test
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());
49   }
50
51   /**
52    * Test that CategoryListParams behave correctly when compared against each
53    * other.
54    */
55   @Test
56   public void testIdentityConsistency() {
57     // Test 2 CategoryListParams with the default parameter
58     CategoryListParams clParams1 = new CategoryListParams();
59     CategoryListParams clParams2 = new CategoryListParams();
60     assertEquals(
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());
65
66     // Test 2 CategoryListParams with the same specified Term
67     clParams1 = new CategoryListParams(new Term("test"));
68     clParams2 = new CategoryListParams(new Term("test"));
69     assertEquals(
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());
74     
75     // Test 2 CategoryListParams with DIFFERENT terms
76     clParams1 = new CategoryListParams(new Term("test1"));
77     clParams2 = new CategoryListParams(new Term("test2"));
78     assertFalse(
79         "2 CategoryListParams with the different terms should NOT equal each other.",
80         clParams1.equals(clParams2));
81     assertFalse(
82         "2 CategoryListParams with the different terms should NOT have the same hashcode.",
83         clParams1.hashCode() == clParams2.hashCode());
84   }
85
86 }