You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

DefaultPluginFactoryTest.java 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. * Copyright 2015 Decebal Suiu
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package ro.fortsoft.pf4j;
  17. import org.junit.After;
  18. import org.junit.Before;
  19. import org.junit.Test;
  20. import ro.fortsoft.pf4j.plugin.AnotherFailTestPlugin;
  21. import ro.fortsoft.pf4j.plugin.FailTestPlugin;
  22. import ro.fortsoft.pf4j.plugin.TestPlugin;
  23. import static org.hamcrest.CoreMatchers.instanceOf;
  24. import static org.junit.Assert.assertNotNull;
  25. import static org.junit.Assert.assertNull;
  26. import static org.junit.Assert.assertThat;
  27. import static org.mockito.Mockito.mock;
  28. import static org.mockito.Mockito.when;
  29. /**
  30. *
  31. * @author Mario Franco
  32. */
  33. public class DefaultPluginFactoryTest {
  34. public DefaultPluginFactoryTest() {
  35. }
  36. @Before
  37. public void setUp() {
  38. }
  39. @After
  40. public void tearDown() {
  41. }
  42. /**
  43. * Test of create method, of class DefaultPluginFactory.
  44. */
  45. @Test
  46. public void testCreate() {
  47. PluginDescriptor pluginDescriptor = mock(PluginDescriptor.class);
  48. when(pluginDescriptor.getPluginClass()).thenReturn(TestPlugin.class.getName());
  49. PluginWrapper pluginWrapper = mock(PluginWrapper.class);
  50. when(pluginWrapper.getDescriptor()).thenReturn(pluginDescriptor);
  51. when(pluginWrapper.getPluginClassLoader()).thenReturn(getClass().getClassLoader());
  52. DefaultPluginFactory instance = new DefaultPluginFactory();
  53. Plugin result = instance.create(pluginWrapper);
  54. assertNotNull(result);
  55. assertThat(result, instanceOf(TestPlugin.class));
  56. }
  57. /**
  58. * Test of create method, of class DefaultPluginFactory.
  59. */
  60. @Test
  61. public void testCreateFail() {
  62. PluginDescriptor pluginDescriptor = mock(PluginDescriptor.class);
  63. when(pluginDescriptor.getPluginClass()).thenReturn(FailTestPlugin.class.getName());
  64. PluginWrapper pluginWrapper = mock(PluginWrapper.class);
  65. when(pluginWrapper.getDescriptor()).thenReturn(pluginDescriptor);
  66. when(pluginWrapper.getPluginClassLoader()).thenReturn(getClass().getClassLoader());
  67. DefaultPluginFactory instance = new DefaultPluginFactory();
  68. Plugin result = instance.create(pluginWrapper);
  69. assertNull(result);
  70. }
  71. /**
  72. * Test of create method, of class DefaultPluginFactory.
  73. */
  74. @Test
  75. public void testCreateFailConstructor() {
  76. PluginDescriptor pluginDescriptor = mock(PluginDescriptor.class);
  77. when(pluginDescriptor.getPluginClass()).thenReturn(AnotherFailTestPlugin.class.getName());
  78. PluginWrapper pluginWrapper = mock(PluginWrapper.class);
  79. when(pluginWrapper.getDescriptor()).thenReturn(pluginDescriptor);
  80. when(pluginWrapper.getPluginClassLoader()).thenReturn(getClass().getClassLoader());
  81. DefaultPluginFactory instance = new DefaultPluginFactory();
  82. Plugin result = instance.create(pluginWrapper);
  83. assertNull(result);
  84. }
  85. }