MTV Tests Reimplemented

This commit is contained in:
Marcus Rockwell 2023-10-05 16:35:38 -05:00
parent 2770a2c445
commit 5bdf7e0151
2 changed files with 112 additions and 0 deletions

View File

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

View File

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