/*
 * Licensed 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 io.trino.plugin.base.classloader;

import com.google.common.collect.ImmutableSet;
import io.trino.spi.connector.ConnectorAccessControl;
import io.trino.spi.connector.ConnectorMetadata;
import io.trino.spi.connector.ConnectorNodePartitioningProvider;
import io.trino.spi.connector.ConnectorPageSink;
import io.trino.spi.connector.ConnectorPageSinkProvider;
import io.trino.spi.connector.ConnectorPageSourceProvider;
import io.trino.spi.connector.ConnectorRecordSetProvider;
import io.trino.spi.connector.ConnectorSecurityContext;
import io.trino.spi.connector.ConnectorSplitManager;
import io.trino.spi.connector.ConnectorSplitSource;
import io.trino.spi.connector.RecordSet;
import io.trino.spi.connector.SchemaTableName;
import io.trino.spi.connector.SystemTable;
import io.trino.spi.eventlistener.EventListener;
import io.trino.spi.ptf.ConnectorTableFunction;
import io.trino.spi.type.Type;
import org.testng.annotations.Test;

import static io.trino.spi.testing.InterfaceTestUtils.assertAllMethodsOverridden;

public class TestClassLoaderSafeWrappers
{
    @Test
    public void testAllMethodsOverridden()
            throws NoSuchMethodException
    {
        assertAllMethodsOverridden(ConnectorAccessControl.class, ClassLoaderSafeConnectorAccessControl.class, ImmutableSet.of(
                ClassLoaderSafeConnectorAccessControl.class.getMethod("getRowFilter", ConnectorSecurityContext.class, SchemaTableName.class),
                ClassLoaderSafeConnectorAccessControl.class.getMethod("getColumnMask", ConnectorSecurityContext.class, SchemaTableName.class, String.class, Type.class)));
        assertAllMethodsOverridden(ConnectorMetadata.class, ClassLoaderSafeConnectorMetadata.class);
        assertAllMethodsOverridden(ConnectorPageSink.class, ClassLoaderSafeConnectorPageSink.class);
        assertAllMethodsOverridden(ConnectorPageSinkProvider.class, ClassLoaderSafeConnectorPageSinkProvider.class);
        assertAllMethodsOverridden(ConnectorPageSourceProvider.class, ClassLoaderSafeConnectorPageSourceProvider.class);
        assertAllMethodsOverridden(ConnectorSplitManager.class, ClassLoaderSafeConnectorSplitManager.class);
        assertAllMethodsOverridden(ConnectorNodePartitioningProvider.class, ClassLoaderSafeNodePartitioningProvider.class);
        assertAllMethodsOverridden(ConnectorSplitSource.class, ClassLoaderSafeConnectorSplitSource.class);
        assertAllMethodsOverridden(SystemTable.class, ClassLoaderSafeSystemTable.class);
        assertAllMethodsOverridden(ConnectorRecordSetProvider.class, ClassLoaderSafeConnectorRecordSetProvider.class);
        assertAllMethodsOverridden(RecordSet.class, ClassLoaderSafeRecordSet.class);
        assertAllMethodsOverridden(EventListener.class, ClassLoaderSafeEventListener.class);
        assertAllMethodsOverridden(ConnectorTableFunction.class, ClassLoaderSafeConnectorTableFunction.class);
    }
}

@@ -1493,16 +1493,72 @@
 .Test;%0A%0A
+import java.lang.reflect.Method;%0Aimport java.util.Set;%0A%0A
 import s
@@ -1631,16 +1631,16 @@
 ridden;%0A
-
 %0Apublic 
@@ -1705,36 +1705,16 @@
 oid test
-AllMethodsOverridden
 ()%0A     
@@ -1767,34 +1767,27 @@
     
-assertAllMethodsOverridden
+testClassLoaderSafe
 (Con
@@ -2200,34 +2200,27 @@
     
-assertAllMethodsOverridden
+testClassLoaderSafe
 (Con
@@ -2294,34 +2294,27 @@
     
-assertAllMethodsOverridden
+testClassLoaderSafe
 (Con
@@ -2388,34 +2388,27 @@
     
-assertAllMethodsOverridden
+testClassLoaderSafe
 (Con
@@ -2498,34 +2498,27 @@
     
-assertAllMethodsOverridden
+testClassLoaderSafe
 (Con
@@ -2612,34 +2612,27 @@
     
-assertAllMethodsOverridden
+testClassLoaderSafe
 (Con
@@ -2714,34 +2714,27 @@
     
-assertAllMethodsOverridden
+testClassLoaderSafe
 (Con
@@ -2831,34 +2831,27 @@
     
-assertAllMethodsOverridden
+testClassLoaderSafe
 (Con
@@ -2931,34 +2931,27 @@
     
-assertAllMethodsOverridden
+testClassLoaderSafe
 (Sys
@@ -3013,34 +3013,27 @@
     
-assertAllMethodsOverridden
+testClassLoaderSafe
 (Con
@@ -3125,34 +3125,27 @@
     
-assertAllMethodsOverridden
+testClassLoaderSafe
 (Rec
@@ -3203,34 +3203,27 @@
     
-assertAllMethodsOverridden
+testClassLoaderSafe
 (Eve
@@ -3289,34 +3289,27 @@
     
-assertAllMethodsOverridden
+testClassLoaderSafe
 (Con
@@ -3386,11 +3386,362 @@
 );%0A    %7D
+%0A%0A    private static %3CI, C extends I%3E void testClassLoaderSafe(Class%3CI%3E iface, Class%3CC%3E clazz)%0A    %7B%0A        testClassLoaderSafe(iface, clazz, Set.of());%0A    %7D%0A%0A    private static %3CI, C extends I%3E void testClassLoaderSafe(Class%3CI%3E iface, Class%3CC%3E clazz, Set%3CMethod%3E exclusions)%0A    %7B%0A        assertAllMethodsOverridden(iface, clazz, exclusions);%0A    %7D
 %0A%7D%0A

Refactor TestClassLoaderSafeWrappers