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