### Question:
PluginInstanceService { public List<PluginInstance> getRunningPluginInstances(String pluginName) { List<PluginPackage> activePluginPackages = pluginPackageRepository .findLatestActiveVersionPluginPackagesByName(pluginName); if (activePluginPackages == null || activePluginPackages.isEmpty()) { throw new WecubeCoreException("3068",String.format("Plugin package [%s] not found.", pluginName), pluginName); } List<PluginInstance> runningInstances = new ArrayList<PluginInstance>(); for (PluginPackage pkg : activePluginPackages) { List<PluginInstance> instances = pluginInstanceRepository .findByContainerStatusAndPluginPackage_Id(PluginInstance.CONTAINER_STATUS_RUNNING, pkg.getId()); if (instances != null && (!instances.isEmpty())) { runningInstances.addAll(instances); } if (runningInstances.size() > 0) { break; } } if (runningInstances.isEmpty()) { throw new WecubeCoreException("3069",String.format("No instance for plugin [%s] is available.", pluginName)); } return runningInstances; }  List<String> getAvailableContainerHosts(); Integer getAvailablePortByHostIp(String hostIp); List<PluginInstance> getAllInstances(); List<PluginInstance> getAvailableInstancesByPackageId(String packageId); PluginInstance getRunningPluginInstance(String pluginName); List<PluginInstance> getRunningPluginInstances(String pluginName); boolean versionGreaterThan(String version, String baseVersion); boolean versionEquals(String version, String baseVersion); void launchPluginInstance(String packageId, String hostIp, Integer port); PluginMysqlInstance createPluginMysqlDatabase(PluginPackageRuntimeResourcesMysql mysqlInfo,
            String currentPluginVersion); void removePluginInstanceById(String instanceId); String getInstanceAddress(PluginInstance instance);  }### Answer:
@Test public void givenLatestPackageNotRegisteredWhenQueryRunningInstanceByPackageNameThenShouldReturnTheInstanceRunningWithOlderRegisteredPackage() { prepareDataForLatestPackageNotRegistered(); String packageName = "service-mgmt"; List<PluginInstance> runningPluginInstances = pluginInstanceService.getRunningPluginInstances(packageName); assertThat(runningPluginInstances).hasSize(1); assertThat(runningPluginInstances.get(0).getPluginPackage().getId()).isEqualTo("service-mgmt__v1.0"); }
@Test public void givenLatestPackageRegisterButNoRunningInstanceWhenQueryRunningInstanceByPackageNameThenShouldReturnNull() { prepareDataForLatestPackageRegisteredButNoRunningInstance(); String packageName = "service-mgmt"; try { pluginInstanceService.getRunningPluginInstances(packageName); assertThat(false); } catch (Exception e) { assertThat(e instanceof WecubeCoreException); assertThat(e.getMessage()).contains("No instance for plugin"); } }