pluginWrapper.setPluginState(PluginState.STOPPED);
getStartedPlugins().remove(pluginWrapper);
- firePluginStateEvent(new PluginStateEvent(this, pluginWrapper, PluginState.STOPPED));
+ firePluginStateEvent(new PluginStateEvent(this, pluginWrapper, PluginState.STARTED));
return PluginState.STOPPED;
}
package org.pf4j;
import java.util.EventObject;
+import java.util.Objects;
/**
* Event object that indicates a change in the state of a plugin.
']';
}
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+ PluginStateEvent that = (PluginStateEvent) o;
+ return Objects.equals(plugin, that.plugin) && oldState == that.oldState;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(plugin, oldState);
+ }
+
}
verify(pluginManager, times(1)).resolveDependencies();
}
+ @Test
+ void stopPluginFirePluginStateListeners() {
+ PluginStateListener pluginStateListener = mock(PluginStateListener.class);
+ pluginManager.addPluginStateListener(pluginStateListener);
+
+ String pluginId = "plugin1";
+ PluginWrapper pluginWrapper = createPluginWrapper(pluginId);
+ pluginWrapper.setPluginState(PluginState.STARTED);
+
+ doReturn(pluginWrapper).when(pluginManager).getPlugin(pluginId);
+ doNothing().when(pluginManager).checkPluginId(pluginId);
+ doReturn(new ArrayList<>(Arrays.asList(pluginWrapper))).when(pluginManager).getStartedPlugins();
+
+ pluginManager.stopPlugin(pluginId, false);
+
+ PluginStateEvent event = new PluginStateEvent(pluginManager, pluginWrapper, PluginState.STARTED);
+ verify(pluginStateListener).pluginStateChanged(event);
+ }
+
private PluginWrapper createPluginWrapper(String pluginId, String... dependencies) {
PluginDescriptor pluginDescriptor = new DefaultPluginDescriptor()
.setPluginId(pluginId)