OSGIObjectFactory implements IPentahoObjectFactory { @Override public <T> List<T> getAll( Class<T> interfaceClass, IPentahoSession curSession ) throws ObjectFactoryException { return getAll( interfaceClass, curSession, Collections.<String, String>emptyMap() ); } 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 testGetAll() throws Exception { ServiceReference<String> ref = Mockito.mock( ServiceReference.class ); ServiceReference<String> ref2 = Mockito.mock( ServiceReference.class ); when( mockContext.getServiceReferences( String.class, null ) ).thenReturn( Arrays.asList( ref, ref2 ) ); when( mockContext.getServiceReferences( Integer.class, null ) ) .thenThrow( new InvalidSyntaxException( "bad", "call" ) ); when( mockContext.getService( ref ) ).thenReturn( "SomeString" ); when( mockContext.getService( ref2 ) ).thenReturn( "SomeString2" ); List<String> actual = factory.getAll( String.class, session ); assertEquals( 2, actual.size() ); assertEquals( "SomeString", actual.get( 0 ) ); assertEquals( "SomeString2", actual.get( 1 ) ); verify( mockContext ).getServiceReferences( String.class, null ); List<Integer> madInts = factory.getAll( Integer.class, session ); assertNotNull( madInts ); assertEquals( 0, madInts.size() ); List<Float> emptyFloats = factory.getAll( Float.class, session ); assertNotNull( emptyFloats ); assertEquals( 0, emptyFloats.size() ); }