test/unit/util/TimeoutMapTest.java
author cli
Wed, 14 Sep 2011 12:54:40 +0200
changeset 60 39f1fadf50a0
parent 1 6fceb66e1ad7
permissions -rwxr-xr-x
Add libcommons-codec-java to Debian dependencies.
     1 /*
     2  *   SONEWS News Server
     3  *   see AUTHORS for the list of contributors
     4  *
     5  *   This program is free software: you can redistribute it and/or modify
     6  *   it under the terms of the GNU General Public License as published by
     7  *   the Free Software Foundation, either version 3 of the License, or
     8  *   (at your option) any later version.
     9  *
    10  *   This program is distributed in the hope that it will be useful,
    11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
    12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    13  *   GNU General Public License for more details.
    14  *
    15  *   You should have received a copy of the GNU General Public License
    16  *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
    17  */
    18 
    19 package test.unit.util;
    20 
    21 import junit.framework.TestCase;
    22 import org.sonews.util.TimeoutMap;
    23 
    24 /**
    25  * Unit test for class org.sonews.util.TimeoutMap.
    26  * @author Christian Lins
    27  * @since sonews/0.5.0
    28  * @see org.sonews.util.TimeoutMap
    29  */
    30 public class TimeoutMapTest extends TestCase
    31 {
    32 
    33   public TimeoutMapTest()
    34   {
    35     super("TimeoutMapTest");
    36   }
    37   
    38   public void testTimeoutBehaviour()
    39   {
    40     TimeoutMap<String, Object> tm = new TimeoutMap<String, Object>(1000);
    41     Object testobj = new Object();
    42     
    43     tm.put("testkey", testobj);
    44     
    45     assertNotNull(tm.get("testkey"));
    46     assertTrue(tm.containsKey("testkey"));
    47     assertTrue(tm.contains(testobj));
    48     
    49     try
    50     {
    51       Thread.sleep(800);
    52     }
    53     catch(InterruptedException ex) { ex.printStackTrace(); }
    54     
    55     assertNotNull(tm.get("testkey"));
    56     assertTrue(tm.containsKey("testkey"));
    57     assertTrue(tm.contains(testobj));
    58     
    59     try
    60     {
    61       Thread.sleep(200);
    62     }
    63     catch(InterruptedException ex) { ex.printStackTrace(); }
    64     
    65     assertNull(tm.get("testkey"));
    66     assertFalse(tm.containsKey("testkey"));
    67     assertFalse(tm.contains(testobj));
    68   }
    69   
    70 }