GenericStatsImplTestpublic class GenericStatsImplTest extends TestCase Tests the class GenericStatsImplTescc.
No need to import the class being tested, as the package name is the same. |
Constructors Summary |
---|
public GenericStatsImplTest(String testName)
super(testName);
|
Methods Summary |
---|
private EJBStats | createEjbStatsProvider()
return new EjbStatsImpl();
| public static void | main(java.lang.String[] args)
junit.textui.TestRunner.run(suite());
//junicc.swingui.TestRunner.run(suite());
| protected void | setUp()
| public static junit.framework.Test | suite()
TestSuite suite = new TestSuite(GenericStatsImplTest.class);
return suite;
| protected void | tearDown()
| public void | testCorrectClassNameConstructor()
try {
final String c = "javax.management.j2ee.statistics.EJBStats";
final EJBStats provider = createEjbStatsProvider();
final Stats stats = new GenericStatsImpl(c, provider);
assertNotNull("Object is not null", stats);
}
catch (Exception e) {
// It should never get here as this should never be exceptional
}
| public void | testGetAStatisticWithEjbStats()
try {
final String c = "javax.management.j2ee.statistics.EJBStats";
final EJBStats provider = createEjbStatsProvider();
final Stats stats = new GenericStatsImpl(c, provider);
final String[] names = new String[]{"CreateCount", "RemoveCount"};
final CountStatistic c1 = new CountStatisticImpl(10, names[0], "", "Beans Created", 10, 10);
final CountStatistic c2 = new CountStatisticImpl(5, names[1], "", "Beans Removed", 10, 10);
/* tests for equality */
final CountStatistic cc = (CountStatistic)stats.getStatistic(names[0]);
final CountStatistic rc = (CountStatistic)stats.getStatistic(names[1]);
assertEquals(c1.getCount(), cc.getCount());
assertEquals(c1.getName(), cc.getName());
final CountStatistic u = (CountStatistic)stats.getStatistic(names[1]);
assertEquals(c2.getCount(), rc.getCount());
assertEquals(c2.getName(), rc.getName());
/* tests for inequality */
final CountStatistic c3 = new CountStatisticImpl(1111, names[0], "", "Beans Created", 10, 10);
final CountStatistic c4 = new CountStatisticImpl(444, names[1], "", "Beans Removed", 10, 10);
assertTrue(c3.getCount() != cc.getCount());
assertTrue(c4.getCount() != rc.getCount());
}
catch (Exception e) {
// It should never get here as this should never be exceptional
}
| public void | testGetStatisticNamesWithEjbStats()
try {
final String c = "javax.management.j2ee.statistics.EJBStats";
final EJBStats provider = createEjbStatsProvider();
final Stats stats = new GenericStatsImpl(c, provider);
final String[] s1 = stats.getStatisticNames();
final String[] s2 = new String[]{"CreateCount", "RemoveCount"};
final List ls1 = Arrays.asList(s1);
final List ls2 = Arrays.asList(s2);
assertTrue(ls1.containsAll(ls2)); //order is unimportant
assertEquals(s1.length, s2.length);
}
catch (Exception e) {
// It should never get here as this should never be exceptional
}
| public void | testInCorrectClassNameConstructor()
try {
final String invalid = "javax.management.j2ee.statistics.UnknownStats";
final EJBStats provider = createEjbStatsProvider();
final Stats stats = new GenericStatsImpl(invalid, provider);
fail("How can javax.management.j2ee.statistics.UnknownStats be impl????");
}
catch (Exception e) {
//We always should get this exception -- so this test should PASS.
}
| public void | testInvalidInterface()
try {
final String invalid = "java.io.Serializable";
final EJBStats provider = createEjbStatsProvider();
final Stats stats = new GenericStatsImpl(invalid, provider);
fail("We have not committed to java.io.Serializable as it is not a Stats interface");
}
catch (Exception e) {
//We always should get this exception -- so this test should PASS.
}
|
|