Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #581 (default plugin-path) and implement basic test for PluginOptions #582

Merged
merged 1 commit into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ private List<Plugin> getEffectivePlugins() {
// Use current folder as plugin if no plugin is provided
if (effectivePlugins.isEmpty()) {
try {
effectivePlugins.add(new PluginPathConverter().convert("."));
return List.of(new PluginPathConverter().convert("."));
} catch (Exception e) {
throw new ModernizerException("Current directory doesn't seem to contains a plugin", e);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package io.jenkins.tools.pluginmodernizer.cli.options;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

import io.jenkins.tools.pluginmodernizer.core.config.Config;
import io.jenkins.tools.pluginmodernizer.core.model.ModernizerException;
import io.jenkins.tools.pluginmodernizer.core.model.Plugin;
import java.lang.reflect.Field;
import java.util.List;
import org.junit.jupiter.api.Test;
import org.junit.platform.commons.util.ReflectionUtils;

/**
* Test for {@link PluginOptions}
*/
public class PluginOptionsTest {

@Test
public void testWithoutPluginSetToDefault() {
Config.Builder builder = Config.builder();
PluginOptions pluginOptions = new PluginOptions();
// Test
assertThrows(
ModernizerException.class,
() -> {
pluginOptions.config(builder);
},
"Path does not contain a Jenkins plugin: .");
}

@Test
public void testWithOnePlugin() throws Exception {

Config.Builder builder = Config.builder();
PluginOptions pluginOptions = new PluginOptions();

// Set one plugin
Field field = ReflectionUtils.findFields(
PluginOptions.class,
f -> f.getName().equals("plugins"),
ReflectionUtils.HierarchyTraversalMode.TOP_DOWN)
.get(0);
field.setAccessible(true);
field.set(pluginOptions, List.of(Plugin.build("one-plugin")));
pluginOptions.config(builder);

// Check only one plugin on the list
Config config = builder.build();
assertEquals(1, config.getPlugins().size(), "Only one plugin should be on the list");
assertEquals("one-plugin", config.getPlugins().get(0).getName(), "Plugin name should be 'one-plugin'");
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
package io.jenkins.tools.pluginmodernizer.core.github;

import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.isNull;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mockStatic;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoInteractions;
import static org.mockito.Mockito.verifyNoMoreInteractions;

import com.google.inject.Guice;
import io.jenkins.tools.pluginmodernizer.core.GuiceModule;
Expand Down
Loading