package com.oskopek.transporteditor.view;

import javafx.stage.Stage;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.testfx.api.FxAssert.*;
import org.testfx.framework.junit.ApplicationTest;
import static org.testfx.matcher.base.NodeMatchers.*;
import static org.assertj.core.api.Assertions.*;

public class ApplicationStartupUT extends ApplicationTest {

    @Override
    public void start(Stage stage) throws Exception {
        stage.setMaximized(true); // needs to happen
    }

    @BeforeClass
    public static void setUpClass() throws Exception {
        ApplicationTest.launch(TransportEditorApplication.class);
        Thread.sleep(5000);
    }

    @Before
    public void setUp() throws Exception {
        clickOn("#sessionMenu");
        clickOn("#sessionNewMenuItem");
        if (lookup("#dialogPane").query() != null) {
            clickOn("Discard");
        }
    }

    @Test
    public void shouldContainAboutMenu() {
        assertThat(lookup("#aboutMenu").tryQuery()).isPresent();
        verifyThat("#aboutMenu", isEnabled());
    }

    @Test
    public void shouldCreateNewSession() throws Exception {
        verifyThat("#domainMenu", isEnabled());
        verifyThat("#problemMenu", isDisabled());
        clickOn("#sessionMenu");
        verifyThat("#sessionNewMenuItem", isNotNull());
        verifyThat("#sessionNewMenuItem", isEnabled());
        clickOn("#sessionNewMenuItem");
        verifyThat("#domainMenu", isEnabled());
        verifyThat("#problemMenu", isDisabled());
    }

    @Test
    public void shouldCreateNewDomain() throws Exception {
        verifyThat("#domainMenu", isEnabled());
        verifyThat("#problemMenu", isDisabled());
        clickOn("#domainMenu");
        verifyThat("#domainNewMenuItem", isNotNull());
        verifyThat("#domainNewMenuItem", isEnabled());
        clickOn("#domainNewMenuItem");
        clickOn("#sequentialRadio");
        clickOn("Apply");
        verifyThat("#problemMenu", isEnabled());
    }
}

@@ -63,16 +63,97 @@
 .Stage;%0A
+import org.jboss.weld.environment.se.WeldContainer;%0Aimport org.junit.AfterClass;%0A
 import o
@@ -169,16 +169,16 @@
 Before;%0A
-
 import o
@@ -226,49 +226,8 @@
 st;%0A
-import static org.testfx.api.FxAssert.*;%0A
 impo
@@ -268,24 +268,174 @@
 icationTest;
+%0A%0Aimport javax.enterprise.inject.spi.CDI;%0A%0Aimport static org.assertj.core.api.Assertions.assertThat;%0Aimport static org.testfx.api.FxAssert.verifyThat;
 %0Aimport stat
@@ -480,57 +480,8 @@
 s.*;
-%0Aimport static org.assertj.core.api.Assertions.*;
 %0A%0Apu
@@ -543,136 +543,8 @@
  %7B%0A%0A
-    @Override%0A    public void start(Stage stage) throws Exception %7B%0A        stage.setMaximized(true); // needs to happen%0A    %7D%0A%0A
     
@@ -677,16 +677,16 @@
 class);%0A
-
         
@@ -708,24 +708,308 @@
 00);%0A    %7D%0A%0A
+    @AfterClass%0A    public static void tearDownClass() %7B%0A        WeldContainer container = (WeldContainer) CDI.current();%0A        container.close();%0A    %7D%0A%0A    @Override%0A    public void start(Stage stage) throws Exception %7B%0A        stage.setMaximized(true); // needs to happen%0A    %7D%0A%0A
     @Before%0A

Fix UT test cleanup