コード例 #1
0
  @Test
  public void testStop() throws Exception {
    RoundRobinSchedulerStats stats =
        EasyMock.createMockBuilder(RoundRobinSchedulerStats.class)
            .withConstructor()
            .addMockedMethod("unregisterMBean")
            .createStrictMock();

    MovingAverage mavg = EasyMock.createStrictMock(MovingAverage.class);
    stats.m_addMavg = mavg;
    stats.m_addMavg.stopTimer();
    EasyMock.expectLastCall();
    stats.unregisterMBean();
    EasyMock.expectLastCall();

    EasyMock.replay(stats, mavg);
    stats.stop();
    EasyMock.verify(stats, mavg);
    assertNull("Mavg should be null.", stats.m_addMavg);

    // with no avg
    EasyMock.reset(stats);
    EasyMock.replay(stats);
    stats.stop();
    EasyMock.verify(stats);
  }
コード例 #2
0
  @Test
  public void testUnregisterMBean() throws Exception {
    RoundRobinSchedulerStats stats =
        EasyMock.createMockBuilder(RoundRobinSchedulerStats.class)
            .withConstructor()
            .addMockedMethod("getMBeanServer")
            .createStrictMock();

    // do nothing
    EasyMock.replay(stats);
    stats.unregisterMBean();
    EasyMock.verify(stats);

    // now work
    stats.m_mbeanName = stats.createObjectName();
    EasyMock.reset(stats);
    MBeanServer mbs = EasyMock.createStrictMock(MBeanServer.class);
    EasyMock.expect(stats.getMBeanServer()).andReturn(mbs);
    mbs.unregisterMBean(stats.m_mbeanName);
    EasyMock.expectLastCall();

    EasyMock.replay(stats, mbs);
    stats.unregisterMBean();
    EasyMock.verify(stats, mbs);
    assertNull("Object name should be null.", stats.m_mbeanName);

    // with exception that is just logged
    stats.m_mbeanName = stats.createObjectName();
    EasyMock.reset(stats, mbs);
    EasyMock.expect(stats.getMBeanServer()).andReturn(mbs);
    mbs.unregisterMBean(stats.m_mbeanName);
    EasyMock.expectLastCall().andThrow(new MBeanRegistrationException(new Exception()));

    EasyMock.replay(stats, mbs);
    stats.unregisterMBean();
    EasyMock.verify(stats, mbs);
    assertNull("Object name should be null.", stats.m_mbeanName);
  }