Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright 1&1 Internet AG, https://github.com/1and1/ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
 
 package net.oneandone.jasmin.cache;
 
 import org.junit.Test;
 
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertSame;
 
 public class CacheTest {
     private TestCache cache;
 
     @Before
     public void before() {
          = new TestCache(500);
     }
 
     @After
     public void after() {
         .validate();
         .resize(0);
     }
 
     @Test
     public void get() throws IOException {
         String key = "foo";
         String value;
 
         assertNull(.probe(key));
         value = .get(key);
         assertSame(keyvalue);
         assertSame(key.probe(key));
         assertEquals(1, .items());
         assertEquals(3, .size());
     }
 
     @Test
     public void free() throws IOException {
         String key = "foo";
 
         .get(key);
         assertEquals(1, .items());
         .resize(4);
         assertEquals(1, .items());
         .resize(3);
         assertEquals(1, .items());
         .resize(2);
         assertEquals(0, .items());
         assertEquals(0, .size());
         assertNull(.probe(key));
     }
 
     @Test
     public void ordering() throws IOException {
         .get("foo");
         .get("bar");
         .resize(3);
         assertEquals(1, .items());
         assertNull(.probe("foo"));
         assertNotNull(.probe("bar"));
     }
 
     @Test
     public void reordering() throws IOException {
         .get("foo");
         .get("bar");
         .get("foo");
         .resize(3);
         assertEquals(1, .items());
         assertNull(.probe("bar"));
         assertNotNull(.probe("foo"));
     }
 
     @Test
     public void stats() throws IOException {
         String key = "foo";
 
         assertEquals(0, .gets());
         assertEquals(0, .misses());
        .get(key);
        assertEquals(1, .gets());
        assertEquals(1, .misses());
        .get(key);
        assertEquals(2, .gets());
        assertEquals(1, .misses());
        .resize(0);
        assertEquals(2, .gets());
        assertEquals(1, .misses());
        .get(key);
        assertEquals(3, .gets());
        assertEquals(2, .misses());
        .get(key);
        assertEquals(4, .gets());
        assertEquals(2, .misses());
    }
New to GrepCode? Check out our FAQ X