~slub.team/goobi-indexserver/3.x

« back to all changes in this revision

Viewing changes to lucene/contrib/facet/src/test/org/apache/lucene/util/collections/TestLRUHashMap.java

  • Committer: Sebastian Meyer
  • Date: 2012-08-03 09:12:40 UTC
  • Revision ID: sebastian.meyer@slub-dresden.de-20120803091240-x6861b0vabq1xror
Remove Lucene and Solr source code and add patches instead
Fix Bug #985487: Auto-suggestion for the search interface

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
package org.apache.lucene.util.collections;
2
 
 
3
 
import org.junit.Test;
4
 
 
5
 
import org.apache.lucene.util.LuceneTestCase;
6
 
import org.apache.lucene.util.collections.LRUHashMap;
7
 
 
8
 
/**
9
 
 * Licensed to the Apache Software Foundation (ASF) under one or more
10
 
 * contributor license agreements.  See the NOTICE file distributed with
11
 
 * this work for additional information regarding copyright ownership.
12
 
 * The ASF licenses this file to You under the Apache License, Version 2.0
13
 
 * (the "License"); you may not use this file except in compliance with
14
 
 * the License.  You may obtain a copy of the License at
15
 
 *
16
 
 *     http://www.apache.org/licenses/LICENSE-2.0
17
 
 *
18
 
 * Unless required by applicable law or agreed to in writing, software
19
 
 * distributed under the License is distributed on an "AS IS" BASIS,
20
 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21
 
 * See the License for the specific language governing permissions and
22
 
 * limitations under the License.
23
 
 */
24
 
 
25
 
public class TestLRUHashMap extends LuceneTestCase {
26
 
  // testLRU() tests that the specified size limit is indeed honored, and
27
 
  // the remaining objects in the map are indeed those that have been most
28
 
  // recently used
29
 
  @Test
30
 
  public void testLRU() throws Exception {
31
 
    LRUHashMap<String, String> lru = new LRUHashMap<String, String>(3);
32
 
    assertEquals(0, lru.size());
33
 
    lru.put("one", "Hello world");
34
 
    assertEquals(1, lru.size());
35
 
    lru.put("two", "Hi man");
36
 
    assertEquals(2, lru.size());
37
 
    lru.put("three", "Bonjour");
38
 
    assertEquals(3, lru.size());
39
 
    lru.put("four", "Shalom");
40
 
    assertEquals(3, lru.size());
41
 
    assertNotNull(lru.get("three"));
42
 
    assertNotNull(lru.get("two"));
43
 
    assertNotNull(lru.get("four"));
44
 
    assertNull(lru.get("one"));
45
 
    lru.put("five", "Yo!");
46
 
    assertEquals(3, lru.size());
47
 
    assertNull(lru.get("three")); // three was last used, so it got removed
48
 
    assertNotNull(lru.get("five"));
49
 
    lru.get("four");
50
 
    lru.put("six", "hi");
51
 
    lru.put("seven", "hey dude");
52
 
    assertEquals(3, lru.size());
53
 
    assertNull(lru.get("one"));
54
 
    assertNull(lru.get("two"));
55
 
    assertNull(lru.get("three"));
56
 
    assertNotNull(lru.get("four"));
57
 
    assertNull(lru.get("five"));
58
 
    assertNotNull(lru.get("six"));
59
 
    assertNotNull(lru.get("seven"));
60
 
  }
61
 
}