### Question:
StopWatch extends ThresholdWatch implements StopWatchMBean { public void stopTiming() { long now = System.currentTimeMillis(); long startTime = getStartTime(); long elapsed = now - startTime; setElapsedTime(elapsed, now); } StopWatch(String id);  StopWatch(String id, Configuration config); @SuppressWarnings("unused")  StopWatch(WatchDataSource watchDataSource, String id); void startTiming(); void stopTiming(); void stopTiming(String detail); void setElapsedTime(long elapsed); void setElapsedTime(long elapsed, String detail); void setElapsedTime(long elapsed, long now); void setElapsedTime(long elapsed, long now, String detail); long getStartTime(); void setStartTime(long startTime); static final String VIEW; }### Answer:
@Test public void testStopTiming() throws RemoteException { StopWatch watch = new StopWatch("watch"); DataSourceMonitor mon = new DataSourceMonitor(watch); checkData(0, watch); for (int i = 0; i < 10; i++) { Utils.sleep(100); watch.stopTiming(); mon.waitFor(i + 1); Calculable[] calcs = watch.getWatchDataSource().getCalculable(); Assert.assertEquals(i + 1, calcs.length); Assert.assertTrue(calcs[0].getValue() > 0); for (int j = 1; j < calcs.length; j++) { Assert.assertTrue(calcs[j].getValue() >= calcs[j - 1].getValue()); } } for (int i = 0; i < 10; i++) { watch.startTiming(); Utils.sleep(100); watch.stopTiming(); checkData(10 + i + 1, watch); } Utils.close(watch.getWatchDataSource()); }