### Question:
EnforceCommand extends BaseCommand<T> { HTTPServer metricServer(int port) throws IOException { return new HTTPServer(port, true); } protected  EnforceCommand();   EnforceCommand(Enforcer<T> enforcer, Map<String, Object> cmdConfig, boolean continuous, int interval); @Override int run();  }### Answer:
@Test public void testMetricServer() throws IOException { EnforceCommand<Dummy> command = spy(new EnforceCommand<>(enforcer, config, true, 0)); doReturn(metricServer).when(command).metricServer(anyInt()); check(command, 1); verify(metricServer).stop(); verifyNoMoreInteractions(metricServer); }
@Test public void testNoMetricServer() throws IOException { EnforceCommand<Dummy> command = spy(new EnforceCommand<>(enforcer, config, false, 0)); verify(command, never()).metricServer(anyInt()); }
@Test public void testAbortIfMetricServerFails() throws IOException { EnforceCommand<Dummy> command = spy(new EnforceCommand<>(enforcer, config, true, 0)); doThrow(new IOException("failed")).when(command).metricServer(anyInt()); check(command, 0); verify(command).metricServer(anyInt()); }