View Javadoc

1   package com.atlassian.plugin.predicate;
2   
3   import com.atlassian.plugin.ModuleDescriptor;
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   * Testing {@link EnabledModulePredicate}
11   */
12  public class TestEnabledModulePredicate extends TestCase
13  {
14      private static final String MODULE_TEST_KEY = "some-module-key";
15  
16      private Mock mockPluginAccessor;
17      private ModuleDescriptorPredicate moduleDescriptorPredicate;
18      private ModuleDescriptor moduleDescriptor;
19  
20      protected void setUp() throws Exception
21      {
22          mockPluginAccessor = new Mock(PluginAccessor.class);
23          moduleDescriptorPredicate = new EnabledModulePredicate((PluginAccessor) mockPluginAccessor.proxy());
24  
25          final Mock mockModuleDescriptor = new Mock(ModuleDescriptor.class);
26          mockModuleDescriptor.matchAndReturn("getCompleteKey", MODULE_TEST_KEY);
27          moduleDescriptor = (ModuleDescriptor) mockModuleDescriptor.proxy();
28      }
29  
30      protected void tearDown() throws Exception
31      {
32          moduleDescriptorPredicate = null;
33          mockPluginAccessor = null;
34          moduleDescriptor = null;
35      }
36  
37      public void testCannotCreateWithNullPluginAccessor()
38      {
39          try
40          {
41              new EnabledModulePredicate(null);
42              fail("Constructor should have thrown illegal argument exception.");
43          }
44          catch (IllegalArgumentException e)
45          {
46              // noop
47          }
48      }
49  
50      public void testMatchesEnabledModule()
51      {
52          mockPluginAccessor.matchAndReturn("isPluginModuleEnabled", C.eq(MODULE_TEST_KEY), true);
53          assertTrue(moduleDescriptorPredicate.matches(moduleDescriptor));
54      }
55  
56      public void testDoesNotMatchDisabledModule()
57      {
58          mockPluginAccessor.matchAndReturn("isPluginModuleEnabled", C.eq(MODULE_TEST_KEY), false);
59          assertFalse(moduleDescriptorPredicate.matches(moduleDescriptor));
60      }
61  }