DataServiceMetaObjectFactory implements IMetaStoreObjectFactory { @Override public Object instantiateClass( final String className, Map<String, String> objectContext ) throws MetaStoreException { for ( PushDownFactory factory : factories ) { if ( factory.getType().getName().equals( className ) ) { return factory.createPushDown(); } } try { return Class.forName( className ).newInstance(); } catch ( Throwable t ) { Throwables.propagateIfPossible( t, MetaStoreException.class ); throw new MetaStoreException( t ); } } DataServiceMetaObjectFactory( List<PushDownFactory> factories ); @Override Object instantiateClass( final String className, Map<String, String> objectContext ); @Override Map<String, String> getContext( Object pluginObject );  }
@Test public void testInstantiateNoFactories() throws MetaStoreException { objectFactory = new DataServiceMetaObjectFactory( Collections.emptyList() ); assertThat( objectFactory.instantiateClass( "java.lang.String", Collections.emptyMap() ), instanceOf( String.class ) ); }
@Test public void testMatchingPushdownFactory() throws MetaStoreException { initObjectFactory(); objectFactory.instantiateClass( ServiceCache.class.getName(), Collections.emptyMap() ); verify( pushDownFactory, times( 1 ) ).createPushDown(); }
@Test public void testNonMatchingPushdownFactory() throws MetaStoreException { initObjectFactory(); try { objectFactory.instantiateClass( "some.nonexistent.class", Collections.emptyMap() ); } catch ( Exception e ) { assertThat( e, instanceOf( MetaStoreException.class ) ); } }