@Test
  public void testRegisterMBean() throws Exception {
    RoundRobinSchedulerStats stats =
        EasyMock.createMockBuilder(RoundRobinSchedulerStats.class)
            .withConstructor()
            .addMockedMethod("getMBeanServer")
            .addMockedMethod("createObjectName")
            .createStrictMock();

    // do nothing
    stats.setUseJMX(false);
    EasyMock.replay(stats);
    stats.registerMBean();
    EasyMock.verify(stats);
    assertNull("Object name should still be null.", stats.m_mbeanName);

    // now work
    EasyMock.reset(stats);
    stats.setUseJMX(true);
    MBeanServer mbs = EasyMock.createStrictMock(MBeanServer.class);
    ObjectName objectName = EasyMock.createStrictMock(ObjectName.class);
    EasyMock.expect(stats.getMBeanServer()).andReturn(mbs);
    EasyMock.expect(stats.createObjectName()).andReturn(objectName);
    EasyMock.expect(mbs.registerMBean(stats, objectName)).andReturn(null);

    EasyMock.replay(stats, mbs, objectName);
    stats.registerMBean();
    EasyMock.verify(stats, mbs, objectName);
    assertEquals("Object name should not be null.", objectName, stats.m_mbeanName);

    // with exception that is just logged
    EasyMock.reset(stats, mbs, objectName);
    stats.m_mbeanName = null;
    EasyMock.expect(stats.getMBeanServer()).andReturn(mbs);
    EasyMock.expect(stats.createObjectName()).andReturn(objectName);
    EasyMock.expect(mbs.registerMBean(stats, objectName))
        .andThrow(new NotCompliantMBeanException("blah"));

    EasyMock.replay(stats, mbs, objectName);
    stats.registerMBean();
    EasyMock.verify(stats, mbs, objectName);
    assertNull("Object name should still be null.", stats.m_mbeanName);
  }
  @Test
  public void testConstructor() throws Exception {
    RoundRobinSchedulerStats stats = new RoundRobinSchedulerStats();
    assertFalse("JMX should not be enabled by default.", stats.isUseJMX());

    stats.setUseJMX(true);
    assertTrue("JMX should be enabled.", stats.isUseJMX());
    assertEquals("Wrong default mavg period.", 300000, stats.getAddMavgPeriod());
    assertNull("Mavg should not be created.", stats.m_addMavg);
    assertEquals("Wrong default mavg sample size.", 360, stats.getAddMavgSampleSize());
  }