1 package com.atlassian.plugin.predicate;
2
3 import com.atlassian.plugin.Plugin;
4 import com.atlassian.plugin.PluginAccessor;
5 import com.mockobjects.dynamic.C;
6 import com.mockobjects.dynamic.Mock;
7 import junit.framework.TestCase;
8
9
10
11
12 public class TestEnabledPluginPredicate extends TestCase
13 {
14 private static final String TEST_PLUGIN_KEY = "some-test-plugin";
15
16
17
18
19 private PluginPredicate pluginPredicate;
20
21 private Mock mockPluginAccessor;
22 private Plugin plugin;
23
24 protected void setUp() throws Exception
25 {
26 mockPluginAccessor = new Mock(PluginAccessor.class);
27
28 pluginPredicate = new EnabledPluginPredicate((PluginAccessor) mockPluginAccessor.proxy());
29
30 final Mock mockPlugin = new Mock(Plugin.class);
31 mockPlugin.matchAndReturn("getKey", TEST_PLUGIN_KEY);
32 plugin = (Plugin) mockPlugin.proxy();
33 }
34
35 protected void tearDown() throws Exception
36 {
37 pluginPredicate = null;
38 mockPluginAccessor = null;
39 plugin = null;
40 }
41
42 public void testCannotCreateWithNullPluginAccessor()
43 {
44 try
45 {
46 new EnabledPluginPredicate(null);
47 fail("Constructor should have thrown illegal argument exception.");
48 }
49 catch (IllegalArgumentException e)
50 {
51
52 }
53 }
54
55 public void testMatchesEnabledPlugin()
56 {
57 mockPluginAccessor.matchAndReturn("isPluginEnabled", C.eq(TEST_PLUGIN_KEY), true);
58 assertTrue(pluginPredicate.matches(plugin));
59 }
60
61 public void testDoesNotMatchDisabledPlugin()
62 {
63 mockPluginAccessor.matchAndReturn("isPluginEnabled", C.eq(TEST_PLUGIN_KEY), false);
64 assertFalse(pluginPredicate.matches(plugin));
65 }
66 }