Skip to content
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 @@ -33,7 +33,7 @@
*/
public class ScriptSet {
// have it sorted
protected final Set<Script> scriptSet = new TreeSet<>();
protected Set<Script> scriptSet = new TreeSet<>();

public Script getScriptById(String id) {
for (Script scr : scriptSet) {
Expand Down Expand Up @@ -89,6 +89,9 @@ private Script merge(Script origin, Script newScript) {
}

public final Set<Script> getScripts() {
if (scriptSet == null) {
scriptSet = new TreeSet<>();
}
return Collections.unmodifiableSet(scriptSet);
}

Expand All @@ -103,6 +106,9 @@ public final Set<Script> getUserScripts() {
}

public void setScripts(Set<Script> scripts) {
if (scriptSet == null) {
scriptSet = new TreeSet<>();
}
scriptSet.clear();
scriptSet.addAll(scripts);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package org.jenkinsci.plugins.scriptler.config;

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

import java.util.Collections;
import org.junit.jupiter.api.Test;

public class ScriptSetTest {

@Test
public void testGetScriptsHandlesNull() {
ScriptSet scriptSet = new ScriptSet();

scriptSet.scriptSet = null;

assertNotNull(scriptSet.getScripts(), "getScripts() should never return null");
assertEquals(
Collections.emptySet(), scriptSet.getScripts(), "Should return empty set when internal state is null");
}

@Test
public void testSetScriptsHandlesNull() {
ScriptSet scriptSet = new ScriptSet();
scriptSet.scriptSet = null;

scriptSet.setScripts(Collections.emptySet());

assertNotNull(scriptSet.getScripts(), "Internal set should be initialized after setter");
}
}
Loading