@Test public void setErrorTextWithCauseMessageException() { ClientProtocolException cpe = new ClientProtocolException( "causeMessage" ); 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 ); Throwable cause = e.getCause(); assertEquals( text.toString(), cause.getMessage().toString() ); }
@VisibleForTesting protected void handleException( String message, Exception exception, StringBuilder text, StringBuilder details ) { if ( exception instanceof KettleException ) { 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 ) { 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 { 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() ); }
ErrorDialog extends Dialog { @VisibleForTesting protected void handleException( String message, Exception exception, StringBuilder text, StringBuilder details ) { if ( exception instanceof KettleException ) { 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 ) { 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 { 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() ); } }
ErrorDialog extends Dialog { @VisibleForTesting protected void handleException( String message, Exception exception, StringBuilder text, StringBuilder details ) { if ( exception instanceof KettleException ) { 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 ) { 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 { 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() ); } ErrorDialog( Shell parent, String title, String message, Throwable throwable );  ErrorDialog( Shell parent, String title, String message, Exception exception );  ErrorDialog( Shell parent, String title, String message, Exception exception, boolean showCancelButton ); }
ErrorDialog extends Dialog { @VisibleForTesting protected void handleException( String message, Exception exception, StringBuilder text, StringBuilder details ) { if ( exception instanceof KettleException ) { 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 ) { 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 { 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() ); } ErrorDialog( Shell parent, String title, String message, Throwable throwable );  ErrorDialog( Shell parent, String title, String message, Exception exception );  ErrorDialog( Shell parent, String title, String message, Exception exception, boolean showCancelButton ); void dispose(); boolean isCancelled(); }
ErrorDialog extends Dialog { @VisibleForTesting protected void handleException( String message, Exception exception, StringBuilder text, StringBuilder details ) { if ( exception instanceof KettleException ) { 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 ) { 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 { 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() ); } ErrorDialog( Shell parent, String title, String message, Throwable throwable );  ErrorDialog( Shell parent, String title, String message, Exception exception );  ErrorDialog( Shell parent, String title, String message, Exception exception, boolean showCancelButton ); void dispose(); boolean isCancelled();  }