2 * ============LICENSE_START====================================================
\r
4 * ===========================================================================
\r
5 * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
\r
6 * ===========================================================================
\r
7 * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * you may not use this file except in compliance with the License.
\r
9 * You may obtain a copy of the License at
\r
11 * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * Unless required by applicable law or agreed to in writing, software
\r
14 * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * See the License for the specific language governing permissions and
\r
17 * limitations under the License.
\r
18 * ============LICENSE_END====================================================
\r
21 package org.onap.aaf.misc.env.util.test;
\r
23 import static org.junit.Assert.assertEquals;
\r
25 import org.junit.Before;
\r
26 import org.junit.Test;
\r
27 import org.onap.aaf.misc.env.APIException;
\r
28 import org.onap.aaf.misc.env.LogTarget;
\r
29 import org.onap.aaf.misc.env.util.Pool;
\r
31 public class JU_PoolTest {
\r
34 public void setUp() throws Exception {
\r
38 public void test() {
\r
39 Pool pool = new Pool<Integer>(new Pool.Creator<Integer>() {
\r
41 Integer content = 0;
\r
44 public Integer create() throws APIException {
\r
49 public void destroy(Integer t) {
\r
54 public boolean isValid(Integer t) {
\r
55 return t == content;
\r
59 public void reuse(Integer t) {
\r
65 assertEquals("Should return intial value", 0, pool.get().content);
\r
67 pool.prime(LogTarget.SYSOUT, 23);
\r
68 assertEquals("Should Return 23 as added at last prime", 23, pool.get(LogTarget.SYSOUT).content);
\r
69 pool.prime(LogTarget.SYSERR, 13);
\r
70 assertEquals("Should add another 13 from SysErr and remove 1", 35, pool.get(LogTarget.SYSERR).content);
\r
71 assertEquals("Create a new creator with create method", 1, pool.get().content);
\r
72 assertEquals("Create a new creator with create method", 2, pool.get().content);
\r
73 assertEquals("Should remove last from pool", 34, pool.get(LogTarget.SYSOUT).content);
\r
76 assertEquals("Should remove last from pool", 17, pool.get(LogTarget.SYSOUT).content);
\r
77 } catch (APIException e) {
\r