The current AdapterManagerImpl makes it hard to be used within junit
tests if you need an adapter factory during your tests.
You need to know the internals of the implementation just to register
your adapter factory.

I suggested in the bug to simply make the static INSTANCE field of the
AdapterManagerImpl public - while I'm not that happy with the solution I
think it's a pragmatic way to solve the problem. Making this public is
no problem in an OSGI environment as the whole class is still private.
For junit tests one can simply set this public field to a mock adapter
factory implementation to make an own adapter factory available.
This avoids to know any internals of the adapter manager implementation.

By this we create a simple contract for use cases like unit tests: the
INSTANCE field is usable in these cases without opening up the
implementation details.

WDYT?

Carsten


Carsten Ziegeler (JIRA) wrote:
>     [ 
> https://issues.apache.org/jira/browse/SLING-1195?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12795565#action_12795565
>  ] 
> 
> Carsten Ziegeler commented on SLING-1195:
> -----------------------------------------
> 
> I think the easiest way would be to make the INSTANCE field in the 
> AdapterManagerImpl public - this causes no problems in an OSGi environment as 
> the whole class is private.
> Within a junit test one can simple set an own AdapterManager through the 
> static field without knowing any implemetation details of the adapter manager 
> implementation.
> 
>> Make AdapterManager implementation somehow accessible for junit tests
>> ---------------------------------------------------------------------
>>
>>                 Key: SLING-1195
>>                 URL: https://issues.apache.org/jira/browse/SLING-1195
>>             Project: Sling
>>          Issue Type: Improvement
>>          Components: Extensions
>>    Affects Versions: Adapter 2.0.4
>>            Reporter: Carsten Ziegeler
>>             Fix For: Adapter 2.0.6
>>
>>
>> The SlingAdaptable directly uses the internal AdapterManagerImpl class to 
>> get adapter factories. This works fine in an OSGi context.
>> Using a SlingAdaptable within a junit test is harder, especially if one 
>> wants to use an adapter factory. This requires manual instantiation of the 
>> adaptermanager impl and some reflection tricks etc. to get the factory 
>> registered.
>> We should find a better way which makes writing junit tests easier.
> 


-- 
Carsten Ziegeler
[email protected]

Reply via email to