/*
 * Copyright (c) 2023 looly(loolly@aliyun.com)
 * Hutool is licensed under Mulan PSL v2.
 * You can use this software according to the terms and conditions of the Mulan PSL v2.
 * You may obtain a copy of Mulan PSL v2 at:
 *          https://license.coscl.org.cn/MulanPSL2
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the Mulan PSL v2 for more details.
 */

package org.dromara.hutool.core.reflect;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import java.lang.reflect.Type;
import java.util.Map;

/**
 * 见：<a href="https://gitee.com/dromara/hutool/pulls/447/files">https://gitee.com/dromara/hutool/pulls/447/files</a>
 * <p>
 * TODO 同时继承泛型和实现泛型接口需要解析，此处为F
 */
public class ActualTypeMapperPoolTest {

	@Test
	public void getTypeArgumentTest(){
		final Map<Type, Type> typeTypeMap = ActualTypeMapperPool.get(FinalClass.class);
		typeTypeMap.forEach((key, value)->{
			if("A".equals(key.getTypeName())){
				Assertions.assertEquals(Character.class, value);
			} else if("B".equals(key.getTypeName())){
				Assertions.assertEquals(Boolean.class, value);
			} else if("C".equals(key.getTypeName())){
				Assertions.assertEquals(String.class, value);
			} else if("D".equals(key.getTypeName())){
				Assertions.assertEquals(Double.class, value);
			} else if("E".equals(key.getTypeName())){
				Assertions.assertEquals(Integer.class, value);
			}
		});
	}

	@Test
	public void getTypeArgumentStrKeyTest(){
		final Map<String, Type> typeTypeMap = ActualTypeMapperPool.getStrKeyMap(FinalClass.class);
		typeTypeMap.forEach((key, value)->{
			if("A".equals(key)){
				Assertions.assertEquals(Character.class, value);
			} else if("B".equals(key)){
				Assertions.assertEquals(Boolean.class, value);
			} else if("C".equals(key)){
				Assertions.assertEquals(String.class, value);
			} else if("D".equals(key)){
				Assertions.assertEquals(Double.class, value);
			} else if("E".equals(key)){
				Assertions.assertEquals(Integer.class, value);
			}
		});
	}

	public interface BaseInterface<A, B, C> {}
	public interface FirstInterface<A, B, D, E> extends BaseInterface<A, B, String> {}
	public interface SecondInterface<A, B, F> extends BaseInterface<A, B, String> {}

	public static class BaseClass<A, D> implements FirstInterface<A, Boolean, D, Integer> {}
	public static class FirstClass extends BaseClass<Character, Double> implements SecondInterface<Character, Boolean, FirstClass> {}
	public static class SecondClass extends FirstClass {}
	public static class FinalClass extends SecondClass {}
}
