PrecomputedJoinUpdaterSupplier implements Supplier<PrecomputedJoinUpdater> { @Override public PrecomputedJoinUpdater get() { final Configuration config = configSupplier.get(); checkNotNull(config, "Can not build the PrecomputedJoinUpdater until the PrecomputedJoinIndexer has been configured."); final PrecomputedJoinIndexerConfig indexerConfig = new PrecomputedJoinIndexerConfig(config); final Optional<PrecomputedJoinUpdaterType> updaterType = indexerConfig.getPcjUpdaterType(); checkArgument(updaterType.isPresent(), "The '" + PrecomputedJoinIndexerConfig.PCJ_UPDATER_TYPE + "' property must have one of the following values: " + PrecomputedJoinUpdaterType.values()); switch(updaterType.get()) { case FLUO: return fluoSupplier.get(); default: throw new IllegalArgumentException("Unsupported PrecomputedJoinUpdaterType: " + updaterType.get()); } } PrecomputedJoinUpdaterSupplier(
            final Supplier<Configuration> configSupplier,
            final FluoPcjUpdaterSupplier fluoSupplier); @Override PrecomputedJoinUpdater get();  }
@Test(expected = NullPointerException.class) public void notConfigured() { final Supplier<Configuration> configSupplier = mock(Supplier.class); final PrecomputedJoinUpdaterSupplier updaterSupplier = new PrecomputedJoinUpdaterSupplier(configSupplier, mock(FluoPcjUpdaterSupplier.class)); updaterSupplier.get(); }
@Test(expected = IllegalArgumentException.class) public void updaterTypeNotSet() { final Supplier<Configuration> configSupplier = mock(Supplier.class); when(configSupplier.get()).thenReturn( new Configuration() ); final PrecomputedJoinUpdaterSupplier updaterSupplier = new PrecomputedJoinUpdaterSupplier(configSupplier, mock(FluoPcjUpdaterSupplier.class)); updaterSupplier.get(); }
@Test public void configuredForFluo() { final Supplier<Configuration> configSupplier = mock(Supplier.class); final Configuration config = new Configuration(); config.set(PrecomputedJoinIndexerConfig.PCJ_UPDATER_TYPE, PrecomputedJoinUpdaterType.FLUO.toString()); when(configSupplier.get()).thenReturn( config ); final FluoPcjUpdaterSupplier fluoSupplier = mock(FluoPcjUpdaterSupplier.class); final FluoPcjUpdater mockFluoUpdater = mock(FluoPcjUpdater.class); when(fluoSupplier.get()).thenReturn(mockFluoUpdater); final PrecomputedJoinUpdaterSupplier updaterSupplier = new PrecomputedJoinUpdaterSupplier(configSupplier, fluoSupplier); final PrecomputedJoinUpdater updater = updaterSupplier.get(); assertEquals(mockFluoUpdater, updater); }