@Override
    public void pluginJarRemoved(BundleOrPluginFileDetails bundleOrPluginFileDetails) {
        GoPluginDescriptor existingDescriptor = registry.getPluginByIdOrFileName(null, bundleOrPluginFileDetails.file().getName());
        if (existingDescriptor == null) {
            return;
        }
        try {
            LOGGER.info("Plugin removal starting: {}", bundleOrPluginFileDetails.file());

            boolean externalPlugin = !bundleOrPluginFileDetails.isBundledPlugin();
            boolean bundledPlugin = existingDescriptor.isBundledPlugin();
            boolean externalPluginWithSameIdAsBundledPlugin = bundledPlugin && externalPlugin;
            if (externalPluginWithSameIdAsBundledPlugin) {
                LOGGER.info("External Plugin file '{}' having same name as bundled plugin file has been removed. Refusing to unload bundled plugin with id: '{}'", bundleOrPluginFileDetails.file(), existingDescriptor.id());
                return;
            }
            removePlugin(existingDescriptor.bundleDescriptor());
        } finally {
            LOGGER.info("Plugin removal finished: {}", bundleOrPluginFileDetails.file());
        }
    }
@Test
    void shouldNotRemoveBundledPluginExternalPluginJarRemovedWithSameId() {
        String pluginId = "plugin-id";
        String pluginJarFileName = "plugin-file-name";
        File pluginJarFile = mock(File.class);
        when(pluginJarFile.getName()).thenReturn(pluginJarFileName);
        when(pluginJarFile.getAbsoluteFile()).thenReturn(new File(pluginJarFileName));

        final GoPluginDescriptor oldPluginDescriptor = getPluginDescriptor(pluginId, "1.0", null, null, true, null);
        GoPluginBundleDescriptor oldPluginBundleDescriptor = new GoPluginBundleDescriptor(oldPluginDescriptor);
        when(registry.getPluginByIdOrFileName(null, pluginJarFileName)).thenReturn(oldPluginDescriptor);

        DefaultPluginJarChangeListener spy = spy(listener);
        spy.pluginJarRemoved(new BundleOrPluginFileDetails(pluginJarFile, false, pluginWorkDir));
        verify(registry, never()).unloadPlugin(oldPluginBundleDescriptor);
        verify(pluginLoader, never()).unloadPlugin(oldPluginBundleDescriptor);
    }