Skip to content
Permalink
Browse files

test: Initialize RosterConfigManager where needed

  • Loading branch information...
rhwood committed Aug 6, 2019
1 parent 2216801 commit 65e9329dbcf643aa999c68cd8c3c7ce8313cfbb8
@@ -177,6 +177,7 @@ public void testIsValidAddress() throws NoSuchMethodException, IllegalAccessExce
@Before
public void setUp() throws Exception {
JUnitUtil.setUp();
JUnitUtil.initRosterConfigManager();
InstanceManager.setDefault(NamedBeanHandleManager.class, new NamedBeanHandleManager());
InstanceManager.setDefault(WiThrottlePreferences.class, new WiThrottlePreferences());
JUnitUtil.initDebugThrottleManager();
@@ -25,6 +25,7 @@ public void setUp() {
JUnitUtil.setUp();
jmri.util.JUnitUtil.resetProfileManager();
jmri.util.JUnitUtil.initDebugCommandStation();
JUnitUtil.initRosterConfigManager();
InstanceManager.setDefault(ConsistManager.class, new TestConsistManager());
}

@@ -18,6 +18,7 @@
public void setUp() {
JUnitUtil.setUp();
JUnitUtil.resetProfileManager();
JUnitUtil.initRosterConfigManager();
InstanceManager.setDefault(ConsistPreferencesManager.class,new ConsistPreferencesManager());
jmri.util.JUnitUtil.initDebugCommandStation();
jmri.DccLocoAddress addr = new jmri.DccLocoAddress(123, false);
@@ -74,6 +74,7 @@
public void setUp() {
JUnitUtil.setUp();
JUnitUtil.resetProfileManager();
JUnitUtil.initRosterConfigManager();
InstanceManager.setDefault(ConsistPreferencesManager.class,new ConsistPreferencesManager());
_memo = new EasyDccSystemConnectionMemo("E", "EasyDCC Test");
_memo.setEasyDccTrafficController(new EasyDccTrafficControlScaffold(_memo));
@@ -2,12 +2,13 @@

import jmri.InstanceManager;
import jmri.jmrit.consisttool.ConsistPreferencesManager;
import jmri.util.JUnitUtil;
import jmri.util.junit.annotations.*;
import org.junit.*;

/**
* XNetConsistTest.java
*
* <p>
* Description: tests for the jmri.jmrix.lenz.XNetConsist class
*
* @author Paul Bender Copyright (C) 2010,2016,2017
@@ -18,109 +19,117 @@
private XNetInterfaceScaffold tc = null;
private XNetSystemConnectionMemo memo = null;

@Test public void dccLocoAddressConstructorTest() {
jmri.DccLocoAddress addr = new jmri.DccLocoAddress(5,false);
@Test
public void dccLocoAddressConstructorTest() {
jmri.DccLocoAddress addr = new jmri.DccLocoAddress(5, false);

XNetConsist ac = new XNetConsist(addr, tc, memo);
Assert.assertNotNull(ac);
}

@Override
@Test(expected=java.lang.NullPointerException.class)
public void checkDisposeMethod(){
@Test(expected = java.lang.NullPointerException.class)
public void checkDisposeMethod() {
// verify that c has been added to the traffic controller's
// list of listeners.
int listeners = tc.numListeners();

jmri.DccLocoAddress A = new jmri.DccLocoAddress(200,true);
jmri.DccLocoAddress B = new jmri.DccLocoAddress(250,true);
c.restore(A,true); // use restore here, as it does not send
// any data to the command station
c.restore(B,false); // use restore here, as it does not send
// any data to the command station
jmri.DccLocoAddress A = new jmri.DccLocoAddress(200, true);
jmri.DccLocoAddress B = new jmri.DccLocoAddress(250, true);
c.restore(A, true); // use restore here, as it does not send
// any data to the command station
c.restore(B, false); // use restore here, as it does not send
// any data to the command station
// before dispose, this should succeed.
Assert.assertTrue("Advanced Consist Contains",c.contains(A));
Assert.assertTrue("Advanced Consist Contains",c.contains(B));
Assert.assertTrue("Advanced Consist Contains", c.contains(A));
Assert.assertTrue("Advanced Consist Contains", c.contains(B));

c.dispose();
Assert.assertEquals("dispose check",listeners -1, tc.numListeners());
Assert.assertEquals("dispose check", listeners - 1, tc.numListeners());

// after dispose, this should fail
Assert.assertTrue("Advanced Consist Contains",c.contains(A));
Assert.assertTrue("Advanced Consist Contains",c.contains(B));
Assert.assertTrue("Advanced Consist Contains", c.contains(A));
Assert.assertTrue("Advanced Consist Contains", c.contains(B));

}

@Override
@Test public void testSetConsistTypeCS(){
@Test
public void testSetConsistTypeCS() {
c.setConsistType(jmri.Consist.CS_CONSIST);
Assert.assertEquals("CS consist type",jmri.Consist.CS_CONSIST,c.getConsistType());
Assert.assertEquals("CS consist type", jmri.Consist.CS_CONSIST, c.getConsistType());
}

@Test public void checkSizeLimitCS(){
@Test
public void checkSizeLimitCS() {
c.setConsistType(jmri.Consist.CS_CONSIST);
Assert.assertEquals("CS Consist Limit",2,c.sizeLimit());
}
Assert.assertEquals("CS Consist Limit", 2, c.sizeLimit());
}

@Test public void checkContainsCS(){
@Test
public void checkContainsCS() {
c.setConsistType(jmri.Consist.CS_CONSIST);
jmri.DccLocoAddress A = new jmri.DccLocoAddress(200,true);
jmri.DccLocoAddress B = new jmri.DccLocoAddress(250,true);
jmri.DccLocoAddress A = new jmri.DccLocoAddress(200, true);
jmri.DccLocoAddress B = new jmri.DccLocoAddress(250, true);
// nothing added, should be false for all.
Assert.assertFalse("CS Consist Contains",c.contains(A));
Assert.assertFalse("CS Consist Contains",c.contains(B));
Assert.assertFalse("CS Consist Contains", c.contains(A));
Assert.assertFalse("CS Consist Contains", c.contains(B));
// add just A
c.restore(A,true); // use restore here, as it does not send
// any data to the command station
Assert.assertTrue("CS Consist Contains",c.contains(A));
Assert.assertFalse("CS Consist Contains",c.contains(B));
c.restore(A, true); // use restore here, as it does not send
// any data to the command station
Assert.assertTrue("CS Consist Contains", c.contains(A));
Assert.assertFalse("CS Consist Contains", c.contains(B));
// then add B
c.restore(B,false);
Assert.assertTrue("CS Consist Contains",c.contains(A));
Assert.assertTrue("CS Consist Contains",c.contains(B));
c.restore(B, false);
Assert.assertTrue("CS Consist Contains", c.contains(A));
Assert.assertTrue("CS Consist Contains", c.contains(B));
}

@Test public void checkGetLocoDirectionCS(){
@Test
public void checkGetLocoDirectionCS() {
c.setConsistType(jmri.Consist.CS_CONSIST);
jmri.DccLocoAddress A = new jmri.DccLocoAddress(200,true);
jmri.DccLocoAddress B = new jmri.DccLocoAddress(250,true);
c.restore(A,true); // use restore here, as it does not send
// any data to the command station
c.restore(B,false); // revese direction.
Assert.assertTrue("Direction in CS Consist",c.getLocoDirection(A));
Assert.assertFalse("Direction in CS Consist",c.getLocoDirection(B));
jmri.DccLocoAddress A = new jmri.DccLocoAddress(200, true);
jmri.DccLocoAddress B = new jmri.DccLocoAddress(250, true);
c.restore(A, true); // use restore here, as it does not send
// any data to the command station
c.restore(B, false); // revese direction.
Assert.assertTrue("Direction in CS Consist", c.getLocoDirection(A));
Assert.assertFalse("Direction in CS Consist", c.getLocoDirection(B));
}

@Test
@Ignore("Remove requires response from command station")
@ToDo("re-write parent class test here and include simulated command station response")
public void checkRemoveWithGetRosterIDAdvanced(){
@ToDo("re-write parent class test here and include simulated command station response")
@Override
public void checkRemoveWithGetRosterIDAdvanced() {
}

@Test
@Ignore("Remove requires response from command station")
@ToDo("re-write parent class test here and include simulated command station response")
public void checkAddRemoveWithRosterUpdateAdvanced(){
@ToDo("re-write parent class test here and include simulated command station response")
@Override
public void checkAddRemoveWithRosterUpdateAdvanced() {
}

// The minimal setup for log4J
@Before
@Override
public void setUp() {
jmri.util.JUnitUtil.setUp();
jmri.util.JUnitUtil.resetProfileManager();
InstanceManager.setDefault(ConsistPreferencesManager.class,new ConsistPreferencesManager());
JUnitUtil.setUp();
JUnitUtil.resetProfileManager();
JUnitUtil.initRosterConfigManager();
InstanceManager.setDefault(ConsistPreferencesManager.class, new ConsistPreferencesManager());
tc = new XNetInterfaceScaffold(new LenzCommandStation());
memo = new XNetSystemConnectionMemo(tc);
c = new XNetConsist(5, tc, memo);
}

@After
@Override
public void tearDown() {
jmri.util.JUnitUtil.tearDown();
tc=null;
memo=null;
JUnitUtil.tearDown();
tc = null;
memo = null;
}

}
@@ -111,6 +111,7 @@ public void testSetConsistTypeCS(){
public void setUp() {
JUnitUtil.setUp();
JUnitUtil.resetProfileManager();
JUnitUtil.initRosterConfigManager();
InstanceManager.setDefault(ConsistPreferencesManager.class,new ConsistPreferencesManager());
// prepare an interface
lnis = new LocoNetInterfaceScaffold();
@@ -94,6 +94,7 @@ public void checkAddRemoveWithRosterUpdateAdvanced(){
public void setUp() {
JUnitUtil.setUp();
JUnitUtil.resetProfileManager();
JUnitUtil.initRosterConfigManager();
InstanceManager.setDefault(ConsistPreferencesManager.class,new ConsistPreferencesManager());
// prepare an interface
nnis = new NceInterfaceScaffold();
@@ -16,7 +16,7 @@
public void setUp() {
JUnitUtil.setUp();
jmri.util.JUnitUtil.resetProfileManager();

JUnitUtil.initRosterConfigManager();
panel = new NceConsistEditPanel();
helpTarget="package.jmri.jmrix.nce.consist.NceConsistEditFrame";
title="NCE_: Edit NCE Consist";
@@ -23,6 +23,7 @@ public void testCTor() {
public void setUp() {
JUnitUtil.setUp();
jmri.util.JUnitUtil.resetProfileManager();
JUnitUtil.initRosterConfigManager();
}

@After
@@ -31,6 +31,7 @@ public void setUp() throws IOException {
JUnitUtil.setUp();
JUnitUtil.resetProfileManager(
new NullProfile("JsonClientHandlerTest", "12345678", FileUtil.getFile("program:test")));
JUnitUtil.initRosterConfigManager();
}

@After
@@ -338,6 +338,7 @@ public void testRequestEmptyThrottle() throws IOException, JmriException {
public void setUp() {
JUnitUtil.setUp();
JUnitUtil.resetProfileManager();
JUnitUtil.initRosterConfigManager();
JUnitUtil.initDebugThrottleManager();
}

@@ -208,6 +208,7 @@ public void testFunctionKeys() throws JsonException {
public void setUp() {
JUnitUtil.setUp();
JUnitUtil.resetProfileManager();
JUnitUtil.initRosterConfigManager();
JUnitUtil.initDebugCommandStation();
InstanceManager.store(new TestThrottleManager(), ThrottleManager.class);
}

0 comments on commit 65e9329

Please sign in to comment.
You can’t perform that action at this time.