formatted code in LRUCacheTest.java
[appc.git] / appc-core / appc-common-bundle / src / test / java / org / onap / appc / cache / impl / LRUCacheTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP : APPC
4  * ================================================================================
5  * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Copyright (C) 2017 Amdocs
8  * =============================================================================
9  * Modifications Copyright (C) 2018 IBM.
10  * =============================================================================
11  * Licensed under the Apache License, Version 2.0 (the "License");
12  * you may not use this file except in compliance with the License.
13  * You may obtain a copy of the License at
14  * 
15  *      http://www.apache.org/licenses/LICENSE-2.0
16  * 
17  * Unless required by applicable law or agreed to in writing, software
18  * distributed under the License is distributed on an "AS IS" BASIS,
19  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20  * See the License for the specific language governing permissions and
21  * limitations under the License.
22  * 
23  * ============LICENSE_END=========================================================
24  */
25
26 package org.onap.appc.cache.impl;
27
28 import java.util.Map;
29
30 import org.junit.Assert;
31 import org.junit.Before;
32 import org.junit.Test;
33 import org.powermock.reflect.Whitebox;
34
35 public class LRUCacheTest {
36
37     private LRUCache cache;
38
39     @Before
40     public void setUp() {
41         cache = new LRUCache(20);
42     }
43
44     @Test
45     public void testConstructor() throws Exception {
46         Map internalMap = Whitebox.getInternalState(cache, "map");
47         Assert.assertTrue(internalMap != null);
48         Assert.assertTrue(internalMap.size() == 0);
49     }
50
51     @Test
52     public void testGetAndPutObject() throws Exception {
53         String key = "testing key";
54         Assert.assertTrue(cache.getObject(key) == null);
55
56         String value = "testing value";
57         cache.putObject(key, value);
58         Map internalMap = Whitebox.getInternalState(cache, "map");
59         Assert.assertTrue(internalMap.containsKey(key));
60         Assert.assertTrue(internalMap.containsValue(value));
61         Assert.assertTrue(internalMap.size() == 1);
62
63         Assert.assertEquals(value, cache.getObject(key));
64     }
65
66 }