1   /*
2    *   Licensed to the Apache Software Foundation (ASF) under one
3    *   or more contributor license agreements.  See the NOTICE file
4    *   distributed with this work for additional information
5    *   regarding copyright ownership.  The ASF licenses this file
6    *   to you under the Apache License, Version 2.0 (the
7    *   "License"); you may not use this file except in compliance
8    *   with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   *   Unless required by applicable law or agreed to in writing,
13   *   software distributed under the License is distributed on an
14   *   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   *   KIND, either express or implied.  See the License for the
16   *   specific language governing permissions and limitations
17   *   under the License.
18   *
19   */
20  
21  package org.apache.mina.util;
22  
23  
24  import junit.framework.TestCase;
25  
26  import org.junit.Before;
27  
28  /**
29   * Simple test that checks to see if the {@link ExpiringMap} can
30   * properly clean up itself.
31   *
32   * @author The Apache MINA Project (dev@mina.apache.org)
33   * @version $Rev$, $Date$
34   */
35  public class ExpiringMapTest extends TestCase
36  {
37      private ExpiringMap<String,String> theMap;
38      
39      /**
40       * Create the map, populate it and then kick off 
41       * the Expirer, then sleep long enough so that the
42       * Expirer can clean up the map.
43       *
44       * @throws java.lang.Exception
45       */
46      @Before
47      public void setUp() throws Exception
48      {
49          theMap = new ExpiringMap<String,String>(1, 2);
50          theMap.put( "Apache", "MINA" );
51          theMap.getExpirer().startExpiringIfNotStarted();
52          Thread.sleep(3000);
53      }
54  
55      /**
56       * Check to see if the map has been cleaned up.
57       *
58       */
59      public void testGet(){
60          assertNull( theMap.get( "Apache" ) );
61      }
62  }