You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@sling.apache.org by "Stefan Seifert (JIRA)" <ji...@apache.org> on 2015/10/02 00:01:26 UTC

[jira] [Resolved] (SLING-5086) sling-mock: Add SlingContext.registerAdapter convenience method

     [ https://issues.apache.org/jira/browse/SLING-5086?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Stefan Seifert resolved SLING-5086.
-----------------------------------
    Resolution: Fixed

Completed: At revision: 1706325  


> sling-mock: Add SlingContext.registerAdapter convenience method
> ---------------------------------------------------------------
>
>                 Key: SLING-5086
>                 URL: https://issues.apache.org/jira/browse/SLING-5086
>             Project: Sling
>          Issue Type: New Feature
>          Components: Testing
>            Reporter: Stefan Seifert
>            Assignee: Stefan Seifert
>              Labels: mocks
>             Fix For: Testing Sling Mock 1.6.0
>
>
> scenario: adapt from an object in your unit test where no existing adapterfactory is available. currently you have to create a AdapterFactory instance and register it with proper OSGi properties in OSGi.
> two convenience methods simplify this by allowing to trim it down to one codeline:
> {code:java}
>     /**
>      * Create a Sling AdapterFactory on the fly which can adapt from <code>adaptableClass</code>
>      * to <code>adapterClass</code> and just returns the given value as result.
>      * @param adaptableClass Class to adapt from
>      * @param adapterClass Class to adapt to
>      * @param adapter Object which is always returned for this adaption.
>      */
>     public <T1, T2> void registerAdapter(final Class<T1> adaptableClass, final Class<T2> adapterClass, final T2 adapter) {
> ...
> {code}
> {code:java}
>     /**
>      * Create a Sling AdapterFactory on the fly which can adapt from <code>adaptableClass</code>
>      * to <code>adapterClass</code> and delegates the adapter mapping to the given <code>adaptHandler</code> function.
>      * @param adaptableClass Class to adapt from
>      * @param adapterClass Class to adapt to
>      * @param adaptHandler Function to handle the adaption
>      */
>     public <T1, T2> void registerAdapter(final Class<T1> adaptableClass, final Class<T2> adapterClass, final Function<T1,T2> adaptHandler) {
> ...
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)