/*******************************************************************************
 * 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.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.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;

	@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());
	}

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

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

}

@@ -2081,16 +2081,18 @@
 ption %7B%0A
+//
 %09%09SWTBot
@@ -2121,24 +2121,26 @@
 nu(%22File%22);%0A
+//
 %09%09assertNotN
@@ -2154,16 +2154,18 @@
 eMenu);%0A
+//
 %09%09SWTBot
@@ -2203,16 +2203,18 @@
 Exit%22);%0A
+//
 %09%09assert
@@ -2232,16 +2232,18 @@
 tMenu);%0A
+//
 %09%09exitMe
@@ -2254,17 +2254,21 @@
 lick();%0A
-%0A
+//%0A//
 %09%09// Tes
@@ -2277,16 +2277,18 @@
 execute%0A
+//
 //%09%09asse
@@ -2426,16 +2426,18 @@
 /731040%0A
+//
 %09%09assert

Comment out ExitHandlerGUITest so ExitHandlerTest doesn't fail