Skip to content
Permalink
Browse files

new tests for reporters

  • Loading branch information...
pabender committed Oct 6, 2018
1 parent b4ebf8d commit 6acd8ffc0220b4d401b8b0715e7fa15b334ad4ba
@@ -1,39 +1,31 @@
package jmri.implementation;

import jmri.util.JUnitUtil;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.*;
/**
*
* @author Paul Bender Copyright (C) 2017
*/
public class AbstractRailComReporterTest {
public class AbstractRailComReporterTest extends AbstractReporterTestBase {

@Test
public void testCTor() {
AbstractRailComReporter t = new AbstractRailComReporter("IR1");
Assert.assertNotNull("exists",t);
@Override
protected Object generateObjectToReport(){
return new DefaultRailCom("ID1234", "Test Tag");
}

@Test
public void testGetBeanType(){
AbstractRailComReporter t = new AbstractRailComReporter("IR1");
Assert.assertEquals("bean type",t.getBeanType(),Bundle.getMessage("BeanNameReporter"));
}

// The minimal setup for log4J
@Before
@Override
public void setUp() {
JUnitUtil.setUp();
r = new AbstractRailComReporter("IR1");
}

@After
@Override
public void tearDown() {
r = null;
JUnitUtil.tearDown();
}

//private final static Logger log = LoggerFactory.getLogger(AbstractRailComReporterTest.class);

}
@@ -0,0 +1,71 @@
package jmri.implementation;

import jmri.Reporter;
import org.junit.*;

/**
* Tests for the Reporter class
* <hr>
* This file is part of JMRI.
* <P>
* JMRI is free software; you can redistribute it and/or modify it under the
* terms of version 2 of the GNU General Public License as published by the Free
* Software Foundation. See the "COPYING" file for a copy of this license.
* <P>
* JMRI is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU General Public License for more details.
* <P>
*
* @author Matthew Harris Copyright (C) 2011
* @author Paul Bender Copyright (C) 2018
*/
abstract public class AbstractReporterTestBase {

// concrete classes should create r in setUp and remove in tearDown
protected Reporter r = null;

// concrete classes should generate an appropriate report.
abstract protected Object generateObjectToReport();

@Test
public void testCtor() {
// Check that it is not a null object
Assert.assertNotNull("Created Reporter not null", r);
// Check that CurrentReport and LastReport return a null object
Assert.assertNull("CurrentReport at initialisation is 'null'", r.getCurrentReport());
Assert.assertNull("LastReport at initialisation is 'null'", r.getLastReport());
}

@Test
public void testReport() {
// Report a String
r.setReport(generateObjectToReport());
// Check that both CurrentReport and LastReport are not null
Assert.assertNotNull("CurrentReport Object exists", r.getCurrentReport());
Assert.assertNotNull("LastReport Object exists", r.getLastReport());
// Check the value of both CurrentReport and LastReport
Assert.assertEquals("CurrentReport equals LastReport",r.getLastReport(), r.getCurrentReport());

// Nothing to report now
r.setReport(null);
// Check that CurrentReport returns a null value, but LastReport returns the reported String
Assert.assertNull("After null report, CurrentReport is null", r.getCurrentReport());
Assert.assertNotNull("After null report, LastReport String is not null",r.getLastReport());
}

@Test
public void testGetBeanType(){
AbstractRailComReporter t = new AbstractRailComReporter("IR1");
Assert.assertEquals("bean type",t.getBeanType(),Bundle.getMessage("BeanNameReporter"));
}

@Before
abstract public void setUp();

@After
abstract public void tearDown();

}


@@ -1,10 +1,7 @@
package jmri.implementation;

import jmri.Reporter;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.junit.Assert;
import org.junit.*;

/**
* Tests for the Reporter class
@@ -22,11 +19,12 @@
*
* @author Matthew Harris Copyright (C) 2011
*/
public class ReporterTest extends TestCase {
public class ReporterTest {

private Reporter r = null;

@Test
public void testReporterCreation() {
// Create a new reporter
Reporter r = createNewReporter("SYS", "usr");
// Check that it is not a null object
Assert.assertNotNull("Created Reporter not null", r);
// Check that the SystemName and UserName is as specified
@@ -37,10 +35,8 @@ public void testReporterCreation() {
Assert.assertNull("LastReport at initialisation is 'null'", r.getLastReport());
}

@Test
public void testReportStringObject() {
// Create a new reporter
Reporter r = createNewReporter("SYS", "usr");

// Report a String
r.setReport("Something To Report");
// Check that both CurrentReport and LastReport are String objects
@@ -57,10 +53,8 @@ public void testReportStringObject() {
Assert.assertEquals("After null report, LastReport String is 'Something To Report'", "Something To Report", r.getLastReport());
}

@Test
public void testReportOtherObject() {
// Create a new reporter
Reporter r = createNewReporter("SYS", "usr");

// Create an ObjectToReport object to report
ObjectToReport otr = new ObjectToReport(42);
// and report it.
@@ -90,9 +84,10 @@ public void testReportOtherObject() {
Assert.assertSame("After null report, LastReport Object is identical to otr", otr, r.getLastReport());
}

// Utility method to create a concrete AbstractReporter
private Reporter createNewReporter(String systemName, String userName) {
return new AbstractReporter(systemName, userName) {
@Before
public void setUp(){
jmri.util.JUnitUtil.setUp();
r = new AbstractReporter("SYS", "usr") {
@Override
public int getState() {
return state;
@@ -106,6 +101,12 @@ public void setState(int s) {
};
}

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

// Utility class for testing reporter
public static class ObjectToReport {

@@ -119,24 +120,6 @@ public int getValue() {
return this.value;
}
}

// from here down is testing infrastructure
public ReporterTest(String s) {
super(s);
}

// Main entry point
static public void main(String[] args) {
String[] testCaseName = {ReporterTest.class.getName()};
junit.textui.TestRunner.main(testCaseName);
}

// test suite from all defined tests
public static Test suite() {
TestSuite suite = new TestSuite(ReporterTest.class);
return suite;
}

}


@@ -11,22 +11,23 @@
*
* @author Paul Bender Copyright (C) 2017
*/
public class CbusReporterTest {
public class CbusReporterTest extends jmri.implementation.AbstractReporterTestBase {

@Test
public void testCTor() {
CbusReporter t = new CbusReporter(1,new TrafficControllerScaffold(),"Test");
Assert.assertNotNull("exists",t);
@Override
protected Object generateObjectToReport(){
return new jmri.implementation.DefaultIdTag("ID0413276BC1", "Test Tag");
}

// The minimal setup for log4J
@Before
public void setUp() {
JUnitUtil.setUp();
r = new CbusReporter(1,new TrafficControllerScaffold(),"Test");
}

@After
public void tearDown() {
r = null;
JUnitUtil.tearDown();
}

@@ -10,21 +10,17 @@
*
* @author Paul Bender Copyright (C) 2017
*/
public class Dcc4PcReporterTest {
public class Dcc4PcReporterTest extends jmri.implementation.AbstractRailComReporterTest {

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

// The minimal setup for log4J
@Before
@Override
public void setUp() {
r = new Dcc4PcReporter("DR1","test");
JUnitUtil.setUp();
}

@After
@Override
public void tearDown() {
JUnitUtil.tearDown();
}
@@ -10,21 +10,18 @@
*
* @author Paul Bender Copyright (C) 2017
*/
public class EcosReporterTest {

@Test
public void testCTor() {
EcosReporter t = new EcosReporter("UR1","Test");
Assert.assertNotNull("exists",t);
}
public class EcosReporterTest extends jmri.implementation.AbstractRailComReporterTest {

// The minimal setup for log4J
@Before
@Override
public void setUp() {
JUnitUtil.setUp();
r = new EcosReporter("UR1","Test");
}

@After
@Override
public void tearDown() {
JUnitUtil.tearDown();
}
@@ -1,10 +1,7 @@
package jmri.jmrix.jmriclient;

import jmri.util.JUnitUtil;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.junit.Assert;
import org.junit.*;

/**
* JMRIClientReporterTest.java
@@ -13,45 +10,30 @@
*
* @author Bob Jacobsen
*/
public class JMRIClientReporterTest extends TestCase {
public class JMRIClientReporterTest extends jmri.implementation.AbstractReporterTestBase{

public void testCtor() {
@Override
protected Object generateObjectToReport(){
return new jmri.implementation.DefaultIdTag("ID0413276BC1", "Test Tag");
}

@Before
@Override
public void setUp() {
JUnitUtil.setUp();
JMRIClientTrafficController tc = new JMRIClientTrafficController() {
@Override
public void sendJMRIClientMessage(JMRIClientMessage m, JMRIClientListener reply) {
// do nothing to avoid null pointer when sending to non-existant
// connection during test.
}
};
JMRIClientReporter m = new JMRIClientReporter(3, new JMRIClientSystemConnectionMemo(tc));
Assert.assertNotNull(m);
}

// from here down is testing infrastructure
public JMRIClientReporterTest(String s) {
super(s);
}

// Main entry point
static public void main(String[] args) {
String[] testCaseName = {"-noloading", JMRIClientReporterTest.class.getName()};
junit.textui.TestRunner.main(testCaseName);
}

// test suite from all defined tests
public static Test suite() {
TestSuite suite = new TestSuite(JMRIClientReporterTest.class);
return suite;
}

// The minimal setup for log4J
@Override
protected void setUp() {
JUnitUtil.setUp();
r = new JMRIClientReporter(3, new JMRIClientSystemConnectionMemo(tc));
}

@Override
protected void tearDown() {
public void tearDown() {
r = null;
JUnitUtil.tearDown();
}

0 comments on commit 6acd8ff

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