Got maven set up so that the tests run

This commit is contained in:
Marcus Rockwell 2023-10-02 18:23:36 -05:00
parent 02f7203597
commit 0be90e3791
6 changed files with 258 additions and 1 deletions

View File

@ -6,7 +6,11 @@ include ${TRICK_HOME}/share/trick/makefiles/Makefile.common
all:
@echo "Building java application..."
@${MVN} package -q -Dcmake=false -Dmaven.wagon.http.retryHandler.count=15
@${MVN} package -q -Dmaven.test.skip -Dcmake=false -Dmaven.wagon.http.retryHandler.count=15
test:
@echo "Building java tests..."
@${MVN} test --quiet -Dcmake=false -Dmaven.wagon.http.retryHandler.count=15
javadoc:
${MVN} javadoc:javadoc

View File

@ -313,6 +313,9 @@
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
<configuration>
<printSummary>true</printSummary>
</configuration>
</plugin>
<plugin>

View File

@ -0,0 +1,88 @@
package trick.common;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import javax.swing.ActionMap;
import javax.swing.Icon;
import org.jdesktop.application.ResourceMap;
/**
* A class for checking different properties of an {@link Application}.
*
* @author Hong Chen
*/
public abstract class CheckApplicationProperties{
public static String getActionText(javax.swing.Action action) {
return (String)action.getValue(javax.swing.Action.NAME);
}
public static String getActionShortDescription(javax.swing.Action action) {
return (String)action.getValue(javax.swing.Action.SHORT_DESCRIPTION);
}
// check to see if the action exists (the related @Action code needs to be implemented)
public static javax.swing.Action checkAction(ActionMap aMap, String actionKey) {
javax.swing.Action action = aMap.get(actionKey);
assertNotNull(actionMapGetString(actionKey), action);
return action;
}
// check to see if the action text exists
public static void checkActionText(ActionMap aMap, String actionKey) {
javax.swing.Action action = checkAction(aMap, actionKey);
assertNotNull(actionMapGetString(actionKey) + ".getValue(javax.swing.Action.Name)", getActionText(action));
}
// check to see if the action short description exists
public static void checkActionShortDescription(ActionMap aMap, String actionKey) {
javax.swing.Action action = checkAction(aMap, actionKey);
assertNotNull(actionMapGetString(actionKey) + ".getValue(javax.swing.Action.SHORT_DESCRIPTION)", getActionShortDescription(action));
}
// check to see if the action text is as expected
public static void checkActionText(ActionMap aMap, String actionKey, String expectedValue) {
javax.swing.Action action = aMap.get(actionKey);
assertEquals(actionMapGetString(actionKey) + ".getValue(javax.swing.Action.Name)", expectedValue, (String)action.getValue(javax.swing.Action.NAME));
}
// check to see if the action short description is as expected
public static void checkActionShortDescription(ActionMap aMap, String actionKey, String expectedValue) {
javax.swing.Action action = checkAction(aMap, actionKey);
assertEquals(actionMapGetString(actionKey) + ".getValue(javax.swing.Action.SHORT_DESCRIPTION)", expectedValue, getActionShortDescription(action));
}
// check to see if the action icon is specified
public static void checkActionIcon(ActionMap aMap, String actionKey) {
javax.swing.Action action = checkAction(aMap, actionKey);
Icon icon = (Icon)(action.getValue(javax.swing.Action.SMALL_ICON));
assertNotNull(actionMapGetString(actionKey) + ".getValue(javax.swing.Action.SMALL_ICON)", icon);
}
// check to see if the text of a key is defined
public static void checkKeyText(ResourceMap rMap, String key) {
assertNotNull(rMap.getString(key));
}
// check to see if the text of a key is as expected
public static void checkKeyText(ResourceMap rMap, String key, String expectedValue) {
String keyText = rMap.getString(key);
assertNotNull(keyText);
if (expectedValue != null) {
assertEquals(resourceMapGetString(key), expectedValue, keyText);
}
}
private static String actionMapGetString(String actionKey) {
return "ActionMap.get(\"" + actionKey + "\")";
}
private static String resourceMapGetString(String key) {
return "ResourceMap.get(\"" + key + "\")";
}
}

View File

@ -0,0 +1,80 @@
package trick.dre;
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 DreApplication life cycle.
*
* @author hchen
*
*/
public class DreApplicationTest {
@BeforeClass
public static void setUpBeforeClass() throws Exception {
WaitForDreApplication.launchAndWait(WaitForDreApplication.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("DreApplicationTest 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 = {"openDR", "saveDR", "selectDRBinary", "selectDRAscii", "selectDRHDF5",
"selectDRAlways", "selectDRChanges", "selectDRStepChanges", "toggleSinglePrecision",
"selectDRBuffer", "selectDRNoBuffer", "selectDRRingBuffer", "selectDRThreadBuffer",
"addVariables", "removeSelected", "removeAll"};
String[] actionTexts = {"Open...", "Save...", "DR Binary", "DR Ascii", "DR HDF5", "DR Always", "DR Changes",
"DR Step Changes", "Single Precision", "DR Buffer", "DR No Buffer", "DR Ring Buffer",
"DR Thread Buffer", "Add", "Remove Selected", "Remove All"};
for (int i = 0; i < actionNames.length; i++) {
CheckApplicationProperties.checkAction(application().actionMap, actionNames[i]);
CheckApplicationProperties.checkActionText(application().actionMap, actionNames[i], actionTexts[i]);
}
}
@Test
public void testDefinedKeyText() {
CheckApplicationProperties.checkKeyText(application().resourceMap, "fileMenu.text", "&File");
CheckApplicationProperties.checkKeyText(application().resourceMap, "optionsMenu.text", "&Options");
}
@Test
public void testExit() {
application().removeExitListener(application().exitListener);
application().exit();
assertTrue(application().isEnded);
}
private static WaitForDreApplication application() {
return Application.getInstance(WaitForDreApplication.class);
}
}

View File

@ -0,0 +1,51 @@
package trick.dre;
import org.jdesktop.application.Application;
public class WaitForDreApplication extends DreApplication {
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 DreApplication and block
* (wait) until it's startup() method has run.
*/
public static void launchAndWait(Class<? extends WaitForDreApplication> applicationClass) {
synchronized(lock) {
sieResourcePath ="resources" + java.io.File.separator + "S_sie.resource";
Application.launch(applicationClass, new String[]{});
while(true) {
try {
lock.wait();
}
catch (InterruptedException e) {
System.err.println("launchAndWait interrupted!");
break;
}
Application app = Application.getInstance(WaitForDreApplication.class);
if (app instanceof WaitForDreApplication) {
if (((WaitForDreApplication)app).isReady()) {
break;
}
}
}
}
}
}

View File

@ -0,0 +1,31 @@
package trick.test;
import static org.junit.Assert.assertTrue;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
public class Testing {
@BeforeClass
public static void beforeClassmethod() {
System.out.println("Hi welcome in Before Class Method");
}
@Before
public void beforemethod() {
System.out.println("Hello there welcome in Before Test Case strategy ");
}
@Test
public void Test(){
System.out.println("Welcome in First Test");
int num = 5;
assertTrue(num == 5);
}
@After
public void aftermethod() {
System.out.println("Hi welcome in After Test Case");
}
@AfterClass
public static void afterClassmethod() {
System.out.println("Hi welcome in After Class");
}
}