@Override
    public void onApplicationEvent(final PluginHandlerEvent event) {
        PluginHandlerEventEnum stateEnums = event.getPluginStateEnums();
        PluginData pluginData = (PluginData) event.getSource();
        switch (stateEnums) {
            case ENABLED:
                onPluginEnabled(pluginData);
                break;
            case DELETE:
            case DISABLED:
                // disable or removed plugin.
                onPluginRemoved(pluginData);
                break;
            case SORTED:
                // copy a new one, or there will be concurrency problems
                this.plugins = sortPlugins(new ArrayList<>(this.plugins));
                break;
            default:
                throw new IllegalStateException("Unexpected value: " + event.getPluginStateEnums());
        }
    }
@Test
    public void testOnApplicationEvent() {
        PluginData pluginData1 = PluginData.builder().id("1")
                .name("test-plugin1")
                .enabled(true)
                .config("config")
                .role("test")
                .sort(50)
                .build();
        PluginData pluginData2 = PluginData.builder().id("2")
                .name("test-plugin2")
                .enabled(false)
                .config("config")
                .role("test")
                .sort(60)
                .build();
        shenyuWebHandler.onApplicationEvent(new PluginHandlerEvent(PluginHandlerEventEnum.ENABLED, pluginData1));
        shenyuWebHandler.onApplicationEvent(new PluginHandlerEvent(PluginHandlerEventEnum.DISABLED, pluginData2));
        List<ShenyuPlugin> plugins = (List<ShenyuPlugin>) ReflectionTestUtils.getField(shenyuWebHandler, "plugins");
        assertNotNull(plugins);
        assertTrue(plugins.contains(plugin1) && !plugins.contains(plugin2));

        shenyuWebHandler.onApplicationEvent(new PluginHandlerEvent(PluginHandlerEventEnum.ENABLED, pluginData1));
        shenyuWebHandler.onApplicationEvent(new PluginHandlerEvent(PluginHandlerEventEnum.DELETE, pluginData2));
        List<ShenyuPlugin> pluginDelete = (List<ShenyuPlugin>) ReflectionTestUtils.getField(shenyuWebHandler, "plugins");
        assertNotNull(pluginDelete);
        assertTrue(pluginDelete.contains(plugin1) && !pluginDelete.contains(plugin2));

        pluginData1.setSort(70);
        pluginData2.setEnabled(true);
        BaseDataCache.getInstance().cachePluginData(pluginData1);
        BaseDataCache.getInstance().cachePluginData(pluginData2);
        shenyuWebHandler.onApplicationEvent(new PluginHandlerEvent(PluginHandlerEventEnum.ENABLED, pluginData1));
        shenyuWebHandler.onApplicationEvent(new PluginHandlerEvent(PluginHandlerEventEnum.ENABLED, pluginData2));
        List<ShenyuPlugin> pluginDataSorted = (List<ShenyuPlugin>) ReflectionTestUtils.getField(shenyuWebHandler, "plugins");
        assertNotNull(pluginDataSorted);
        assertEquals(pluginDataSorted.get(0), plugin2);
        assertEquals(pluginDataSorted.get(1), plugin1);

        shenyuWebHandler.onApplicationEvent(new PluginHandlerEvent(PluginHandlerEventEnum.SORTED, pluginData1));
        assertEquals(pluginDataSorted.get(0), plugin2);
    }