Skip to content

Commit

Permalink
eliminate data files left behind by TimeTable tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
pabender committed Feb 28, 2019
1 parent 756cf65 commit e2f8b00
Show file tree
Hide file tree
Showing 12 changed files with 207 additions and 15 deletions.
9 changes: 7 additions & 2 deletions java/src/jmri/jmrit/timetable/configurexml/TimeTableXml.java
Expand Up @@ -433,8 +433,7 @@ public static boolean doLoad() {
}



private static class TimeTableXmlFile extends XmlFile {
public static class TimeTableXmlFile extends XmlFile {
private static String fileLocation = FileUtil.getUserFilesPath() + "timetable/"; // NOI18N
private static String demoLocation = FileUtil.getProgramPath() + "xml/demoTimetable/"; // NOI18N
private static String baseFileName = "TimeTableData.xml"; // NOI18N
Expand Down Expand Up @@ -477,6 +476,9 @@ public File getFile(boolean store) {
}

public static String getFileName() {
if(baseFileName == null) {
baseFileName = "TimeTableData.xml"; // NOI18N
}
return baseFileName;
}

Expand All @@ -486,6 +488,9 @@ public static String getFileName() {
* @return path to location
*/
public static String getFileLocation() {
if(fileLocation==null){
fileLocation = FileUtil.getUserFilesPath() + "timetable/"; // NOI18N
}
return fileLocation;
}
}
Expand Down
18 changes: 17 additions & 1 deletion java/test/jmri/jmrit/timetable/StopTest.java
Expand Up @@ -11,6 +11,9 @@
*/
public class StopTest {

@Rule
public org.junit.rules.TemporaryFolder folder = new org.junit.rules.TemporaryFolder();

@Test
public void testCreate() {
try {
Expand Down Expand Up @@ -85,11 +88,24 @@ public void setUp() {
jmri.util.JUnitUtil.setUp();

JUnitUtil.resetInstanceManager();
JUnitUtil.resetProfileManager();
try {
JUnitUtil.resetProfileManager(new jmri.profile.NullProfile(folder.newFolder(jmri.profile.Profile.PROFILE)));
} catch(java.io.IOException ioe){
Assert.fail("failed to setup profile for test");
}
}

@After
public void tearDown() {
// use reflection to reset the static file location.
try {
Class<?> c = jmri.jmrit.timetable.configurexml.TimeTableXml.TimeTableXmlFile.class;
java.lang.reflect.Field f = c.getDeclaredField("fileLocation");
f.setAccessible(true);
f.set(new String(), null);
} catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException x) {
Assert.fail("Failed to reset TimeTableXml static fileLocation " + x);
}
jmri.util.JUnitUtil.tearDown();
}
}
18 changes: 17 additions & 1 deletion java/test/jmri/jmrit/timetable/TimeTableCsvExportTest.java
Expand Up @@ -14,6 +14,9 @@
*/
public class TimeTableCsvExportTest {

@Rule
public org.junit.rules.TemporaryFolder folder = new org.junit.rules.TemporaryFolder();

@Test
public void testExport() {
TimeTableDataManager dm = new TimeTableDataManager(true);
Expand Down Expand Up @@ -74,11 +77,24 @@ public void setUp() {
jmri.util.JUnitUtil.setUp();

JUnitUtil.resetInstanceManager();
JUnitUtil.resetProfileManager();
try {
JUnitUtil.resetProfileManager(new jmri.profile.NullProfile(folder.newFolder(jmri.profile.Profile.PROFILE)));
} catch(java.io.IOException ioe){
Assert.fail("failed to setup profile for test");
}
}

@After
public void tearDown() {
// use reflection to reset the static file location.
try {
Class<?> c = jmri.jmrit.timetable.configurexml.TimeTableXml.TimeTableXmlFile.class;
java.lang.reflect.Field f = c.getDeclaredField("fileLocation");
f.setAccessible(true);
f.set(new String(), null);
} catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException x) {
Assert.fail("Failed to reset TimeTableXml static fileLocation " + x);
}
jmri.util.JUnitUtil.tearDown();
}

Expand Down
18 changes: 17 additions & 1 deletion java/test/jmri/jmrit/timetable/TimeTableCsvImportTest.java
Expand Up @@ -18,6 +18,9 @@
*/
public class TimeTableCsvImportTest {

@Rule
public org.junit.rules.TemporaryFolder folder = new org.junit.rules.TemporaryFolder();

@Test
public void testImport() {
TimeTableDataManager dm = new TimeTableDataManager(false);
Expand Down Expand Up @@ -161,11 +164,24 @@ public void setUp() {
jmri.util.JUnitUtil.setUp();

JUnitUtil.resetInstanceManager();
JUnitUtil.resetProfileManager();
try {
JUnitUtil.resetProfileManager(new jmri.profile.NullProfile(folder.newFolder(jmri.profile.Profile.PROFILE)));
} catch(java.io.IOException ioe){
Assert.fail("failed to setup profile for test");
}
}

@After
public void tearDown() {
// use reflection to reset the static file location.
try {
Class<?> c = jmri.jmrit.timetable.configurexml.TimeTableXml.TimeTableXmlFile.class;
java.lang.reflect.Field f = c.getDeclaredField("fileLocation");
f.setAccessible(true);
f.set(new String(), null);
} catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException x) {
Assert.fail("Failed to reset TimeTableXml static fileLocation " + x);
}
jmri.util.JUnitUtil.tearDown();
}
private final static org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(TimeTableCsvImportTest.class);
Expand Down
19 changes: 18 additions & 1 deletion java/test/jmri/jmrit/timetable/TimeTableDataManagerTest.java
Expand Up @@ -8,6 +8,9 @@
*/
public class TimeTableDataManagerTest {

@Rule
public org.junit.rules.TemporaryFolder folder = new org.junit.rules.TemporaryFolder();

@Test
public void testCreate() {
TimeTableDataManager dx = new TimeTableDataManager(false);
Expand Down Expand Up @@ -82,12 +85,26 @@ public void testExercise() {
@Before
public void setUp() {
jmri.util.JUnitUtil.setUp();
try {
jmri.util.JUnitUtil.resetProfileManager(new jmri.profile.NullProfile(folder.newFolder(jmri.profile.Profile.PROFILE)));
} catch(java.io.IOException ioe){
Assert.fail("failed to setup profile for test");
}
}

@After
public void tearDown() {
// use reflection to reset the static file location.
try {
Class<?> c = jmri.jmrit.timetable.configurexml.TimeTableXml.TimeTableXmlFile.class;
java.lang.reflect.Field f = c.getDeclaredField("fileLocation");
f.setAccessible(true);
f.set(new String(), null);
} catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException x) {
Assert.fail("Failed to reset TimeTableXml static fileLocation " + x);
}
jmri.util.JUnitUtil.tearDown();
}

// private final static org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(TimeTableDataManagerTest.class);
}
}
19 changes: 18 additions & 1 deletion java/test/jmri/jmrit/timetable/TimeTableImportTest.java
Expand Up @@ -12,6 +12,9 @@
*/
public class TimeTableImportTest {

@Rule
public org.junit.rules.TemporaryFolder folder = new org.junit.rules.TemporaryFolder();

@Test
public void testCreate() {
new TimeTableImport();
Expand Down Expand Up @@ -53,11 +56,25 @@ public void testImport() {
@Before
public void setUp() {
jmri.util.JUnitUtil.setUp();
try {
jmri.util.JUnitUtil.resetProfileManager(new jmri.profile.NullProfile(folder.newFolder(jmri.profile.Profile.PROFILE)));
} catch(java.io.IOException ioe){
Assert.fail("failed to setup profile for test");
}
}

@After
public void tearDown() {
// use reflection to reset the static file location.
try {
Class<?> c = jmri.jmrit.timetable.configurexml.TimeTableXml.TimeTableXmlFile.class;
java.lang.reflect.Field f = c.getDeclaredField("fileLocation");
f.setAccessible(true);
f.set(new String(), null);
} catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException x) {
Assert.fail("Failed to reset TimeTableXml static fileLocation " + x);
}
jmri.util.JUnitUtil.tearDown();
}
private final static org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(TimeTableImportTest.class);
}
}
21 changes: 20 additions & 1 deletion java/test/jmri/jmrit/timetable/TrainTest.java
@@ -1,5 +1,6 @@
package jmri.jmrit.timetable;

import jmri.util.JUnitUtil;
import org.junit.*;

/**
Expand All @@ -8,6 +9,9 @@
*/
public class TrainTest {

@Rule
public org.junit.rules.TemporaryFolder folder = new org.junit.rules.TemporaryFolder();

@Test
public void testCreate() {
try {
Expand Down Expand Up @@ -70,10 +74,25 @@ public void testSettersAndGetters() {
@Before
public void setUp() {
jmri.util.JUnitUtil.setUp();
JUnitUtil.resetInstanceManager();
try {
JUnitUtil.resetProfileManager(new jmri.profile.NullProfile(folder.newFolder(jmri.profile.Profile.PROFILE)));
} catch(java.io.IOException ioe){
Assert.fail("failed to setup profile for test");
}
}

@After
public void tearDown() {
// use reflection to reset the static file location.
try {
Class<?> c = jmri.jmrit.timetable.configurexml.TimeTableXml.TimeTableXmlFile.class;
java.lang.reflect.Field f = c.getDeclaredField("fileLocation");
f.setAccessible(true);
f.set(new String(), null);
} catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException x) {
Assert.fail("Failed to reset TimeTableXml static fileLocation " + x);
}
jmri.util.JUnitUtil.tearDown();
}
}
}
20 changes: 19 additions & 1 deletion java/test/jmri/jmrit/timetable/TrainTypeTest.java
@@ -1,5 +1,6 @@
package jmri.jmrit.timetable;

import jmri.util.JUnitUtil;
import org.junit.*;

/*
Expand All @@ -8,6 +9,9 @@
*/
public class TrainTypeTest {

@Rule
public org.junit.rules.TemporaryFolder folder = new org.junit.rules.TemporaryFolder();

@Test
public void testCreate() {
try {
Expand All @@ -32,10 +36,24 @@ public void testSettersAndGetters() {
@Before
public void setUp() {
jmri.util.JUnitUtil.setUp();
try {
JUnitUtil.resetProfileManager(new jmri.profile.NullProfile(folder.newFolder(jmri.profile.Profile.PROFILE)));
} catch(java.io.IOException ioe){
Assert.fail("failed to setup profile for test");
}
}

@After
public void tearDown() {
// use reflection to reset the static file location.
try {
Class<?> c = jmri.jmrit.timetable.configurexml.TimeTableXml.TimeTableXmlFile.class;
java.lang.reflect.Field f = c.getDeclaredField("fileLocation");
f.setAccessible(true);
f.set(new String(), null);
} catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException x) {
Assert.fail("Failed to reset TimeTableXml static fileLocation " + x);
}
jmri.util.JUnitUtil.tearDown();
}
}
}
20 changes: 18 additions & 2 deletions java/test/jmri/jmrit/timetable/configurexml/TimeTableXmlTest.java
Expand Up @@ -12,6 +12,9 @@
*/
public class TimeTableXmlTest {

@Rule
public org.junit.rules.TemporaryFolder folder = new org.junit.rules.TemporaryFolder();

@Test
public void testCreate() {
new TimeTableXml();
Expand All @@ -33,11 +36,24 @@ public void setUp() {
jmri.util.JUnitUtil.setUp();

JUnitUtil.resetInstanceManager();
JUnitUtil.resetProfileManager();
try {
JUnitUtil.resetProfileManager(new jmri.profile.NullProfile(folder.newFolder(jmri.profile.Profile.PROFILE)));
} catch(java.io.IOException ioe){
Assert.fail("failed to setup profile for test");
}
}

@After
public void tearDown() {
// use reflection to reset the static file location.
try {
Class<?> c = jmri.jmrit.timetable.configurexml.TimeTableXml.TimeTableXmlFile.class;
java.lang.reflect.Field f = c.getDeclaredField("fileLocation");
f.setAccessible(true);
f.set(new String(), null);
} catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException x) {
Assert.fail("Failed to reset TimeTableXml static fileLocation " + x);
}
jmri.util.JUnitUtil.tearDown();
}
}
}
21 changes: 20 additions & 1 deletion java/test/jmri/jmrit/timetable/swing/TimeTableActionTest.java
@@ -1,6 +1,7 @@
package jmri.jmrit.timetable.swing;

import java.awt.GraphicsEnvironment;
import jmri.util.JUnitUtil;
import org.junit.*;
import org.junit.rules.ExpectedException;

Expand All @@ -10,6 +11,9 @@
*/
public class TimeTableActionTest {

@Rule
public org.junit.rules.TemporaryFolder folder = new org.junit.rules.TemporaryFolder();

@Rule
public final ExpectedException thrown = ExpectedException.none();

Expand All @@ -36,10 +40,25 @@ public void testMakePanel() {
@Before
public void setUp() {
jmri.util.JUnitUtil.setUp();
JUnitUtil.resetInstanceManager();
try {
JUnitUtil.resetProfileManager(new jmri.profile.NullProfile(folder.newFolder(jmri.profile.Profile.PROFILE)));
} catch(java.io.IOException ioe){
Assert.fail("failed to setup profile for test");
}
}

@After
public void tearDown() {
// use reflection to reset the static file location.
try {
Class<?> c = jmri.jmrit.timetable.configurexml.TimeTableXml.TimeTableXmlFile.class;
java.lang.reflect.Field f = c.getDeclaredField("fileLocation");
f.setAccessible(true);
f.set(new String(), null);
} catch (NoSuchFieldException | IllegalArgumentException | IllegalAccessException x) {
Assert.fail("Failed to reset TimeTableXml static fileLocation " + x);
}
jmri.util.JUnitUtil.tearDown();
}
}
}

0 comments on commit e2f8b00

Please sign in to comment.