OSGIObjectFactory implements IPentahoObjectFactory { public <T> T get( Class<T> tClass, IPentahoSession session ) throws ObjectFactoryException { return get( tClass, null, session ); } OSGIObjectFactory( final BundleContext context ); T get( Class<T> tClass, IPentahoSession session ); @Override T get( Class<T> interfaceClass, String key, IPentahoSession session ); @Override T get( Class<T> interfaceClass, IPentahoSession session, Map<String, String> properties ); @Override boolean objectDefined( String clazz ); @Override boolean objectDefined( Class<?> clazz ); @Override Class<?> getImplementingClass( String key ); @Override void init( String configFile, Object context ); @Override List<T> getAll( Class<T> interfaceClass, IPentahoSession curSession ); @Override List<T> getAll( Class<T> interfaceClass, IPentahoSession session, Map<String, String> properties ); @Override IPentahoObjectReference<T> getObjectReference( Class<T> interfaceClass, IPentahoSession curSession ); @Override IPentahoObjectReference<T> getObjectReference( Class<T> interfaceClass, IPentahoSession curSession,
                                                            Map<String, String> properties ); @Override List<IPentahoObjectReference<T>> getObjectReferences( Class<T> interfaceClass, IPentahoSession curSession ); @Override List<IPentahoObjectReference<T>> getObjectReferences( Class<T> interfaceClass, IPentahoSession curSession,
                                                                   Map<String, String> properties ); @Override String getName(); static final String REFERENCE_CLASS; }
@Test public void testGet() throws Exception { ServiceReference<String> ref = Mockito.mock( ServiceReference.class ); when( mockContext.getServiceReferences( String.class, null ) ).thenReturn( Collections.singletonList( ref ) ); when( mockContext.getService( ref ) ).thenReturn( "SomeString" ); when( mockContext.getServiceReferences( java.lang.Integer.class, null ) ) .thenThrow( new InvalidSyntaxException( "bad", "call" ) ); String actual = factory.get( String.class, session ); Integer missing = factory.get( Integer.class, session ); assertEquals( "SomeString", actual ); assertNull( missing ); Float missing2 = factory.get( Float.class, session ); assertNull( missing2 ); verify( mockContext ).getServiceReferences( String.class, null ); }