Reimplemented the Sniffer Test Suite

This commit is contained in:
Marcus Rockwell 2023-10-06 16:16:30 -05:00
parent 935bf287d4
commit 69dc3d4110
2 changed files with 126 additions and 0 deletions

View File

@ -0,0 +1,76 @@
package trick.sniffer;
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 SnifferApplication life cycle.
*
* @author hchen
*
*/
public class SnifferApplicationTest {
@BeforeClass
public static void setUpBeforeClass() throws Exception {
WaitForSnifferApplication.launchAndWait(WaitForSnifferApplication.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("SnifferApplicationTest is not ready yet!", application().isReady());
}
/**
* Verify that all implemented actions exist as well as their text, shortDescription properties.
*/
/* @Test
public void testDefinedActions() {
String[] actionNames = {"launchSimControlPanel", "launchTrickView"};
String[] actionTexts = {"Launch Sim Control Panel", "Launch Trick View"};
String[] actionShortDescriptions = {"Launch the Sim Control Panel and connect it to the selected simulation.",
"Launch Trick View and connect it to the selected simulation."};
for (int i = 0; i < actionNames.length; i++) {
CheckApplicationProperties.checkAction(application().actionMap, actionNames[i]);
CheckApplicationProperties.checkActionText(application().actionMap, actionNames[i], actionTexts[i]);
CheckApplicationProperties.checkActionShortDescription(application().actionMap, actionNames[i], actionShortDescriptions[i]);
}
}*/
@Test
public void testDefinedKeyText() {
CheckApplicationProperties.checkKeyText(application().resourceMap, "fileMenu.text", "&File");
}
@Test
public void testExit() {
application().removeExitListener(application().exitListener);
application().exit();
assertTrue(application().isEnded);
}
private static WaitForSnifferApplication application() {
return Application.getInstance(WaitForSnifferApplication.class);
}
}

View File

@ -0,0 +1,50 @@
package trick.sniffer;
import org.jdesktop.application.Application;
public class WaitForSnifferApplication extends SimSnifferApplication {
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 SnifferApplication and block
* (wait) until it's startup() method has run.
*/
public static void launchAndWait(Class<? extends WaitForSnifferApplication> 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(WaitForSnifferApplication.class);
if (app instanceof WaitForSnifferApplication) {
if (((WaitForSnifferApplication)app).isReady()) {
break;
}
}
}
}
}
}