### Question:
LRUCache extends LinkedHashMap<K, V> { public int getMaxSize() { return maxSize; } LRUCache(int maxSize); int getMaxSize();  }### Answer:
@Test public void testLRUCachePut() { LRUCache<String, Integer> cache = new LRUCache<String, Integer>(5); assertThat(cache.getMaxSize(), is(5)); cache.put("1", 1); cache.put("2", 2); cache.put("3", 3); cache.put("4", 4); cache.put("5", 5); assertThat(cache.size(), is(5)); cache.put("6", 6); assertThat(cache.size(), is(5)); assertNull(cache.get("1")); assertThat(cache.getMaxSize(), is(5)); }
@Test public void testLRUCachePutGet() { LRUCache<String, Integer> cache = new LRUCache<String, Integer>(5); assertThat(cache.getMaxSize(), is(5)); cache.put("1", 1); cache.put("2", 2); cache.put("3", 3); cache.put("4", 4); cache.put("5", 5); assertThat(cache.size(), is(5)); assertThat(cache.get("1"), is(1)); cache.put("6", 6); assertThat(cache.size(), is(5)); assertNull(cache.get("2")); assertThat(cache.get("1"), is(1)); assertThat(cache.getMaxSize(), is(5)); }
@Test public void testLRUCachePutGet2() { LRUCache<String, Integer> cache = new LRUCache<String, Integer>(5); assertThat(cache.getMaxSize(), is(5)); cache.put("1", 1); cache.put("2", 2); cache.put("3", 3); cache.put("4", 4); cache.put("5", 5); assertThat(cache.size(), is(5)); assertThat(cache.get("2"), is(2)); assertThat(cache.get("1"), is(1)); cache.put("6", 6); assertThat(cache.size(), is(5)); assertNull(cache.get("3")); assertThat(cache.get("2"), is(2)); assertThat(cache.get("1"), is(1)); assertThat(cache.getMaxSize(), is(5)); }
@Test public void testLRUCachePutGet3() { LRUCache<String, Integer> cache = new LRUCache<String, Integer>(5); assertThat(cache.getMaxSize(), is(5)); cache.put("1", 1); cache.put("2", 2); cache.put("3", 3); cache.put("4", 4); cache.put("5", 5); assertThat(cache.size(), is(5)); cache.put("6", 6); cache.put("7", 7); cache.put("8", 8); cache.put("9", 9); cache.put("10", 10); assertNull(cache.get("1")); assertNull(cache.get("2")); assertNull(cache.get("3")); assertNull(cache.get("4")); assertNull(cache.get("5")); cache.remove("10"); assertThat(cache.size(), is(4)); assertThat(cache.getMaxSize(), is(5)); }
@Test public void testLRUCachePutGet4() { LRUCache<String, Integer> cache = new LRUCache<String, Integer>(1); assertThat(cache.size(), is(0)); cache.put("1", 1); assertThat(cache.get("1"), is(1)); cache.put("2", 2); assertThat(cache.size(), is(1)); assertNull(cache.get("1")); assertThat(cache.get("2"), is(2)); assertThat(cache.getMaxSize(), is(1)); }