Stefan Seifert created SLING-5086:
-------------------------------------
Summary: 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
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)