View Javadoc

1   package com.atlassian.plugin.osgi.factory;
2   
3   import com.atlassian.plugin.IllegalPluginStateException;
4   
5   import org.junit.Before;
6   import org.junit.Rule;
7   import org.junit.Test;
8   import org.junit.rules.ExpectedException;
9   
10  import static org.hamcrest.MatcherAssert.assertThat;
11  import static org.hamcrest.Matchers.is;
12  
13  public class TestOsgiPluginDeinstalledHelper
14  {
15      private static final String PLUGIN_KEY = "plugin-key";
16      @Rule
17      public ExpectedException expectedException = ExpectedException.none();
18  
19      OsgiPluginDeinstalledHelper helper;
20  
21      @Before
22      public void setUp() throws Exception
23      {
24          helper = new OsgiPluginDeinstalledHelper(PLUGIN_KEY, false);
25      }
26  
27      @Test
28      public void loadClassThrowsExceptionWithClassAndGivenCallingClass() throws Exception
29      {
30          final String loadedClass = "loadedClass";
31          expectIllegalPluginStateException(loadedClass, "java.lang.String");
32          helper.loadClass(loadedClass, String.class);
33      }
34  
35      @Test
36      public void loadClassThrowsExceptionWithClassAndNullCallingClass() throws Exception
37      {
38          final String loadedClass = "loadedClass";
39          expectIllegalPluginStateException(loadedClass, "null");
40          helper.loadClass(loadedClass, null);
41      }
42  
43      @Test
44      public void installThrowsException()
45      {
46          expectIllegalPluginStateException();
47          helper.install();
48      }
49  
50      @Test
51      public void isRemotePluginReturnsConstructorParameter()
52      {
53          assertThat(helper.isRemotePlugin(), is(false));
54      }
55  
56      @Test
57      public void getBundleThrowsException()
58      {
59          expectIllegalPluginStateException();
60          helper.getBundle();
61      }
62  
63      @Test
64      public void getResource()
65      {
66          final String resourceName = "some.resource";
67          expectIllegalPluginStateException(resourceName);
68          helper.getResource(resourceName);
69      }
70  
71      @Test
72      public void getResourceAsStream()
73      {
74          final String resourceName = "some.resource";
75          expectIllegalPluginStateException(resourceName);
76          helper.getResourceAsStream(resourceName);
77      }
78  
79      @Test
80      public void getClassLoader()
81      {
82          expectIllegalPluginStateException();
83          helper.getClassLoader();
84      }
85  
86      @Test
87      public void onEnable()
88      {
89          expectIllegalPluginStateException();
90          helper.onEnable();
91      }
92  
93      @Test
94      public void onDisable()
95      {
96          expectIllegalPluginStateException();
97          helper.onDisable();
98      }
99  
100     @Test
101     public void onUninstall()
102     {
103         expectIllegalPluginStateException();
104         helper.onUninstall();
105     }
106 
107     @Test
108     public void getRequiredPlugins()
109     {
110         expectIllegalPluginStateException();
111         helper.getRequiredPlugins();
112     }
113 
114     @Test
115     public void setPluginContainer()
116     {
117         expectIllegalPluginStateException();
118         helper.setPluginContainer(new Object());
119     }
120 
121     @Test
122     public void getContainerAccessor()
123     {
124         expectIllegalPluginStateException();
125         helper.getContainerAccessor();
126     }
127 
128     @Test
129     public void getRequiredContainerAccessor()
130     {
131         expectIllegalPluginStateException();
132         helper.getRequiredContainerAccessor();
133     }
134 
135     private void expectIllegalPluginStateException(final String... messages)
136     {
137         expectedException.expect(IllegalPluginStateException.class);
138         expectedException.expectMessage(PLUGIN_KEY);
139         for (final String message : messages)
140         {
141             expectedException.expectMessage(message);
142         }
143     }
144 }