diff --git a/pf4j/pom.xml b/pf4j/pom.xml index 3c10d84..5c2cb9e 100644 --- a/pf4j/pom.xml +++ b/pf4j/pom.xml @@ -43,6 +43,12 @@ ${junit.version} test + + org.mockito + mockito-core + ${mockito.version} + test + diff --git a/pf4j/src/main/java/ro/fortsoft/pf4j/PluginWrapper.java b/pf4j/src/main/java/ro/fortsoft/pf4j/PluginWrapper.java index 3c3b6e1..45dbc1e 100644 --- a/pf4j/src/main/java/ro/fortsoft/pf4j/PluginWrapper.java +++ b/pf4j/src/main/java/ro/fortsoft/pf4j/PluginWrapper.java @@ -54,7 +54,7 @@ public class PluginWrapper { * for this plug-in. The class loader can be used to directly access * plug-in resources and classes. */ - public PluginClassLoader getPluginClassLoader() { + public ClassLoader getPluginClassLoader() { return pluginClassLoader; } diff --git a/pf4j/src/test/java/ro/fortsoft/pf4j/DefaultPluginFactoryTest.java b/pf4j/src/test/java/ro/fortsoft/pf4j/DefaultPluginFactoryTest.java new file mode 100644 index 0000000..bed82f9 --- /dev/null +++ b/pf4j/src/test/java/ro/fortsoft/pf4j/DefaultPluginFactoryTest.java @@ -0,0 +1,84 @@ +/* + * Copyright 2015 Decebal Suiu + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package ro.fortsoft.pf4j; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import ro.fortsoft.pf4j.plugin.FailTestPlugin; +import ro.fortsoft.pf4j.plugin.TestPlugin; + +import static org.hamcrest.CoreMatchers.instanceOf; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertThat; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +/** + * + * @author Mario Franco + */ +public class DefaultPluginFactoryTest { + + public DefaultPluginFactoryTest() { + } + + @Before + public void setUp() { + } + + @After + public void tearDown() { + } + + /** + * Test of create method, of class DefaultPluginFactory. + */ + @Test + public void testCreate() { + PluginDescriptor pluginDescriptor = mock(PluginDescriptor.class); + when(pluginDescriptor.getPluginClass()).thenReturn(TestPlugin.class.getName()); + + PluginWrapper pluginWrapper = mock(PluginWrapper.class); + when(pluginWrapper.getDescriptor()).thenReturn(pluginDescriptor); + when(pluginWrapper.getPluginClassLoader()).thenReturn(getClass().getClassLoader()); + + DefaultPluginFactory instance = new DefaultPluginFactory(); + + Plugin result = instance.create(pluginWrapper); + assertNotNull(result); + assertThat(result, instanceOf(TestPlugin.class)); + } + + /** + * Test of create method, of class DefaultPluginFactory. + */ + @Test + public void testCreateFail() { + PluginDescriptor pluginDescriptor = mock(PluginDescriptor.class); + when(pluginDescriptor.getPluginClass()).thenReturn(FailTestPlugin.class.getName()); + + PluginWrapper pluginWrapper = mock(PluginWrapper.class); + when(pluginWrapper.getDescriptor()).thenReturn(pluginDescriptor); + when(pluginWrapper.getPluginClassLoader()).thenReturn(getClass().getClassLoader()); + + DefaultPluginFactory instance = new DefaultPluginFactory(); + + Plugin result = instance.create(pluginWrapper); + assertNull(result); + } +} diff --git a/pf4j/src/test/java/ro/fortsoft/pf4j/DefaultPluginRepositoryTest.java b/pf4j/src/test/java/ro/fortsoft/pf4j/DefaultPluginRepositoryTest.java index 7e2a6ec..3ae58af 100644 --- a/pf4j/src/test/java/ro/fortsoft/pf4j/DefaultPluginRepositoryTest.java +++ b/pf4j/src/test/java/ro/fortsoft/pf4j/DefaultPluginRepositoryTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Mario Franco. + * Copyright 2015 Decebal Suiu * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,15 +19,16 @@ import java.io.File; import java.io.IOException; import java.util.List; import org.junit.After; -import org.junit.AfterClass; import org.junit.Before; -import org.junit.BeforeClass; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; import ro.fortsoft.pf4j.util.ZipFileFilter; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + /** * @@ -74,9 +75,9 @@ public class DefaultPluginRepositoryTest { public void testDeletePluginArchive() { DefaultPluginRepository instance = new DefaultPluginRepository(testFolder.getRoot(), new ZipFileFilter()); - assertEquals(true, instance.deletePluginArchive("/plugin-1")); + assertTrue(instance.deletePluginArchive("/plugin-1")); - assertEquals(false, instance.deletePluginArchive("/plugin-3")); + assertFalse(instance.deletePluginArchive("/plugin-3")); List result = instance.getPluginArchives(); diff --git a/pf4j/src/test/java/ro/fortsoft/pf4j/DefaultPluginStatusProviderTest.java b/pf4j/src/test/java/ro/fortsoft/pf4j/DefaultPluginStatusProviderTest.java index 5da32fc..85991c4 100644 --- a/pf4j/src/test/java/ro/fortsoft/pf4j/DefaultPluginStatusProviderTest.java +++ b/pf4j/src/test/java/ro/fortsoft/pf4j/DefaultPluginStatusProviderTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Mario Franco. + * Copyright 2015 Decebal Suiu * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,7 +27,10 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + /** * @@ -71,9 +74,9 @@ public class DefaultPluginStatusProviderTest { setUpEnabled(); DefaultPluginStatusProvider instance = new DefaultPluginStatusProvider(testFolder.getRoot()); - assertEquals(false, instance.isPluginDisabled("plugin-1")); - assertEquals(true, instance.isPluginDisabled("plugin-2")); - assertEquals(true, instance.isPluginDisabled("plugin-3")); + assertFalse(instance.isPluginDisabled("plugin-1")); + assertTrue(instance.isPluginDisabled("plugin-2")); + assertTrue(instance.isPluginDisabled("plugin-3")); } /** @@ -83,9 +86,9 @@ public class DefaultPluginStatusProviderTest { public void testIsPluginDisabledWithEnableEmpty() { DefaultPluginStatusProvider instance = new DefaultPluginStatusProvider(testFolder.getRoot()); - assertEquals(false, instance.isPluginDisabled("plugin-1")); - assertEquals(true, instance.isPluginDisabled("plugin-2")); - assertEquals(false, instance.isPluginDisabled("plugin-3")); + assertFalse(instance.isPluginDisabled("plugin-1")); + assertTrue(instance.isPluginDisabled("plugin-2")); + assertFalse(instance.isPluginDisabled("plugin-3")); } /** @@ -96,10 +99,10 @@ public class DefaultPluginStatusProviderTest { setUpEnabled(); DefaultPluginStatusProvider instance = new DefaultPluginStatusProvider(testFolder.getRoot()); - assertEquals(true, instance.disablePlugin("plugin-1")); - assertEquals(true, instance.isPluginDisabled("plugin-1")); - assertEquals(true, instance.isPluginDisabled("plugin-2")); - assertEquals(true, instance.isPluginDisabled("plugin-3")); + assertTrue(instance.disablePlugin("plugin-1")); + assertTrue(instance.isPluginDisabled("plugin-1")); + assertTrue(instance.isPluginDisabled("plugin-2")); + assertTrue(instance.isPluginDisabled("plugin-3")); } /** @@ -109,10 +112,10 @@ public class DefaultPluginStatusProviderTest { public void testDisablePluginWithEnableEmpty() { DefaultPluginStatusProvider instance = new DefaultPluginStatusProvider(testFolder.getRoot()); - assertEquals(true, instance.disablePlugin("plugin-1")); - assertEquals(true, instance.isPluginDisabled("plugin-1")); - assertEquals(true, instance.isPluginDisabled("plugin-2")); - assertEquals(false, instance.isPluginDisabled("plugin-3")); + assertTrue(instance.disablePlugin("plugin-1")); + assertTrue(instance.isPluginDisabled("plugin-1")); + assertTrue(instance.isPluginDisabled("plugin-2")); + assertFalse(instance.isPluginDisabled("plugin-3")); } /** @@ -123,10 +126,10 @@ public class DefaultPluginStatusProviderTest { setUpEnabled(); DefaultPluginStatusProvider instance = new DefaultPluginStatusProvider(testFolder.getRoot()); - assertEquals(true, instance.enablePlugin("plugin-2")); - assertEquals(false, instance.isPluginDisabled("plugin-1")); - assertEquals(false, instance.isPluginDisabled("plugin-2")); - assertEquals(true, instance.isPluginDisabled("plugin-3")); + assertTrue(instance.enablePlugin("plugin-2")); + assertFalse(instance.isPluginDisabled("plugin-1")); + assertFalse(instance.isPluginDisabled("plugin-2")); + assertTrue(instance.isPluginDisabled("plugin-3")); } /** @@ -136,10 +139,10 @@ public class DefaultPluginStatusProviderTest { public void testEnablePluginWithEnableEmpty() { DefaultPluginStatusProvider instance = new DefaultPluginStatusProvider(testFolder.getRoot()); - assertEquals(true, instance.enablePlugin("plugin-2")); - assertEquals(false, instance.isPluginDisabled("plugin-1")); - assertEquals(false, instance.isPluginDisabled("plugin-2")); - assertEquals(false, instance.isPluginDisabled("plugin-3")); + assertTrue(instance.enablePlugin("plugin-2")); + assertFalse(instance.isPluginDisabled("plugin-1")); + assertFalse(instance.isPluginDisabled("plugin-2")); + assertFalse(instance.isPluginDisabled("plugin-3")); } } diff --git a/pf4j/src/test/java/ro/fortsoft/pf4j/plugin/FailTestPlugin.java b/pf4j/src/test/java/ro/fortsoft/pf4j/plugin/FailTestPlugin.java new file mode 100644 index 0000000..0f4ba65 --- /dev/null +++ b/pf4j/src/test/java/ro/fortsoft/pf4j/plugin/FailTestPlugin.java @@ -0,0 +1,24 @@ +/* + * Copyright 2015 Decebal Suiu + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package ro.fortsoft.pf4j.plugin; + +/** + * + * @author Mario Franco + */ +public class FailTestPlugin { + +} diff --git a/pf4j/src/test/java/ro/fortsoft/pf4j/plugin/TestPlugin.java b/pf4j/src/test/java/ro/fortsoft/pf4j/plugin/TestPlugin.java new file mode 100644 index 0000000..3557a16 --- /dev/null +++ b/pf4j/src/test/java/ro/fortsoft/pf4j/plugin/TestPlugin.java @@ -0,0 +1,31 @@ +/* + * Copyright 2015 Decebal Suiu + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package ro.fortsoft.pf4j.plugin; + +import ro.fortsoft.pf4j.Plugin; +import ro.fortsoft.pf4j.PluginWrapper; + +/** + * + * @author Mario Franco + */ +public class TestPlugin extends Plugin { + + public TestPlugin(PluginWrapper wrapper) { + super(wrapper); + } + +} diff --git a/pom.xml b/pom.xml index a0bd22e..19732a8 100644 --- a/pom.xml +++ b/pom.xml @@ -35,7 +35,8 @@ 1.7 4.12 - 2.7 + 4.12 + 2.0.28-beta 3.1.0