View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      https://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.commons.pool2.impl;
18  
19  import static org.junit.jupiter.api.Assertions.assertEquals;
20  import static org.junit.jupiter.api.Assertions.assertFalse;
21  
22  import java.time.Duration;
23  
24  import org.junit.jupiter.api.Test;
25  
26  /**
27   * Tests for {@link EvictionConfig}.
28   */
29  class TestEvictionConfig {
30  
31      @Test
32      void testConstructor1s() {
33          final EvictionConfig config = new EvictionConfig(Duration.ofMillis(1), Duration.ofMillis(1), 1);
34          assertEquals(1, config.getIdleEvictDuration().toMillis());
35          assertEquals(1, config.getIdleEvictTime());
36          assertEquals(1, config.getIdleEvictTimeDuration().toMillis());
37          assertEquals(1, config.getIdleSoftEvictDuration().toMillis());
38          assertEquals(1, config.getIdleSoftEvictTime());
39          assertEquals(1, config.getIdleSoftEvictTimeDuration().toMillis());
40          assertEquals(1, config.getMinIdle());
41          // toString() should never throw
42          assertFalse(config.toString().isEmpty());
43      }
44  
45      @Test
46      void testConstructorZerosDurations() {
47          final EvictionConfig config = new EvictionConfig(Duration.ZERO, Duration.ZERO, 0);
48          assertEquals(Long.MAX_VALUE, config.getIdleEvictDuration().toMillis());
49          assertEquals(Long.MAX_VALUE, config.getIdleEvictTime());
50          assertEquals(Long.MAX_VALUE, config.getIdleEvictTimeDuration().toMillis());
51          assertEquals(Long.MAX_VALUE, config.getIdleSoftEvictDuration().toMillis());
52          assertEquals(Long.MAX_VALUE, config.getIdleSoftEvictTime());
53          assertEquals(Long.MAX_VALUE, config.getIdleSoftEvictTimeDuration().toMillis());
54          assertEquals(0, config.getMinIdle());
55          // toString() should never throw
56          assertFalse(config.toString().isEmpty());
57      }
58  
59      @Test
60      void testConstructorZerosMillis() {
61          @SuppressWarnings("deprecation")
62          final EvictionConfig config = new EvictionConfig(0, 0, 0);
63          assertEquals(Long.MAX_VALUE, config.getIdleEvictDuration().toMillis());
64          assertEquals(Long.MAX_VALUE, config.getIdleEvictTime());
65          assertEquals(Long.MAX_VALUE, config.getIdleEvictTimeDuration().toMillis());
66          assertEquals(Long.MAX_VALUE, config.getIdleSoftEvictDuration().toMillis());
67          assertEquals(Long.MAX_VALUE, config.getIdleSoftEvictTime());
68          assertEquals(Long.MAX_VALUE, config.getIdleSoftEvictTimeDuration().toMillis());
69          assertEquals(0, config.getMinIdle());
70          // toString() should never throw
71          assertFalse(config.toString().isEmpty());
72      }
73  
74  }