@VisibleForTesting
  protected void handleException( String message, Exception exception, StringBuilder text, StringBuilder details ) {
    if ( exception instanceof KettleException ) {
      // Normal error
      KettleException ke = (KettleException) exception;
      Throwable cause = ke.getCause();
      if ( cause != null && cause.getMessage() != null ) {
        text.append( cause.getMessage() );
      } else {
        text.append( ke.getMessage() );
      }

    } else if ( exception instanceof InvocationTargetException ) {
      // Error from somewhere else, what is the cause?
      Throwable cause = exception.getCause();
      if ( cause instanceof KettleException ) {
        KettleException ke = (KettleException) cause;
        text.append( ke.getMessage() );
      } else {
        text.append( Const.NVL( cause.getMessage(), cause.toString() ) );
        while ( text.length() == 0 && cause != null ) {
          cause = cause.getCause();
          if ( cause != null ) {
            text.append( Const.NVL( cause.getMessage(), cause.toString() ) );
          }
        }
      }
    } else {
      // Error from somewhere else...

      if ( exception.getMessage() == null ) {
        text.append( message );
      } else {
        text.append( exception.getMessage() );
      }
    }

    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter( sw );
    exception.printStackTrace( pw );

    details.append( sw.getBuffer() );
  }
@Test
  public void setErrorTextWithCauseExceptionWithoutCauseMessage() {
    //cause without message
    ClientProtocolException cpe = new ClientProtocolException(  );
    Exception e = new KettleException( "kettleMessage", cpe );


    StringBuilder text = new StringBuilder();
    StringBuilder details = new StringBuilder();

    ErrorDialog dialog = mock( ErrorDialog.class );
    doCallRealMethod().when( dialog ).handleException( anyString(), any( Exception.class ), any( StringBuilder.class ), any( StringBuilder.class ) );

    dialog.handleException( "argMessage", e, text, details );

    assertEquals(  text.toString(), e.getMessage().toString() );

  }