@Test public void testCheckWidgetCalledFromMainThread() { TestObserver<?> testObserver = TestObserver.create(); boolean checkWidget = Preconditions.checkWidget(testObserver, shell); assertThat(checkWidget, is(true)); testObserver.assertNoErrors(); }
public static boolean checkWidget(Observer<?> observer, Widget widget) { if (null == widget) { observer.onError(new NullPointerException("The given widget was null")); return false; } else if (widget.isDisposed()) { observer.onError(new IllegalStateException("The given widget is diposed")); return false; } else if (!(Thread.currentThread().equals(widget.getDisplay().getThread()))) { observer.onError(new IllegalStateException( "Expected to be called on the main thread but was " + Thread.currentThread().getName())); return false; } return true; }
Preconditions { public static boolean checkWidget(Observer<?> observer, Widget widget) { if (null == widget) { observer.onError(new NullPointerException("The given widget was null")); return false; } else if (widget.isDisposed()) { observer.onError(new IllegalStateException("The given widget is diposed")); return false; } else if (!(Thread.currentThread().equals(widget.getDisplay().getThread()))) { observer.onError(new IllegalStateException( "Expected to be called on the main thread but was " + Thread.currentThread().getName())); return false; } return true; } }
Preconditions { public static boolean checkWidget(Observer<?> observer, Widget widget) { if (null == widget) { observer.onError(new NullPointerException("The given widget was null")); return false; } else if (widget.isDisposed()) { observer.onError(new IllegalStateException("The given widget is diposed")); return false; } else if (!(Thread.currentThread().equals(widget.getDisplay().getThread()))) { observer.onError(new IllegalStateException( "Expected to be called on the main thread but was " + Thread.currentThread().getName())); return false; } return true; } private  Preconditions(); }
Preconditions { public static boolean checkWidget(Observer<?> observer, Widget widget) { if (null == widget) { observer.onError(new NullPointerException("The given widget was null")); return false; } else if (widget.isDisposed()) { observer.onError(new IllegalStateException("The given widget is diposed")); return false; } else if (!(Thread.currentThread().equals(widget.getDisplay().getThread()))) { observer.onError(new IllegalStateException( "Expected to be called on the main thread but was " + Thread.currentThread().getName())); return false; } return true; } private  Preconditions(); static boolean checkWidget(Observer<?> observer, Widget widget); static boolean checkDisplay(Observer<?> observer, Display display); }
Preconditions { public static boolean checkWidget(Observer<?> observer, Widget widget) { if (null == widget) { observer.onError(new NullPointerException("The given widget was null")); return false; } else if (widget.isDisposed()) { observer.onError(new IllegalStateException("The given widget is diposed")); return false; } else if (!(Thread.currentThread().equals(widget.getDisplay().getThread()))) { observer.onError(new IllegalStateException( "Expected to be called on the main thread but was " + Thread.currentThread().getName())); return false; } return true; } private  Preconditions(); static boolean checkWidget(Observer<?> observer, Widget widget); static boolean checkDisplay(Observer<?> observer, Display display);  }