PushDownOptimizationMeta implements XulEventSource { public OptimizationImpactInfo preview( DataServiceExecutor executor ) { final OptimizationImpactInfo preview = getType().preview( executor, this ); if ( enabled ) { return preview; } else { return new OptimizationImpactInfo( getStepName() ) { { setModified( false ); setErrorMsg( preview.getErrorMsg() ); setQueryBeforeOptimization( preview.getQueryBeforeOptimization() ); } @Override public String getDescription() { return "#Optimization is disabled\n" + super.getDescription(); } }; } }  String getName(); void setName( String name ); String getStepName(); void setStepName( String stepName ); PushDownType getType(); void setType( PushDownType type ); boolean isEnabled(); void setEnabled( boolean enabled ); ListenableFuture<Boolean> activate( DataServiceExecutor executor ); OptimizationImpactInfo preview( DataServiceExecutor executor ); @Override String toString(); @Override void addPropertyChangeListener( PropertyChangeListener propertyChangeListener ); @Override void removePropertyChangeListener( PropertyChangeListener propertyChangeListener ); static final String PUSH_DOWN_STEP_NAME; }
@Test public void testPreview() throws Exception { OptimizationImpactInfo info = new OptimizationImpactInfo( STEP_NAME ); info.setModified( true ); when( pushDownType.preview( executor, pushDownOptimizationMeta ) ).thenReturn( info ); assertThat( pushDownOptimizationMeta.preview( executor ), sameInstance( info ) ); pushDownOptimizationMeta.setEnabled( false ); OptimizationImpactInfo disabled = pushDownOptimizationMeta.preview( executor ); assertThat( disabled.isModified(), is( false ) ); assertThat( disabled.getDescription(), startsWith( "#Optimization is disabled" ) ); }