/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You 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 org.apache.commons.pool2.impl;

import static org.junit.jupiter.api.Assertions.assertEquals;

import java.time.Instant;

import org.apache.commons.pool2.BasePooledObjectFactory;
import org.apache.commons.pool2.PooledObject;
import org.junit.jupiter.api.Test;

public class TestPoolImplUtils {

    @SuppressWarnings("unused")
    private abstract static class FactoryAB<A, B> extends BasePooledObjectFactory<B> {
        // empty by design
    }

    private abstract static class FactoryBA<A, B> extends FactoryAB<B, A> {
        // empty by design
    }

    private abstract static class FactoryC<C> extends FactoryBA<C, String> {
        // empty by design
    }

    @SuppressWarnings("unused")
    private abstract static class FactoryDE<D, E> extends FactoryC<D> {
        // empty by design
    }

    private abstract static class FactoryF<F> extends FactoryDE<Long, F> {
        // empty by design
    }

    private static class NotSimpleFactory extends FactoryF<Integer> {
        @Override
        public Long create() throws Exception {
            return null;
        }

        @Override
        public PooledObject<Long> wrap(final Long obj) {
            return null;
        }
    }

    private static class SimpleFactory extends BasePooledObjectFactory<String> {
        @Override
        public String create() throws Exception {
            return null;
        }

        @Override
        public PooledObject<String> wrap(final String obj) {
            return null;
        }
    }

    @Test
    public void testFactoryTypeNotSimple() {
        final Class<?> result = PoolImplUtils.getFactoryType(NotSimpleFactory.class);
        assertEquals(Long.class, result);
    }

    @Test
    public void testFactoryTypeSimple() {
        final Class<?> result = PoolImplUtils.getFactoryType(SimpleFactory.class);
        assertEquals(String.class, result);
    }

    @Test
    public void testMaxInstants() {
        final Instant instant0 = Instant.ofEpochMilli(0);
        final Instant instant1 = Instant.ofEpochMilli(1);
        assertEquals(instant1, PoolImplUtils.max(instant0, instant1));
        assertEquals(instant1, PoolImplUtils.max(instant1, instant0));
        assertEquals(instant1, PoolImplUtils.max(instant1, instant1));
        assertEquals(instant0, PoolImplUtils.max(instant0, instant0));
    }

    @Test
    public void testMinInstants() {
        final Instant instant0 = Instant.ofEpochMilli(0);
        final Instant instant1 = Instant.ofEpochMilli(1);
        assertEquals(instant0, PoolImplUtils.min(instant0, instant1));
        assertEquals(instant0, PoolImplUtils.min(instant1, instant0));
        assertEquals(instant1, PoolImplUtils.min(instant1, instant1));
        assertEquals(instant0, PoolImplUtils.min(instant0, instant0));
    }
}

@@ -1098,16 +1098,157 @@
 tils %7B%0A%0A
+    private static final Instant INSTANT_1 = Instant.ofEpochMilli(1);%0A    private static final Instant INSTANT_0 = Instant.ofEpochMilli(0);%0A%0A
     @Sup
@@ -2881,124 +2881,8 @@
 ) %7B%0A
-        final Instant instant0 = Instant.ofEpochMilli(0);%0A        final Instant instant1 = Instant.ofEpochMilli(1);%0A
     
@@ -2890,39 +2890,40 @@
    assertEquals(
-instant
+INSTANT_
 1, PoolImplUtils
@@ -2927,33 +2927,35 @@
 ils.max(
-instant0, instant
+INSTANT_0, INSTANT_
 1));%0A   
@@ -2964,39 +2964,40 @@
    assertEquals(
-instant
+INSTANT_
 1, PoolImplUtils
@@ -3001,33 +3001,35 @@
 ils.max(
-instant1, instant
+INSTANT_1, INSTANT_
 0));%0A   
@@ -3038,39 +3038,40 @@
    assertEquals(
-instant
+INSTANT_
 1, PoolImplUtils
@@ -3075,33 +3075,35 @@
 ils.max(
-instant1, instant
+INSTANT_1, INSTANT_
 1));%0A   
@@ -3112,39 +3112,40 @@
    assertEquals(
-instant
+INSTANT_
 0, PoolImplUtils
@@ -3149,33 +3149,35 @@
 ils.max(
-instant0, instant
+INSTANT_0, INSTANT_
 0));%0A   
@@ -3230,124 +3230,8 @@
 ) %7B%0A
-        final Instant instant0 = Instant.ofEpochMilli(0);%0A        final Instant instant1 = Instant.ofEpochMilli(1);%0A
     
@@ -3239,39 +3239,40 @@
    assertEquals(
-instant
+INSTANT_
 0, PoolImplUtils
@@ -3276,33 +3276,35 @@
 ils.min(
-instant0, instant
+INSTANT_0, INSTANT_
 1));%0A   
@@ -3313,39 +3313,40 @@
    assertEquals(
-instant
+INSTANT_
 0, PoolImplUtils
@@ -3350,33 +3350,35 @@
 ils.min(
-instant1, instant
+INSTANT_1, INSTANT_
 0));%0A   
@@ -3395,23 +3395,24 @@
 tEquals(
-instant
+INSTANT_
 1, PoolI
@@ -3428,25 +3428,27 @@
 min(
-instant1, instant
+INSTANT_1, INSTANT_
 1));
@@ -3469,23 +3469,24 @@
 tEquals(
-instant
+INSTANT_
 0, PoolI
@@ -3502,25 +3502,27 @@
 min(
-instant0, instant
+INSTANT_0, INSTANT_
 0));

Refactor test constants.