use of org.apache.sling.api.adapter.AdapterFactory in project sling by apache.
the class SlingContextTest method prepareInitialAdapterFactory.
private void prepareInitialAdapterFactory() {
// register "traditional" adapter factory without specific service ranking
AdapterFactory adapterFactory = new AdapterFactory() {
@SuppressWarnings("unchecked")
@Override
public <AdapterType> AdapterType getAdapter(Object adaptable, Class<AdapterType> type) {
return (AdapterType) (((TestAdaptable) adaptable).getMessage() + "-initial");
}
};
context.registerService(AdapterFactory.class, adapterFactory, ImmutableMap.<String, Object>builder().put(AdapterFactory.ADAPTABLE_CLASSES, new String[] { TestAdaptable.class.getName() }).put(AdapterFactory.ADAPTER_CLASSES, new String[] { String.class.getName() }).build());
// test initial adapter factory
assertEquals("testMessage1-initial", new TestAdaptable("testMessage1").adaptTo(String.class));
}
Aggregations