Skip to content

Commit

Permalink
Improve test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
danielboudreau authored and danielboudreau committed Sep 26, 2018
1 parent 6ded470 commit b8e54e2
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ public void loadLocations() {
l5.setLength(1005);
}


@Before
public void setUp() throws Exception {
jmri.util.JUnitUtil.setUp();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
package jmri.jmrit.operations.locations.schedules;

import jmri.util.JUnitUtil;
import java.awt.GraphicsEnvironment;
import jmri.InstanceManager;
import jmri.jmrit.operations.OperationsSwingTestCase;
import jmri.jmrit.operations.locations.Location;
import jmri.jmrit.operations.locations.LocationManager;
import jmri.jmrit.operations.locations.Track;
import jmri.util.swing.JemmyUtil;
import org.junit.After;
import org.junit.Assert;
import org.junit.Assume;
import org.junit.Before;
import org.junit.Test;

/**
*
* @author Paul Bender Copyright (C) 2017
*/
public class ExportSchedulesTest {
public class ExportSchedulesTest extends OperationsSwingTestCase{

@Test
public void testCTor() {
Expand All @@ -19,14 +26,55 @@ public void testCTor() {
}

// The minimal setup for log4J
@Override
@Before
public void setUp() {
JUnitUtil.setUp();
public void setUp() throws Exception {
super.setUp();
}

@Test
public void testCreateFile() {
Assume.assumeFalse(GraphicsEnvironment.isHeadless());
ExportSchedules exportLoc = new ExportSchedules();
Assert.assertNotNull("exists", exportLoc);

loadLocations(); //only Test Loc E has a track

LocationManager lManager = InstanceManager.getDefault(LocationManager.class);
Location l1 = lManager.getLocationByName("Test Loc E");
Track track = l1.getTrackByName("Test Track", Track.SPUR);

// create schedule with one item
ScheduleManager sManager = InstanceManager.getDefault(ScheduleManager.class);
Schedule schedule = sManager.newSchedule("test schedule");
schedule.addItem("Boxcar");

track.setSchedule(schedule);

// should cause export complete dialog to appear
Thread export = new Thread(new Runnable() {
@Override
public void run() {
exportLoc.writeOperationsScheduleFile();
}
});
export.setName("Export Schedules"); // NOI18N
export.start();

jmri.util.JUnitUtil.waitFor(() -> {
return export.getState().equals(Thread.State.WAITING);
}, "wait for prompt");

JemmyUtil.pressDialogButton(Bundle.getMessage("ExportComplete"), "OK");

java.io.File file = new java.io.File(ExportSchedules.defaultOperationsFilename());
Assert.assertTrue("Confirm file creation", file.exists());
}

@Override
@After
public void tearDown() {
JUnitUtil.tearDown();
public void tearDown() throws Exception {
super.tearDown();
}

// private final static Logger log = LoggerFactory.getLogger(ExportCarsTest.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,65 @@
package jmri.jmrit.operations.locations.tools;

import jmri.util.JUnitUtil;
import java.awt.GraphicsEnvironment;
import jmri.jmrit.operations.OperationsSwingTestCase;
import jmri.util.swing.JemmyUtil;
import org.junit.After;
import org.junit.Assert;
import org.junit.Assume;
import org.junit.Before;
import org.junit.Test;

/**
*
* @author Paul Bender Copyright (C) 2017
*/
public class ExportLocationsTest {
public class ExportLocationsTest extends OperationsSwingTestCase {

@Test
public void testCTor() {
ExportLocations t = new ExportLocations();
Assert.assertNotNull("exists", t);
}

@Test
public void testCreateFile() {
Assume.assumeFalse(GraphicsEnvironment.isHeadless());
ExportLocations exportLoc = new ExportLocations();
Assert.assertNotNull("exists", exportLoc);

loadLocations(); //only Test Loc E has a track

// should cause export complete dialog to appear
Thread export = new Thread(new Runnable() {
@Override
public void run() {
exportLoc.writeOperationsLocationFile();
}
});
export.setName("Export Locations"); // NOI18N
export.start();

jmri.util.JUnitUtil.waitFor(() -> {
return export.getState().equals(Thread.State.WAITING);
}, "wait for prompt");

JemmyUtil.pressDialogButton(Bundle.getMessage("ExportComplete"), "OK");

java.io.File file = new java.io.File(ExportLocations.defaultOperationsFilename());
Assert.assertTrue("Confirm file creation", file.exists());
}

// The minimal setup for log4J
@Override
@Before
public void setUp() {
JUnitUtil.setUp();
public void setUp() throws Exception {
super.setUp();
}

@Override
@After
public void tearDown() {
JUnitUtil.tearDown();
public void tearDown() throws Exception {
super.tearDown();
}

// private final static Logger log = LoggerFactory.getLogger(ExportCarsTest.class);
Expand Down
41 changes: 16 additions & 25 deletions java/test/jmri/jmrit/operations/trains/TrainBuilderGuiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@
import jmri.jmrit.operations.routes.RouteLocation;
import jmri.jmrit.operations.setup.Setup;
import jmri.util.JUnitOperationsUtil;
import jmri.util.swing.JemmyUtil;
import org.junit.After;
import org.junit.Assert;
import org.junit.Assume;
import org.junit.Before;
import org.junit.Test;
import org.netbeans.jemmy.operators.JButtonOperator;
import org.netbeans.jemmy.operators.JDialogOperator;

/**
* Tests for the Operations Trains GUI class
Expand Down Expand Up @@ -69,7 +68,7 @@ public void run() {
return build.getState().equals(Thread.State.WAITING);
}, "wait for prompt");

pressDialogButton(Bundle.getMessage("SelectDepartureTrack"), "OK");
JemmyUtil.pressDialogButton(Bundle.getMessage("SelectDepartureTrack"), "OK");

jmri.util.JUnitUtil.waitFor(() -> {
return build.getState().equals(Thread.State.TERMINATED);
Expand All @@ -93,7 +92,7 @@ public void run() {
return build2.getState().equals(Thread.State.WAITING);
}, "wait for prompt");

pressDialogButton(Bundle.getMessage("SelectDepartureTrack"), "Cancel");
JemmyUtil.pressDialogButton(Bundle.getMessage("SelectDepartureTrack"), "Cancel");

jmri.util.JUnitUtil.waitFor(() -> {
return build.getState().equals(Thread.State.TERMINATED);
Expand Down Expand Up @@ -129,7 +128,7 @@ public void run() {
return build.getState().equals(Thread.State.WAITING);
}, "wait for prompt");

pressDialogButton(Bundle.getMessage("SelectArrivalTrack"), "OK");
JemmyUtil.pressDialogButton(Bundle.getMessage("SelectArrivalTrack"), "OK");

jmri.util.JUnitUtil.waitFor(() -> {
return build.getState().equals(Thread.State.TERMINATED);
Expand All @@ -153,7 +152,7 @@ public void run() {
return build2.getState().equals(Thread.State.WAITING);
}, "wait for prompt");

pressDialogButton(Bundle.getMessage("SelectArrivalTrack"), "Cancel");
JemmyUtil.pressDialogButton(Bundle.getMessage("SelectArrivalTrack"), "Cancel");

jmri.util.JUnitUtil.waitFor(() -> {
return build.getState().equals(Thread.State.TERMINATED);
Expand Down Expand Up @@ -188,7 +187,7 @@ public void run() {
return build.getState().equals(Thread.State.WAITING);
}, "wait for prompt");

pressDialogButton(MessageFormat.format(Bundle.getMessage("buildErrorMsg"),
JemmyUtil.pressDialogButton(MessageFormat.format(Bundle.getMessage("buildErrorMsg"),
new Object[]{train2.getName(), train2.getDescription()}), "OK");

jmri.util.JUnitUtil.waitFor(() -> {
Expand Down Expand Up @@ -253,7 +252,7 @@ public void run() {
}, "wait for prompt");

// dialog "remove cars from staging" or continue by pressing "OK"
pressDialogButton(MessageFormat.format(Bundle.getMessage("buildErrorMsg"),
JemmyUtil.pressDialogButton(MessageFormat.format(Bundle.getMessage("buildErrorMsg"),
new Object[]{train2.getName(), train2.getDescription()}), Bundle.getMessage("ButtonOK"));

// thread can go from RUNNABLE to WAITING to RUNNABLE to WAITING .....
Expand All @@ -269,7 +268,7 @@ public void run() {
}, "wait for prompt");

// next prompt asks if cars are to be released from train by reset
pressDialogButton(Bundle.getMessage("buildResetTrain"), "No");
JemmyUtil.pressDialogButton(Bundle.getMessage("buildResetTrain"), "No");

jmri.util.JUnitUtil.waitFor(() -> {
return build.getState().equals(Thread.State.TERMINATED);
Expand Down Expand Up @@ -350,7 +349,7 @@ public void run() {
}, "wait for prompt");

// dialog "remove cars from staging" or continue by pressing "OK"
pressDialogButton(MessageFormat.format(Bundle.getMessage("buildErrorMsg"),
JemmyUtil.pressDialogButton(MessageFormat.format(Bundle.getMessage("buildErrorMsg"),
new Object[]{train2.getName(), train2.getDescription()}), Bundle.getMessage("ButtonOK"));

// thread can go from RUNNABLE to WAITING to RUNNABLE to WAITING .....
Expand All @@ -366,7 +365,7 @@ public void run() {
},"wait for prompt");

// next prompt asks if cars are to be released from train by reset
pressDialogButton(Bundle.getMessage("buildResetTrain"), "Yes");
JemmyUtil.pressDialogButton(Bundle.getMessage("buildResetTrain"), "Yes");

jmri.util.JUnitUtil.waitFor(() -> {
return build.getState().equals(Thread.State.TERMINATED);
Expand Down Expand Up @@ -440,7 +439,7 @@ public void run() {
}, "wait for prompt");

// dialog "remove cars from staging" or continue by pressing "OK"
pressDialogButton(MessageFormat.format(Bundle.getMessage("buildErrorMsg"),
JemmyUtil.pressDialogButton(MessageFormat.format(Bundle.getMessage("buildErrorMsg"),
new Object[]{train2.getName(), train2.getDescription()}), Bundle.getMessage("buttonRemoveCars"));

// thread can go from RUNNABLE to WAITING to RUNNABLE to WAITING .....
Expand All @@ -456,7 +455,7 @@ public void run() {
},"wait for prompt");

// next prompt asks if cars are to be released from train by reset
pressDialogButton(Bundle.getMessage("buildResetTrain"), "Yes");
JemmyUtil.pressDialogButton(Bundle.getMessage("buildResetTrain"), "Yes");

jmri.util.JUnitUtil.waitFor(() -> {
return build.getState().equals(Thread.State.TERMINATED);
Expand Down Expand Up @@ -537,7 +536,7 @@ public void run() {
}, "wait for prompt");

// dialog remove engines from staging or continue by pressing OK
pressDialogButton(MessageFormat.format(Bundle.getMessage("buildErrorMsg"),
JemmyUtil.pressDialogButton(MessageFormat.format(Bundle.getMessage("buildErrorMsg"),
new Object[]{train2.getName(), train2.getDescription()}), Bundle.getMessage("ButtonOK"));

// thread can go from RUNNABLE to WAITING to RUNNABLE to WAITING .....
Expand All @@ -553,7 +552,7 @@ public void run() {
},"wait for prompt");

// next prompt asks if cars are to be released from train by reset
pressDialogButton(Bundle.getMessage("buildResetTrain"), "Yes");
JemmyUtil.pressDialogButton(Bundle.getMessage("buildResetTrain"), "Yes");

jmri.util.JUnitUtil.waitFor(() -> {
return build.getState().equals(Thread.State.TERMINATED);
Expand Down Expand Up @@ -629,7 +628,7 @@ public void run() {
}, "wait for prompt");

// dialog remove engines from staging or continue by pressing OK
pressDialogButton(MessageFormat.format(Bundle.getMessage("buildErrorMsg"),
JemmyUtil.pressDialogButton(MessageFormat.format(Bundle.getMessage("buildErrorMsg"),
new Object[]{train2.getName(), train2.getDescription()}), Bundle.getMessage("ButtonOK"));

// thread can go from RUNNABLE to WAITING to RUNNABLE to WAITING .....
Expand All @@ -645,7 +644,7 @@ public void run() {
},"wait for prompt");

// next prompt asks if cars are to be released from train by reset
pressDialogButton(Bundle.getMessage("buildResetTrain"), "No");
JemmyUtil.pressDialogButton(Bundle.getMessage("buildResetTrain"), "No");

jmri.util.JUnitUtil.waitFor(() -> {
return build.getState().equals(Thread.State.TERMINATED);
Expand Down Expand Up @@ -678,14 +677,6 @@ public void setUp() throws Exception {
JUnitOperationsUtil.initOperationsData();
}

protected JDialogOperator pressDialogButton(String dialogTitle, String buttonName) {
JDialogOperator jdo = new JDialogOperator(dialogTitle); // wait for the first dialog.
JButtonOperator jbo = new JButtonOperator(jdo, buttonName);
// Click button
jbo.push();
return jdo;
}

@Override
@After
public void tearDown() throws Exception {
Expand Down
7 changes: 7 additions & 0 deletions java/test/jmri/util/swing/JemmyUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ static public void pressDialogButton(JmriJFrame f, String buttonName) {
// Click button
jbo.push();
}

static public void pressDialogButton(String dialogTitle, String buttonName) {
JDialogOperator jdo = new JDialogOperator(dialogTitle); // wait for the first dialog.
JButtonOperator jbo = new JButtonOperator(jdo, buttonName);
// Click button
jbo.push();
}

static public void pressDialogButton(JmriJFrame f, String dialogTitle, String buttonName) {
JFrameOperator jfo = new JFrameOperator(f);
Expand Down

0 comments on commit b8e54e2

Please sign in to comment.