Browse Source

Merge pull request #59 from lightglitch/unit-tests

A few more unit tests
pull/66/head
Decebal Suiu 10 years ago
parent
commit
d2f73728a2
  1. 6
      pf4j/pom.xml
  2. 2
      pf4j/src/main/java/ro/fortsoft/pf4j/PluginWrapper.java
  3. 41
      pf4j/src/test/java/ro/fortsoft/pf4j/DefaultExtensionFactoryTest.java
  4. 93
      pf4j/src/test/java/ro/fortsoft/pf4j/DefaultPluginFactoryTest.java
  5. 20
      pf4j/src/test/java/ro/fortsoft/pf4j/DefaultPluginRepositoryTest.java
  6. 57
      pf4j/src/test/java/ro/fortsoft/pf4j/DefaultPluginStatusProviderTest.java
  7. 30
      pf4j/src/test/java/ro/fortsoft/pf4j/plugin/AnotherFailTestPlugin.java
  8. 24
      pf4j/src/test/java/ro/fortsoft/pf4j/plugin/FailTestPlugin.java
  9. 26
      pf4j/src/test/java/ro/fortsoft/pf4j/plugin/TestExtension.java
  10. 31
      pf4j/src/test/java/ro/fortsoft/pf4j/plugin/TestPlugin.java
  11. 1
      pom.xml

6
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>

2
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;
}

41
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);
}
}

93
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);
}
}

20
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();

57
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"));
}
}

30
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);
}
}

24
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 {
}

26
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 {
}

31
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);
}
}

1
pom.xml

@ -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>

Loading…
Cancel
Save