mirror of
https://github.com/nasa/trick.git
synced 2025-04-19 00:27:00 +00:00
MTV Tests Reimplemented
This commit is contained in:
parent
2770a2c445
commit
5bdf7e0151
@ -0,0 +1,63 @@
|
||||
package trick.mtv;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.jdesktop.application.Application;
|
||||
import org.junit.After;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import trick.common.CheckApplicationProperties;
|
||||
|
||||
/**
|
||||
*
|
||||
* Test MtvApplication life cycle.
|
||||
*
|
||||
* @author hchen
|
||||
* @intern mrockwell2
|
||||
*
|
||||
*/
|
||||
public class MtvApplicationTest {
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpBeforeClass() throws Exception {
|
||||
WaitForMtvApplication.launchAndWait(WaitForMtvApplication.class);
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void tearDownAfterClass() throws Exception {
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReady() {
|
||||
assertTrue("MtvApplicationTest is not ready yet!", application().isReady());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testDefinedKeyText() {
|
||||
CheckApplicationProperties.checkKeyText(application().resourceMap, "fileMenu.text", "&File");
|
||||
CheckApplicationProperties.checkKeyText(application().resourceMap, "default_event_directory", "./Modified_data");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExit() {
|
||||
application().removeExitListener(application().exitListener);
|
||||
application().exit();
|
||||
assertTrue(application().isEnded);
|
||||
}
|
||||
|
||||
private static WaitForMtvApplication application() {
|
||||
return Application.getInstance(WaitForMtvApplication.class);
|
||||
}
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
package trick.mtv;
|
||||
|
||||
|
||||
import org.jdesktop.application.Application;
|
||||
|
||||
|
||||
public class WaitForMtvApplication extends MtvApp {
|
||||
static Object lock = new Object();
|
||||
|
||||
boolean isEnded;
|
||||
|
||||
@Override
|
||||
protected void end() {
|
||||
isEnded = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void ready() {
|
||||
super.ready();
|
||||
synchronized(lock) {
|
||||
lock.notifyAll();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Launch the specified subclsas of MtvApp and block
|
||||
* (wait) until it's startup() method has run.
|
||||
*/
|
||||
public static void launchAndWait(Class<? extends WaitForMtvApplication> applicationClass) {
|
||||
synchronized(lock) {
|
||||
Application.launch(applicationClass, new String[]{});
|
||||
while(true) {
|
||||
try {
|
||||
lock.wait();
|
||||
}
|
||||
catch (InterruptedException e) {
|
||||
System.err.println("launchAndWait interrupted!");
|
||||
break;
|
||||
}
|
||||
Application app = Application.getInstance(WaitForMtvApplication.class);
|
||||
if (app instanceof WaitForMtvApplication) {
|
||||
if (((WaitForMtvApplication)app).isReady()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user