/*******************************************************************************
 * Copyright 2015 Friedrich-Schiller-Universität Jena
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * Contributors:
 *     Stephan Druskat - initial API and implementation
 *******************************************************************************/
package org.corpus_tools.atomic.commands;

import static org.junit.Assert.*;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotMenu;
import org.eclipse.ui.PlatformUI;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;

/**
 * TODO Description
 * <p>
 * 
 * @author Stephan Druskat <stephan.druskat@uni-jena.de>
 */
@RunWith(SWTBotJunit4ClassRunner.class)
public class ExitHandlerGUITest {

	private static SWTWorkbenchBot bot;
	private ExitHandler fixture;
	private ExecutionEvent exitEvent;

	@BeforeClass
	public static void beforeClass() throws Exception {
		bot = new SWTWorkbenchBot();
	}

	/**
	 * @throws java.lang.Exception
	 */
	@Before
	public void setUp() throws Exception {
		this.setFixture(new ExitHandler());
	}

	/**
	 * Not implemented
	 *
	 * @throws java.lang.Exception
	 */
	@After
	public void tearDown() throws Exception {
	}

	/**
	 * SWTBot test for menu entries executing the OUT
	 * 
	 * @throws ExecutionException
	 */
	@Test
	public void testExecute() throws ExecutionException {
		SWTBotMenu fileMenu = bot.menu("File");
		assertNotNull(fileMenu);
		SWTBotMenu exitMenu = fileMenu.menu("Exit");
		assertNotNull(exitMenu);
		exitMenu.click();

		// Test execute
//		assertTrue((boolean) getFixture().execute(exitEvent)); // Note: The workbench is closed by now. Cf. http://stackoverflow.com/q/34333091/731040
		assertNull(PlatformUI.getWorkbench().getActiveWorkbenchWindow());
	}

	@AfterClass
	public static void sleep() {
		bot.sleep(2000);
	}

	/**
	 * @return the fixture
	 */
	private ExitHandler getFixture() {
		return fixture;
	}

	/**
	 * @param fixture the fixture to set
	 */
	private void setFixture(ExitHandler fixture) {
		this.fixture = fixture;
	}

}

@@ -925,57 +925,8 @@
 .*;%0A
-import org.eclipse.core.commands.ExecutionEvent;%0A
 impo
@@ -974,16 +974,16 @@
 eption;%0A
+
 import o
@@ -1219,37 +1219,8 @@
 er;%0A
-import org.junit.AfterClass;%0A
 impo
@@ -1535,16 +1535,16 @@
 ot bot;%0A
+
 %09private
@@ -1568,43 +1568,8 @@
 ure;
-%0A%09private ExecutionEvent exitEvent;
 %0A%0A%09@
@@ -2486,74 +2486,8 @@
 %09%7D%0A%0A
-%09@AfterClass%0A%09public static void sleep() %7B%0A%09%09bot.sleep(2000);%0A%09%7D%0A%0A
 %09/**

Modify ExitHandlerGUITest