]> source.dussan.org Git - pf4j.git/commitdiff
Improve code quality (sonar hints)
authorDecebal Suiu <decebal.suiu@gmail.com>
Sun, 23 Jan 2022 23:03:22 +0000 (01:03 +0200)
committerDecebal Suiu <decebal.suiu@gmail.com>
Sun, 23 Jan 2022 23:03:22 +0000 (01:03 +0200)
pf4j/src/test/java/org/pf4j/AbstractExtensionFinderTest.java
pf4j/src/test/java/org/pf4j/CompoundPluginDescriptorFinderTest.java
pf4j/src/test/java/org/pf4j/DefaultExtensionFactoryTest.java
pf4j/src/test/java/org/pf4j/DefaultPluginFactoryTest.java
pf4j/src/test/java/org/pf4j/DefaultPluginManagerTest.java
pf4j/src/test/java/org/pf4j/DefaultPluginRepositoryTest.java
pf4j/src/test/java/org/pf4j/DefaultPluginStatusProviderTest.java
pf4j/src/test/java/org/pf4j/DevelopmentPluginRepositoryTest.java
pf4j/src/test/java/org/pf4j/JarPluginRepositoryTest.java

index c1e842221d5d46cc5d6d1f2e0bba715fb58e260c..57bc3c6dd8106b632f339b602e778d41103b6fe4 100644 (file)
@@ -18,8 +18,6 @@ package org.pf4j;
 import com.google.common.collect.ImmutableList;
 import com.google.common.io.ByteStreams;
 import com.google.testing.compile.Compilation;
-import java.util.Comparator;
-import java.util.UUID;
 import org.junit.jupiter.api.AfterEach;
 import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
@@ -30,26 +28,27 @@ import javax.tools.JavaFileObject;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Collections;
+import java.util.Comparator;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.UUID;
 
 import static com.google.testing.compile.CompilationSubject.assertThat;
 import static com.google.testing.compile.Compiler.javac;
 import static org.junit.Assert.assertNull;
 import static org.junit.jupiter.api.Assertions.assertEquals;
 import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.mockito.Mockito.eq;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
 /**
  * @author Mario Franco
  */
-public class AbstractExtensionFinderTest {
+class AbstractExtensionFinderTest {
 
     private PluginManager pluginManager;
 
@@ -64,9 +63,9 @@ public class AbstractExtensionFinderTest {
         when(pluginStopped.getPluginState()).thenReturn(PluginState.STOPPED);
 
         pluginManager = mock(PluginManager.class);
-        when(pluginManager.getPlugin(eq("plugin1"))).thenReturn(pluginStarted);
-        when(pluginManager.getPlugin(eq("plugin2"))).thenReturn(pluginStopped);
-        when(pluginManager.getPluginClassLoader(eq("plugin1"))).thenReturn(getClass().getClassLoader());
+        when(pluginManager.getPlugin("plugin1")).thenReturn(pluginStarted);
+        when(pluginManager.getPlugin("plugin2")).thenReturn(pluginStopped);
+        when(pluginManager.getPluginClassLoader("plugin1")).thenReturn(getClass().getClassLoader());
         when(pluginManager.getExtensionFactory()).thenReturn(new DefaultExtensionFactory());
     }
 
@@ -79,7 +78,7 @@ public class AbstractExtensionFinderTest {
      * Test of {@link AbstractExtensionFinder#find(Class)}.
      */
     @Test
-    void testFindFailType() {
+    void findFailType() {
         ExtensionFinder instance = new AbstractExtensionFinder(pluginManager) {
 
             @Override
@@ -101,7 +100,7 @@ public class AbstractExtensionFinderTest {
      * Test of {@link AbstractExtensionFinder#find(Class)}.
      */
     @Test
-    void testFindFromClasspath() {
+    void findFromClasspath() {
         ExtensionFinder instance = new AbstractExtensionFinder(pluginManager) {
 
             @Override
@@ -131,7 +130,7 @@ public class AbstractExtensionFinderTest {
      * Test of {@link AbstractExtensionFinder#find(Class, String)}.
      */
     @Test
-    void testFindFromPlugin() {
+    void findFromPlugin() {
         ExtensionFinder instance = new AbstractExtensionFinder(pluginManager) {
 
             @Override
@@ -170,7 +169,7 @@ public class AbstractExtensionFinderTest {
      * Test of {@link AbstractExtensionFinder#findClassNames(String)}.
      */
     @Test
-    void testFindClassNames() {
+    void findClassNames() {
         ExtensionFinder instance = new AbstractExtensionFinder(pluginManager) {
 
             @Override
@@ -209,7 +208,7 @@ public class AbstractExtensionFinderTest {
      * Test of {@link org.pf4j.AbstractExtensionFinder#find(java.lang.String)}.
      */
     @Test
-    void testFindExtensionWrappersFromPluginId() {
+    void findExtensionWrappersFromPluginId() {
         ExtensionFinder instance = new AbstractExtensionFinder(pluginManager) {
 
             @Override
@@ -234,7 +233,7 @@ public class AbstractExtensionFinderTest {
 
         };
 
-        List<ExtensionWrapper> plugin1Result = instance.find("plugin1");
+        List<ExtensionWrapper<?>> plugin1Result = instance.find("plugin1");
         assertEquals(2, plugin1Result.size());
 
         List<ExtensionWrapper> plugin2Result = instance.find("plugin2");
index 9aa1af304804733ad3e55bcbebbe68caeaa4dc20..39bb77a0db2a8ebbcc70beed3d9589e0ae6f918c 100644 (file)
@@ -37,7 +37,7 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
 /**
  * @author Decebal Suiu
  */
-public class CompoundPluginDescriptorFinderTest {
+class CompoundPluginDescriptorFinderTest {
 
     @TempDir
     Path pluginsPath;
@@ -83,13 +83,14 @@ public class CompoundPluginDescriptorFinderTest {
     }
 
     @Test
-    void testNotFound() {
+    void notFound() {
         PluginDescriptorFinder descriptorFinder = new CompoundPluginDescriptorFinder();
-        assertThrows(PluginRuntimeException.class, () -> descriptorFinder.find(pluginsPath.resolve("test-plugin-3")));
+        Path pluginPath = pluginsPath.resolve("test-plugin-3");
+        assertThrows(PluginRuntimeException.class, () -> descriptorFinder.find(pluginPath));
     }
 
     @Test
-    void testSpaceCharacterInFileName() throws Exception {
+    void spaceCharacterInFileName() throws Exception {
         PluginDescriptorFinder descriptorFinder = new CompoundPluginDescriptorFinder()
             .add(new ManifestPluginDescriptorFinder());
 
index c71becb0fee2d4571ff2edf52d60593302865c49..a86490af8512218795355eb30bf9c86c47710083 100644 (file)
@@ -27,7 +27,7 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
 /**
  * @author Mario Franco
  */
-public class DefaultExtensionFactoryTest {
+class DefaultExtensionFactoryTest {
 
     private ExtensionFactory extensionFactory;
 
@@ -45,7 +45,7 @@ public class DefaultExtensionFactoryTest {
      * Test of create method, of class DefaultExtensionFactory.
      */
     @Test
-    void testCreate() {
+    void create() {
         assertNotNull(extensionFactory.create(TestExtension.class));
     }
 
@@ -53,7 +53,7 @@ public class DefaultExtensionFactoryTest {
      * Test of create method, of class DefaultExtensionFactory.
      */
     @Test
-    void testCreateFailConstructor() {
+    void createFailConstructor() {
         assertThrows(PluginRuntimeException.class, () -> extensionFactory.create(FailTestExtension.class));
     }
 
index 02f7be8d8bd8201073a69713b146a2b37cc2fbc2..af3104687c8c93d540f7c18dbca41c68350b7612 100644 (file)
@@ -33,7 +33,7 @@ import static org.mockito.Mockito.when;
 class DefaultPluginFactoryTest {
 
     @Test
-    void testCreate() {
+    void create() {
         PluginDescriptor pluginDescriptor = mock(PluginDescriptor.class);
         when(pluginDescriptor.getPluginClass()).thenReturn(TestPlugin.class.getName());
 
@@ -49,7 +49,7 @@ class DefaultPluginFactoryTest {
     }
 
     @Test
-    void testCreateFail() {
+    void createFail() {
         PluginDescriptor pluginDescriptor = mock(PluginDescriptor.class);
         when(pluginDescriptor.getPluginClass()).thenReturn(FailTestPlugin.class.getName());
 
@@ -64,7 +64,7 @@ class DefaultPluginFactoryTest {
     }
 
     @Test
-    void testCreateFailNotFound() {
+    void createFailNotFound() {
         PluginDescriptor pluginDescriptor = mock(PluginDescriptor.class);
         when(pluginDescriptor.getPluginClass()).thenReturn("org.pf4j.plugin.NotFoundTestPlugin");
 
@@ -79,7 +79,7 @@ class DefaultPluginFactoryTest {
     }
 
     @Test
-    void testCreateFailConstructor() {
+    void createFailConstructor() {
         PluginDescriptor pluginDescriptor = mock(PluginDescriptor.class);
         when(pluginDescriptor.getPluginClass()).thenReturn(AnotherFailTestPlugin.class.getName());
 
index 23ee3286d5eac19746ccdec2ea45c000340f1797..d67746fb7022bebfb727d3bf4eb131d936d81390 100644 (file)
@@ -121,7 +121,7 @@ class DefaultPluginManagerTest {
     }
 
     @Test
-    void testDefaultExactVersionAllowed() {
+    void defaultExactVersionAllowed() {
         assertFalse(pluginManager.isExactVersionAllowed());
     }
 
@@ -130,7 +130,7 @@ class DefaultPluginManagerTest {
      * See https://github.com/pf4j/pf4j/issues/223.
      */
     @Test
-    void testPluginDisabledNoStart() throws IOException {
+    void pluginDisabledNoStart() throws IOException {
         new PluginZip.Builder(pluginsPath.resolve("my-plugin-1.2.3.zip"), "myPlugin")
             .pluginVersion("1.2.3")
             .build();
index 7f9de313cff3e1967c6a49d5cb0cf72ed864d321..50831bd0b790686612d27a53b775958ddc9b83d7 100644 (file)
@@ -62,7 +62,7 @@ class DefaultPluginRepositoryTest {
      * Test of {@link DefaultPluginRepository#getPluginPaths()} method.
      */
     @Test
-    void testGetPluginArchivesFromSinglePath() {
+    void getPluginArchivesFromSinglePath() {
         PluginRepository repository = new DefaultPluginRepository(pluginsPath2);
 
         List<Path> pluginPaths = repository.getPluginPaths();
@@ -76,7 +76,7 @@ class DefaultPluginRepositoryTest {
      * Test of {@link DefaultPluginRepository#getPluginPaths()} method.
      */
     @Test
-    void testGetPluginArchives() {
+    void getPluginArchives() {
         PluginRepository repository = new DefaultPluginRepository(pluginsPath1, pluginsPath2);
 
         List<Path> pluginPaths = repository.getPluginPaths();
@@ -91,7 +91,7 @@ class DefaultPluginRepositoryTest {
      * Test of {@link DefaultPluginRepository#deletePluginPath(Path)} method.
      */
     @Test
-    void testDeletePluginPath() {
+    void deletePluginPath() {
         PluginRepository repository = new DefaultPluginRepository(pluginsPath1, pluginsPath2);
 
         assertTrue(Files.exists(pluginsPath1.resolve("plugin-1.zip")));
@@ -103,7 +103,7 @@ class DefaultPluginRepositoryTest {
         List<Path> pluginPaths = repository.getPluginPaths();
 
         assertEquals(1, pluginPaths.size());
-        assertEquals(pluginsPath2.relativize(pluginPaths.get(0)).toString(), "plugin-2");
+        assertEquals("plugin-2", pluginsPath2.relativize(pluginPaths.get(0)).toString());
     }
 
     private void assertPathExists(List<Path> paths, Path path) {
index 1d23e641dcb94d0523e9a372f1be049e87dbf3b2..7014d337b9742c37d198a6c346339e29cd236b4d 100644 (file)
@@ -38,7 +38,7 @@ class DefaultPluginStatusProviderTest {
     Path pluginsPath;
 
     @Test
-    void testIsPluginDisabled() throws IOException {
+    void isPluginDisabled() throws IOException {
         createEnabledFile();
         createDisabledFile();
 
@@ -50,7 +50,7 @@ class DefaultPluginStatusProviderTest {
     }
 
     @Test
-    void testIsPluginDisabledWithEnableEmpty() throws IOException {
+    void isPluginDisabledWithEnableEmpty() throws IOException {
         createDisabledFile();
 
         PluginStatusProvider statusProvider = new DefaultPluginStatusProvider(pluginsPath);
@@ -61,7 +61,7 @@ class DefaultPluginStatusProviderTest {
     }
 
     @Test
-    void testDisablePlugin() throws Exception {
+    void disablePlugin() throws Exception {
         createEnabledFile();
         createDisabledFile();
 
@@ -74,7 +74,7 @@ class DefaultPluginStatusProviderTest {
     }
 
     @Test
-    void testDisablePluginWithEnableEmpty() throws Exception {
+    void disablePluginWithEnableEmpty() throws Exception {
         // scenario with "disabled.txt"
         createDisabledFile();
 
@@ -107,7 +107,7 @@ class DefaultPluginStatusProviderTest {
     }
 
     @Test
-    void testEnablePlugin() throws Exception {
+    void enablePlugin() throws Exception {
         // scenario with "enabled.txt"
         createEnabledFile();
 
@@ -140,7 +140,7 @@ class DefaultPluginStatusProviderTest {
     }
 
     @Test
-    void testEnablePluginWithEnableEmpty() {
+    void enablePluginWithEnableEmpty() {
         PluginStatusProvider statusProvider = new DefaultPluginStatusProvider(pluginsPath);
         statusProvider.enablePlugin("plugin-2");
 
@@ -150,7 +150,7 @@ class DefaultPluginStatusProviderTest {
     }
 
     @Test
-    void testDisablePluginWithoutDisabledFile() {
+    void disablePluginWithoutDisabledFile() {
         PluginStatusProvider statusProvider = new DefaultPluginStatusProvider(pluginsPath);
 
         assertFalse(statusProvider.isPluginDisabled("plugin-1"));
index 051b2f3c1968e0c904ab6fdc4028aab6601f1b3d..c2a51e611233a3f5b095939728f97f58dd97a5b6 100644 (file)
@@ -43,7 +43,7 @@ class DevelopmentPluginRepositoryTest {
     }
 
     @Test
-    void testGetPluginArchivesInDevelopmentMode() {
+    void getPluginArchivesInDevelopmentMode() {
         PluginRepository repository = new DevelopmentPluginRepository(pluginsPath);
 
         List<Path> pluginPaths = repository.getPluginPaths();
index a9e3e57855851097e9a20c27a8f194b1307c804d..751001a619e0f1d196f4411acbcc38cbc5cab0b9 100644 (file)
@@ -38,7 +38,7 @@ class JarPluginRepositoryTest {
      * Test of {@link JarPluginRepository#deletePluginPath(Path)} method.
      */
     @Test
-    void testDeletePluginPath() throws Exception {
+    void deletePluginPath() throws Exception {
         PluginRepository repository = new JarPluginRepository(pluginsPath);
 
         Path plugin1Path = Files.createDirectory(pluginsPath.resolve("plugin-1"));