public final void registerAdapter()

in core/src/main/java/org/apache/sling/testing/mock/sling/context/SlingContextImpl.java [600:619]


    public final <T1, T2> void registerAdapter(
            @NotNull final Class<T1> adaptableClass,
            @NotNull final Class<T2> adapterClass,
            @NotNull final Function<T1, T2> adaptHandler) {
        AdapterFactory adapterFactory = new AdapterFactory() {
            @SuppressWarnings("unchecked")
            @Override
            public <AdapterType> AdapterType getAdapter(@NotNull Object adaptable, @NotNull Class<AdapterType> type) {
                return (AdapterType) adaptHandler.apply((T1) adaptable);
            }
        };
        Map<String, Object> props = new HashMap<>();
        props.put(AdapterFactory.ADAPTABLE_CLASSES, new String[] {adaptableClass.getName()});
        props.put(AdapterFactory.ADAPTER_CLASSES, new String[] {adapterClass.getName()});
        // make sure this overlay has higher ranking than other adapter factories
        // normally we should use Integer.MAX_VALUE for this - but due to SLING-7194 prefers lowest-ranking services
        // first
        props.put(Constants.SERVICE_RANKING, Integer.MIN_VALUE);
        registerService(AdapterFactory.class, adapterFactory, props);
    }