### Question:
Online implements BaseCommand { @Override public String execute(CommandContext commandContext, String[] args) { logger.info("receive online command"); String servicePattern = ".*"; if (ArrayUtils.isNotEmpty(args)) { servicePattern = args[0]; } boolean hasService = false; Collection<ProviderModel> providerModelList = ApplicationModel.allProviderModels(); for (ProviderModel providerModel : providerModelList) { if (providerModel.getServiceName().matches(servicePattern)) { hasService = true; Set<ProviderInvokerWrapper> providerInvokerWrapperSet = ProviderConsumerRegTable.getProviderInvoker(providerModel.getServiceName()); for (ProviderInvokerWrapper providerInvokerWrapper : providerInvokerWrapperSet) { if (providerInvokerWrapper.isReg()) { continue; } Registry registry = registryFactory.getRegistry(providerInvokerWrapper.getRegistryUrl()); registry.register(providerInvokerWrapper.getProviderUrl()); providerInvokerWrapper.setReg(true); } } } if (hasService) { return "OK"; } else { return "service not found"; } }  @Override String execute(CommandContext commandContext, String[] args);  }### Answer:
@Test public void testExecute() throws Exception { ProviderModel providerModel = mock(ProviderModel.class); when(providerModel.getServiceName()).thenReturn("org.apache.dubbo.BarService"); ApplicationModel.initProviderModel("org.apache.dubbo.BarService", providerModel); Invoker providerInvoker = mock(Invoker.class); URL registryUrl = mock(URL.class); when(registryUrl.toFullString()).thenReturn("test: URL providerUrl = mock(URL.class); when(providerUrl.getServiceKey()).thenReturn("org.apache.dubbo.BarService"); when(providerUrl.toFullString()).thenReturn("dubbo: when(providerInvoker.getUrl()).thenReturn(providerUrl); ProviderConsumerRegTable.registerProvider(providerInvoker, registryUrl, providerUrl); Registry registry = mock(Registry.class); TestRegistryFactory.registry = registry; Online online = new Online(); String output = online.execute(mock(CommandContext.class), new String[]{"org.apache.dubbo.BarService"}); assertThat(output, equalTo("OK")); for (ProviderInvokerWrapper wrapper : getProviderInvoker("org.apache.dubbo.BarService")) { assertTrue(wrapper.isReg()); } }