1 /*
2 * Copyright (c) 2002-2003 by OpenSymphony
3 * All rights reserved.
4 */
5 package com.opensymphony.oscache.base.algorithm;
6
7 import junit.framework.Test;
8 import junit.framework.TestSuite;
9
10 /**
11 * Test class for the FIFOCache class. It tests that the algorithm reacts as
12 * expected when entries are removed
13 *
14 * $Id: TestFIFOCache.java,v 1.1 2005/06/17 05:07:08 dres Exp $
15 * @version $Revision: 1.1 $
16 * @author <a href="mailto:abergevin@pyxis-tech.com">Alain Bergevin</a>
17 */
18 public final class TestFIFOCache extends TestQueueCache {
19 /**
20 * FIFO Cache object
21 */
22 private static FIFOCache cache = null;
23
24 /**
25 * Constructor
26 * <p>
27 * @param str The test name (required by JUnit)
28 */
29 public TestFIFOCache(String str) {
30 super(str);
31 }
32
33 /**
34 * This methods returns the name of this test class to JUnit
35 * <p>
36 * @return The test for this class
37 */
38 public static Test suite() {
39 return new TestSuite(TestFIFOCache.class);
40 }
41
42 /**
43 * Abstract method used by the TestAbstractCache class
44 * <p>
45 * @return A cache instance
46 */
47 public AbstractConcurrentReadCache getCache() {
48 return cache;
49 }
50
51 /**
52 * This method is invoked before each testXXXX methods of the
53 * class. It set ups the variables required for each tests.
54 */
55 public void setUp() {
56 // Create a cache instance on first invocation
57 if (cache == null) {
58 cache = new FIFOCache();
59 assertNotNull(cache);
60 }
61 }
62
63 /**
64 * Test the cache algorithm
65 */
66 public void testRemoveItem() {
67 // Add 2 elements in the cache and ensure that the one to remove is the first
68 // inserted
69 cache.itemPut(KEY);
70 cache.itemPut(KEY + 1);
71 assertTrue(KEY.equals(cache.removeItem()));
72 }
73 }