diff --git a/test/net/azib/ipscan/gui/SWTTestCase.java b/test/net/azib/ipscan/gui/SWTTestCase.java new file mode 100644 index 00000000..1a11107e --- /dev/null +++ b/test/net/azib/ipscan/gui/SWTTestCase.java @@ -0,0 +1,49 @@ +/** + * This file is a part of Angry IP Scanner source code, + * see http://www.azib.net/ for more information. + * Licensed under GPLv2. + */ + +package net.azib.ipscan.gui; + +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; +import org.junit.After; +import org.junit.Before; + +/** + * SWTTestCase - base class for SWT tests + * + * @author Anton Keks + */ +public abstract class SWTTestCase { + protected static final Display display = Display.getDefault(); + + protected Shell shell; + + @Before + public void setUp() { + newShell(); + } + + protected void newShell() { + disposeShell(); + shell = new Shell(display); + } + + private void disposeShell() { + if (shell != null) { + shell.dispose(); + shell = null; + } + } + + @After + public void tearDown() { + display.syncExec(new Runnable() { + public void run() { + disposeShell(); + } + }); + } +}