Add since tag, remove trailing spaces
diff --git a/bundles/org.eclipse.rap.rwt/src/org/eclipse/rap/rwt/application/Application.java b/bundles/org.eclipse.rap.rwt/src/org/eclipse/rap/rwt/application/Application.java index 7fef8b3..7bb6536 100644 --- a/bundles/org.eclipse.rap.rwt/src/org/eclipse/rap/rwt/application/Application.java +++ b/bundles/org.eclipse.rap.rwt/src/org/eclipse/rap/rwt/application/Application.java
@@ -190,21 +190,22 @@ * @see SettingStore */ void setSettingStoreFactory( SettingStoreFactory settingStoreFactory ); - + /** - * The exception handler to which exceptions should be forwarded that occur while running - * the event loop. + * Sets the exception handler to which exceptions should be forwarded that occur while running + * the event loop. * <p> - * To give an exception handler the chance to log errors it called for all classes of exceptions. - * <code>Error</code>s however are re-thrown after the handler was called so that they cannot be - * swallowed. + * To give an exception handler the chance to log errors it called for all classes of exceptions. + * <code>Error</code>s however are re-thrown after the handler was called so that they cannot be + * swallowed. * </p> * <p> - * The default implementation throws the given exception, resulting in a HTTP 500 response. + * The default implementation throws the given exception, resulting in a HTTP 500 response. * </p> - * + * * @param the exception handler to use, must not be <code>null</code> * @see ExceptionHandler + * @since 2.1 */ void setExceptionHandler( ExceptionHandler exceptionHandler );
diff --git a/bundles/org.eclipse.rap.rwt/src/org/eclipse/rap/rwt/application/ExceptionHandler.java b/bundles/org.eclipse.rap.rwt/src/org/eclipse/rap/rwt/application/ExceptionHandler.java index 12ff126..d2f1857 100644 --- a/bundles/org.eclipse.rap.rwt/src/org/eclipse/rap/rwt/application/ExceptionHandler.java +++ b/bundles/org.eclipse.rap.rwt/src/org/eclipse/rap/rwt/application/ExceptionHandler.java
@@ -12,18 +12,19 @@ /** - * This interface allows application code to be informed of exceptions that occurr while - * running the event loop. - * + * This interface allows application code to be informed of exceptions that occur while + * running the event loop. + * * @see Application#setExceptionHandler(ExceptionHandler) * @since 2.1 */ public interface ExceptionHandler { - + /** - * Called if an exception occured. - * - * @param throwable the exception that occured, never <code>null</code> + * Called if an exception occurred. + * + * @param throwable the exception that occurred, never <code>null</code> */ void handleException( Throwable throwable ); + }
diff --git a/bundles/org.eclipse.rap.rwt/src/org/eclipse/rap/rwt/internal/application/ApplicationContextImpl.java b/bundles/org.eclipse.rap.rwt/src/org/eclipse/rap/rwt/internal/application/ApplicationContextImpl.java index 58c39c4..3f7fdd6 100644 --- a/bundles/org.eclipse.rap.rwt/src/org/eclipse/rap/rwt/internal/application/ApplicationContextImpl.java +++ b/bundles/org.eclipse.rap.rwt/src/org/eclipse/rap/rwt/internal/application/ApplicationContextImpl.java
@@ -109,7 +109,7 @@ contextActivator = new ApplicationContextActivator( this ); clientSelector = new ClientSelector(); } - + public void setAttribute( String name, Object value ) { applicationStore.setAttribute( name, value ); } @@ -237,11 +237,11 @@ public ClientSelector getClientSelector() { return clientSelector; } - + public ExceptionHandler getExceptionHandler() { return exceptionHandler; } - + public void setExceptionHandler( ExceptionHandler exceptionHandler ) { this.exceptionHandler = exceptionHandler; }
diff --git a/bundles/org.eclipse.rap.rwt/src/org/eclipse/rap/rwt/internal/application/ApplicationImpl.java b/bundles/org.eclipse.rap.rwt/src/org/eclipse/rap/rwt/internal/application/ApplicationImpl.java index 4af0244..599a007 100644 --- a/bundles/org.eclipse.rap.rwt/src/org/eclipse/rap/rwt/internal/application/ApplicationImpl.java +++ b/bundles/org.eclipse.rap.rwt/src/org/eclipse/rap/rwt/internal/application/ApplicationImpl.java
@@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2011, 2012 Frank Appel and others. + * Copyright (c) 2011, 2013 Frank Appel and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -75,9 +75,10 @@ applicationContext.getSettingStoreManager().register( settingStoreFactory ); } - + public void setExceptionHandler( ExceptionHandler exceptionHandler ) { ParamCheck.notNull( exceptionHandler, "exceptionHandler" ); + applicationContext.setExceptionHandler( exceptionHandler ); }
diff --git a/bundles/org.eclipse.rap.rwt/src/org/eclipse/swt/widgets/Display.java b/bundles/org.eclipse.rap.rwt/src/org/eclipse/swt/widgets/Display.java index 72e2dce..92c006c 100644 --- a/bundles/org.eclipse.rap.rwt/src/org/eclipse/swt/widgets/Display.java +++ b/bundles/org.eclipse.rap.rwt/src/org/eclipse/swt/widgets/Display.java
@@ -157,7 +157,7 @@ private static final String APP_VERSION = Display.class.getName() + "#appVersion"; private static final int DOUBLE_CLICK_TIME = 500; // Keep in sync with client-side (EventUtil.js) private static final int GROW_SIZE = 1024; - + static final String PACKAGE_PREFIX = "org.eclipse.swt.widgets."; private static final ExceptionHandler DEFAULT_EXCEPTION_HANDLER = new ExceptionHandler() { @@ -1212,7 +1212,7 @@ } return result; } - + /** * Causes the user-interface thread to <em>sleep</em> (that is, * to be put in a state where it does not consume CPU cycles) @@ -2432,5 +2432,5 @@ beep = false; } } - + }
diff --git a/tests/org.eclipse.rap.rwt.test/src/org/eclipse/rap/rwt/internal/application/ApplicationImpl_Test.java b/tests/org.eclipse.rap.rwt.test/src/org/eclipse/rap/rwt/internal/application/ApplicationImpl_Test.java index a1c541f..2277cba 100644 --- a/tests/org.eclipse.rap.rwt.test/src/org/eclipse/rap/rwt/internal/application/ApplicationImpl_Test.java +++ b/tests/org.eclipse.rap.rwt.test/src/org/eclipse/rap/rwt/internal/application/ApplicationImpl_Test.java
@@ -149,25 +149,21 @@ } catch( NullPointerException expected ) { } } - + @Test public void testSetExceptionHandler() { ExceptionHandler exceptionHandler = mock( ExceptionHandler.class ); - + application.setExceptionHandler( exceptionHandler ); - + assertSame( exceptionHandler, applicationContext.getExceptionHandler() ); } - @Test - public void testSetExceptionHandlerWithNullArgument() { - try { - application.setExceptionHandler( null ); - fail(); - } catch( NullPointerException expected ) { - } + @Test( expected = NullPointerException.class ) + public void testSetExceptionHandler_failsWithNullArgument() { + application.setExceptionHandler( null ); } - + private void assertFilterRegistered( Class<RWTClusterSupport> filterClass ) { FilterRegistration[] filterRegistrations = getFilterRegistrations(); boolean found = false;
diff --git a/tests/org.eclipse.rap.rwt.test/src/org/eclipse/swt/widgets/DisplayExceptionHandler_Test.java b/tests/org.eclipse.rap.rwt.test/src/org/eclipse/swt/widgets/DisplayExceptionHandler_Test.java index 4d96ab8..05dfdf0 100644 --- a/tests/org.eclipse.rap.rwt.test/src/org/eclipse/swt/widgets/DisplayExceptionHandler_Test.java +++ b/tests/org.eclipse.rap.rwt.test/src/org/eclipse/swt/widgets/DisplayExceptionHandler_Test.java
@@ -10,13 +10,14 @@ ******************************************************************************/ package org.eclipse.swt.widgets; +import static org.junit.Assert.assertSame; +import static org.junit.Assert.fail; import static org.mockito.Matchers.any; import static org.mockito.Matchers.anyBoolean; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.verify; -import junit.framework.TestCase; import org.eclipse.rap.rwt.application.ExceptionHandler; import org.eclipse.rap.rwt.internal.application.ApplicationContextUtil; @@ -27,118 +28,14 @@ import org.eclipse.swt.internal.events.EventList; import org.junit.After; import org.junit.Before; +import org.junit.Test; -public class DisplayExceptionHandler_Test extends TestCase { - +public class DisplayExceptionHandler_Test { + private ExceptionHandler exceptionHandler; private Display display; private Shell shell; - - public void testRuntimeExceptionInListenerWithExceptionHandler() { - ApplicationContextUtil.getInstance().setExceptionHandler( exceptionHandler ); - RuntimeException exception = new RuntimeException(); - addMaliciousListener( SWT.Resize, exception ); - generateEvent( shell, SWT.Resize ); - - display.readAndDispatch(); - - verify( exceptionHandler ).handleException( exception ); - } - - public void testRuntimeExceptionInListenerWithoutExceptionHandler() { - RuntimeException exception = new RuntimeException(); - addMaliciousListener( SWT.Resize, exception ); - generateEvent( shell, SWT.Resize ); - - try { - display.readAndDispatch(); - fail(); - } catch( RuntimeException expected ) { - assertSame( exception, expected ); - } - } - - public void testErrorInListenerWithExceptionHandler() { - ApplicationContextUtil.getInstance().setExceptionHandler( exceptionHandler ); - Error error = new Error(); - addMaliciousListener( SWT.Resize, error ); - generateEvent( shell, SWT.Resize ); - - try { - display.readAndDispatch(); - fail(); - } catch( Error expected ) { - assertSame( error, expected ); - } - - verify( exceptionHandler ).handleException( error ); - } - - public void testErrorInListenerWithoutExceptionHandler() { - Error error = new Error(); - addMaliciousListener( SWT.Resize, error ); - generateEvent( shell, SWT.Resize ); - - try { - display.readAndDispatch(); - fail(); - } catch( Error expected ) { - assertSame( error, expected ); - } - } - - public void testExceptionInExceptionHandler() { - ApplicationContextUtil.getInstance().setExceptionHandler( exceptionHandler ); - RuntimeException exceptionInHandler = new RuntimeException(); - doThrow( exceptionInHandler ).when( exceptionHandler ).handleException( any( Throwable.class ) ); - addMaliciousListener( SWT.Resize, exceptionInHandler ); - generateEvent( shell, SWT.Resize ); - - try { - display.readAndDispatch(); - fail(); - } catch( Exception expected ) { - assertSame( exceptionInHandler, expected ); - } - } - - public void testReSkinningIsRunWithinExceptionHandler() { - ApplicationContextUtil.getInstance().setExceptionHandler( exceptionHandler ); - RuntimeException exception = new RuntimeException(); - Listener listener = mock( Listener.class ); - doThrow( exception ).when( listener ).handleEvent( any( Event.class ) ); - display.addListener( SWT.Skin, listener ); - display.addSkinnableWidget( shell ); - - display.readAndDispatch(); - - verify( exceptionHandler ).handleException( exception ); - } - - public void testDeferredLayoutIsRunWithinExceptionHandler() { - shell = spy( shell ); - ApplicationContextUtil.getInstance().setExceptionHandler( exceptionHandler ); - RuntimeException exception = new RuntimeException(); - doThrow( exception ).when( shell ).setLayoutDeferred( anyBoolean() ); - display.addLayoutDeferred( shell ); - - display.readAndDispatch(); - - verify( exceptionHandler ).handleException( exception ); - } - - public void testProcessActionRunnableIsRunWithinExceptionHandler() { - ApplicationContextUtil.getInstance().setExceptionHandler( exceptionHandler ); - RuntimeException exception = new RuntimeException(); - Runnable runnable = mock( Runnable.class ); - doThrow( exception ).when( runnable ).run(); - addProcessActionRunnable( runnable ); - - display.readAndDispatch(); - - verify( exceptionHandler ).handleException( exception ); - } @Before public void setUp() { @@ -154,6 +51,119 @@ Fixture.tearDown(); } + @Test + public void testRuntimeExceptionInListenerWithExceptionHandler() { + ApplicationContextUtil.getInstance().setExceptionHandler( exceptionHandler ); + RuntimeException exception = new RuntimeException(); + addMaliciousListener( SWT.Resize, exception ); + generateEvent( shell, SWT.Resize ); + + display.readAndDispatch(); + + verify( exceptionHandler ).handleException( exception ); + } + + @Test + public void testRuntimeExceptionInListenerWithoutExceptionHandler() { + RuntimeException exception = new RuntimeException(); + addMaliciousListener( SWT.Resize, exception ); + generateEvent( shell, SWT.Resize ); + + try { + display.readAndDispatch(); + fail(); + } catch( RuntimeException expected ) { + assertSame( exception, expected ); + } + } + + @Test + public void testErrorInListenerWithExceptionHandler() { + ApplicationContextUtil.getInstance().setExceptionHandler( exceptionHandler ); + Error error = new Error(); + addMaliciousListener( SWT.Resize, error ); + generateEvent( shell, SWT.Resize ); + + try { + display.readAndDispatch(); + fail(); + } catch( Error expected ) { + assertSame( error, expected ); + } + + verify( exceptionHandler ).handleException( error ); + } + + @Test + public void testErrorInListenerWithoutExceptionHandler() { + Error error = new Error(); + addMaliciousListener( SWT.Resize, error ); + generateEvent( shell, SWT.Resize ); + + try { + display.readAndDispatch(); + fail(); + } catch( Error expected ) { + assertSame( error, expected ); + } + } + + @Test + public void testExceptionInExceptionHandler() { + ApplicationContextUtil.getInstance().setExceptionHandler( exceptionHandler ); + RuntimeException exceptionInHandler = new RuntimeException(); + doThrow( exceptionInHandler ).when( exceptionHandler ).handleException( any( Throwable.class ) ); + addMaliciousListener( SWT.Resize, exceptionInHandler ); + generateEvent( shell, SWT.Resize ); + + try { + display.readAndDispatch(); + fail(); + } catch( Exception expected ) { + assertSame( exceptionInHandler, expected ); + } + } + + @Test + public void testReSkinningIsRunWithinExceptionHandler() { + ApplicationContextUtil.getInstance().setExceptionHandler( exceptionHandler ); + RuntimeException exception = new RuntimeException(); + Listener listener = mock( Listener.class ); + doThrow( exception ).when( listener ).handleEvent( any( Event.class ) ); + display.addListener( SWT.Skin, listener ); + display.addSkinnableWidget( shell ); + + display.readAndDispatch(); + + verify( exceptionHandler ).handleException( exception ); + } + + @Test + public void testDeferredLayoutIsRunWithinExceptionHandler() { + shell = spy( shell ); + ApplicationContextUtil.getInstance().setExceptionHandler( exceptionHandler ); + RuntimeException exception = new RuntimeException(); + doThrow( exception ).when( shell ).setLayoutDeferred( anyBoolean() ); + display.addLayoutDeferred( shell ); + + display.readAndDispatch(); + + verify( exceptionHandler ).handleException( exception ); + } + + @Test + public void testProcessActionRunnableIsRunWithinExceptionHandler() { + ApplicationContextUtil.getInstance().setExceptionHandler( exceptionHandler ); + RuntimeException exception = new RuntimeException(); + Runnable runnable = mock( Runnable.class ); + doThrow( exception ).when( runnable ).run(); + addProcessActionRunnable( runnable ); + + display.readAndDispatch(); + + verify( exceptionHandler ).handleException( exception ); + } + private void addMaliciousListener( int eventType, Throwable throwable ) { Listener listener = mock( Listener.class ); doThrow( throwable ).when( listener ).handleEvent( any( Event.class ) );