diff options
author | Decebal Suiu <decebal.suiu@gmail.com> | 2015-07-21 16:15:06 +0300 |
---|---|---|
committer | Decebal Suiu <decebal.suiu@gmail.com> | 2015-07-21 16:15:06 +0300 |
commit | d2f73728a2446d0f147c5d5cf1e06abb8cd355bd (patch) | |
tree | a1ce675e39c8a9aa08fcd937c964f08a91205ede | |
parent | fa4d7d547e6de0e043e0cf78b6233149369c07d7 (diff) | |
parent | 8203fc7f42afc81059885233b7ffed12cd29c669 (diff) | |
download | pf4j-d2f73728a2446d0f147c5d5cf1e06abb8cd355bd.tar.gz pf4j-d2f73728a2446d0f147c5d5cf1e06abb8cd355bd.zip |
Merge pull request #59 from lightglitch/unit-tests
A few more unit tests
11 files changed, 286 insertions, 45 deletions
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 @@ <version>${junit.version}</version> <scope>test</scope> </dependency> + <dependency> + <groupId>org.mockito</groupId> + <artifactId>mockito-core</artifactId> + <version>${mockito.version}</version> + <scope>test</scope> + </dependency> </dependencies> </project> 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/DefaultExtensionFactoryTest.java b/pf4j/src/test/java/ro/fortsoft/pf4j/DefaultExtensionFactoryTest.java new file mode 100644 index 0000000..506a393 --- /dev/null +++ b/pf4j/src/test/java/ro/fortsoft/pf4j/DefaultExtensionFactoryTest.java @@ -0,0 +1,41 @@ +/* + * 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.TestExtension; + +import static org.junit.Assert.*; + +/** + * + * @author Mario Franco + */ +public class DefaultExtensionFactoryTest { + + /** + * Test of create method, of class DefaultExtensionFactory. + */ + @Test + public void testCreate() { + DefaultExtensionFactory instance = new DefaultExtensionFactory(); + Object result = instance.create(TestExtension.class); + assertNotNull(result); + } + +} 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..203aa02 --- /dev/null +++ b/pf4j/src/test/java/ro/fortsoft/pf4j/DefaultPluginFactoryTest.java @@ -0,0 +1,93 @@ +/* + * 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.AnotherFailTestPlugin; +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 { + + /** + * 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); + } + + /** + * Test of create method, of class DefaultPluginFactory. + */ + @Test + public void testCreateFailConstructor() { + PluginDescriptor pluginDescriptor = mock(PluginDescriptor.class); + when(pluginDescriptor.getPluginClass()).thenReturn(AnotherFailTestPlugin.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..b2ccbd0 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; + /** * @@ -38,9 +39,6 @@ public class DefaultPluginRepositoryTest { @Rule public TemporaryFolder testFolder = new TemporaryFolder(); - public DefaultPluginRepositoryTest() { - } - @Before public void setUp() throws IOException { testFolder.newFile("plugin-1.zip"); @@ -48,10 +46,6 @@ public class DefaultPluginRepositoryTest { testFolder.newFile("plugin-3.zi_"); } - @After - public void tearDown() { - } - /** * Test of getPluginArchives method, of class DefaultPluginRepository. */ @@ -74,9 +68,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<File> 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..72ef17b 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,9 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; -import static org.junit.Assert.*; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + /** * @@ -38,9 +40,6 @@ public class DefaultPluginStatusProviderTest { @Rule public TemporaryFolder testFolder = new TemporaryFolder(); - public DefaultPluginStatusProviderTest() { - } - @Before public void setUp() throws IOException { File file = testFolder.newFile("disabled.txt"); @@ -59,10 +58,6 @@ public class DefaultPluginStatusProviderTest { } } - @After - public void tearDown() { - } - /** * Test of isPluginDisabled method, of class DefaultPluginStatusProvider. */ @@ -71,9 +66,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 +78,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 +91,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 +104,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 +118,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 +131,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/AnotherFailTestPlugin.java b/pf4j/src/test/java/ro/fortsoft/pf4j/plugin/AnotherFailTestPlugin.java new file mode 100644 index 0000000..5cfe611 --- /dev/null +++ b/pf4j/src/test/java/ro/fortsoft/pf4j/plugin/AnotherFailTestPlugin.java @@ -0,0 +1,30 @@ +/* + * 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; + +/** + * + * @author Mario Franco + */ +public class AnotherFailTestPlugin extends Plugin { + + public AnotherFailTestPlugin() { + super(null); + } + +} 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/TestExtension.java b/pf4j/src/test/java/ro/fortsoft/pf4j/plugin/TestExtension.java new file mode 100644 index 0000000..3d74ffb --- /dev/null +++ b/pf4j/src/test/java/ro/fortsoft/pf4j/plugin/TestExtension.java @@ -0,0 +1,26 @@ +/* + * 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.ExtensionPoint; + +/** + * + * @author Mario Franco + */ +public class TestExtension implements ExtensionPoint { + +} 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); + } + +} @@ -35,6 +35,7 @@ <java.version>1.7</java.version> <junit.version>4.12</junit.version> + <mockito.version>2.0.28-beta</mockito.version> <cobertura.version>2.7</cobertura.version> <coveralls.version>3.1.0</coveralls.version> </properties> |