NewDecisionTableXLSHandler extends DefaultNewResourceHandler { @Override public void validate(final String baseFileName, final ValidatorWithReasonCallback callback) { if(uploadWidget.getFilenameSelectedToUpload() == null || uploadWidget.getFilenameSelectedToUpload().isEmpty()) { uploadWidget.addStyleName(ValidationState.ERROR.getCssName()); } else { super.validate(baseFileName, callback); } } NewDecisionTableXLSHandler(); @Inject  NewDecisionTableXLSHandler( final PlaceManager placeManager,
                                       final DecisionTableXLSResourceType decisionTableXLSResourceType,
                                       final DecisionTableXLSXResourceType decisionTableXLSXResourceType,
                                       final BusyIndicatorView busyIndicatorView,
                                       final ClientMessageBus clientMessageBus ); @Override List<Pair<String, ? extends IsWidget>> getExtensions(); @Override String getDescription(); @Override IsWidget getIcon(); @Override ResourceTypeDefinition getResourceType(); @Override void validate(final String baseFileName, final ValidatorWithReasonCallback callback); @Override void create( final Package pkg,
                        final String baseFileName,
                        final NewResourcePresenter presenter );  }
@Test public void testValidateNullFile() { final ValidatorWithReasonCallback validatorWithReasonCallback = mock(ValidatorWithReasonCallback.class); when(uploadWidget.getFilenameSelectedToUpload()).thenReturn(null); handler.validate("filename", validatorWithReasonCallback); verify(uploadWidget).addStyleName(ValidationState.ERROR.getCssName()); }
@Test public void testValidateEmptyFile() { final ValidatorWithReasonCallback validatorWithReasonCallback = mock(ValidatorWithReasonCallback.class); when(uploadWidget.getFilenameSelectedToUpload()).thenReturn(""); handler.validate("filename", validatorWithReasonCallback); verify(uploadWidget).addStyleName(ValidationState.ERROR.getCssName()); }
@Test public void testValidateNonEmptyFile() { final ValidatorWithReasonCallback validatorWithReasonCallback = mock(ValidatorWithReasonCallback.class); when(uploadWidget.getFilenameSelectedToUpload()).thenReturn("table.xls"); handler.validate("filename", validatorWithReasonCallback); verify(uploadWidget, never()).addStyleName(ValidationState.ERROR.getCssName()); }