Commit 44e3dc0e authored by Alex Wenckus's avatar Alex Wenckus Committed by alex

Made GroupManager mockable

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/trunk@8630 b35dd754-fafc-0310-a699-88a17e54d16e
parent e2e32da4
......@@ -34,11 +34,9 @@ import java.util.Map;
*/
public class GroupManager {
Cache<String, Group> groupCache;
Cache<String, Object> groupMetaCache;
private GroupProvider provider;
private static GroupManager instance = new GroupManager();
private static final class GroupManagerContainer {
private static final GroupManager instance = new GroupManager();
}
private static final String GROUP_COUNT_KEY = "GROUP_COUNT";
private static final String SHARED_GROUPS_KEY = "SHARED_GROUPS";
......@@ -50,9 +48,13 @@ public class GroupManager {
* @return a GroupManager instance.
*/
public static GroupManager getInstance() {
return instance;
return GroupManagerContainer.instance;
}
Cache<String, Group> groupCache;
Cache<String, Object> groupMetaCache;
private GroupProvider provider;
private GroupManager() {
// Initialize caches.
groupCache = CacheFactory.createCache("Group");
......
......@@ -70,7 +70,6 @@ public class BroadcastPlugin extends AbstractPlugin implements Component, Proper
this.pluginName = pluginName;
this.pluginDescription = pluginDescription;
this.jiveProperties = jiveProperties;
this.serviceName = jiveProperties.getProperty("plugin.broadcast.serviceName", "broadcast");
this.sessionManager = sessionManager;
this.groupManager = groupManager;
}
......@@ -376,6 +375,9 @@ public class BroadcastPlugin extends AbstractPlugin implements Component, Proper
* @return the service name of this component.
*/
public String getServiceName() {
if (serviceName == null) {
serviceName = jiveProperties.getProperty("plugin.broadcast.serviceName", "broadcast");
}
return serviceName;
}
......@@ -498,7 +500,7 @@ public class BroadcastPlugin extends AbstractPlugin implements Component, Proper
if (serviceName == null) {
throw new NullPointerException("Service name cannot be null");
}
if (this.serviceName.equals(serviceName)) {
if (serviceName.equals(this.serviceName)) {
return;
}
......
/**
* $Revision:$
* $Date:$
*
* Copyright (C) 2007 Jive Software. All rights reserved.
* This software is the proprietary information of Jive Software. Use is subject to license terms.
*/
package org.jivesoftware.plugin;
import org.jmock.lib.legacy.ClassImposteriser;
import org.jmock.integration.junit4.JUnit4Mockery;
import org.jmock.Mockery;
import org.jmock.Expectations;
import org.jivesoftware.openfire.plugin.AbstractPluginSupport;
import org.jivesoftware.openfire.plugin.BroadcastPlugin;
import org.jivesoftware.openfire.container.plugin.PluginName;
import org.jivesoftware.openfire.container.plugin.PluginDescription;
import org.jivesoftware.openfire.component.ComponentLifecycle;
import org.jivesoftware.util.JiveProperties;
import org.junit.Test;
import org.xmpp.component.ComponentManager;
import com.google.inject.Injector;
import com.google.inject.Module;
import com.google.inject.AbstractModule;
import static org.junit.Assert.*;
/**
*
*/
public class BroadcastPluginTest {
private static final Mockery context = new JUnit4Mockery() {{
setImposteriser(ClassImposteriser.INSTANCE);
}};
private static final Module pluginModule = new AbstractModule() {
protected void configure() {
// not a singleton so we get a fresh one every time.
bind(BroadcastPlugin.class);
bind(String.class).annotatedWith(PluginName.class).toInstance("broadcast");
bind(String.class).annotatedWith(PluginDescription.class)
.toInstance("the broadcast plugin");
}
};
private static final Injector injector = AbstractPluginSupport.createInjector(context,
pluginModule);
@Test
public void testPluginInitialize() {
final BroadcastPlugin broadcastPlugin = injector.getInstance(BroadcastPlugin.class);
final ComponentLifecycle componentLifecycle = context.mock(ComponentLifecycle.class);
context.checking(new Expectations() {{
try {
allowing(injector.getInstance(JiveProperties.class))
.getProperty("plugin.broadcast.serviceName", "broadcast");
will(returnValue("broadcast"));
allowing(injector.getInstance(ComponentManager.class))
.addComponent("broadcast", broadcastPlugin, null);
will(returnValue(componentLifecycle));
}
catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}});
broadcastPlugin.initialize();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment