import java.lang.reflect.Type;
import java.util.List;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

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

class RecordParameterTest {
    public static List<String> fieldWithExpectedType;
    public static Type expected;

    @BeforeAll
    static void determineExpectedType() throws NoSuchFieldException {
        expected = RecordParameterTest.class.getField("fieldWithExpectedType").getGenericType();
    }

    record ImplicitConstructor(List<String> arg){}

    record CompactConstructor(List<String> arg) {
        CompactConstructor { }
    }

    record CanonicalConstructor(List<String> arg) {
        CanonicalConstructor(List<String> arg) {
            this.arg = arg;
        }
    }

    @Test
    void implicit() {
        assertEquals(expected, firstConstructorParameterType(ImplicitConstructor.class));
    }

    @Test
    void compact() {
        assertEquals(expected, firstConstructorParameterType(CompactConstructor.class));
    }

    @Test
    void canonical() {
        assertEquals(expected, firstConstructorParameterType(CanonicalConstructor.class));
    }

    static Type firstConstructorParameterType(Class<?> c) {
        return c.getDeclaredConstructors()[0].getParameters()[0].getParameterizedType();
    }
}
