-
Notifications
You must be signed in to change notification settings - Fork 748
Resolve Descriptor generic type to derive natural names in DescriptorConfigurator #2834
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
Merged
timja
merged 4 commits into
jenkinsci:master
from
somiljain2006:descriptor-configurator-generic-type-resolution
Apr 16, 2026
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
114 changes: 114 additions & 0 deletions
114
.../src/test/java/io/jenkins/plugins/casc/impl/configurators/DescriptorConfiguratorTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| package io.jenkins.plugins.casc.impl.configurators; | ||
|
|
||
| import static org.junit.Assert.assertEquals; | ||
|
|
||
| import hudson.model.Describable; | ||
| import hudson.model.Descriptor; | ||
| import java.util.Arrays; | ||
| import java.util.Collections; | ||
| import org.jenkinsci.Symbol; | ||
| import org.junit.Test; | ||
|
|
||
| public class DescriptorConfiguratorTest { | ||
|
|
||
| public static class DummyTask implements Describable<DummyTask> { | ||
| @Override | ||
| public Descriptor<DummyTask> getDescriptor() { | ||
| throw new UnsupportedOperationException("Not required for name extraction tests"); | ||
| } | ||
| } | ||
|
|
||
| public static class ParameterizedTask<T> implements Describable<ParameterizedTask<T>> { | ||
| @Override | ||
| public Descriptor<ParameterizedTask<T>> getDescriptor() { | ||
| throw new UnsupportedOperationException(); | ||
| } | ||
| } | ||
|
|
||
| public static class DummyTaskDescriptor extends Descriptor<DummyTask> { | ||
| public DummyTaskDescriptor() { | ||
| super(DummyTask.class); | ||
| } | ||
| } | ||
|
|
||
| @Symbol({"primary", "alias"}) | ||
| public static class MultiSymbolDescriptor extends Descriptor<DummyTask> { | ||
| public MultiSymbolDescriptor() { | ||
| super(DummyTask.class); | ||
| } | ||
| } | ||
|
|
||
| public abstract static class SimulatedBuildStepDescriptor<T extends Describable<T>> extends Descriptor<T> { | ||
| protected SimulatedBuildStepDescriptor(Class<? extends T> clazz) { | ||
| super(clazz); | ||
| } | ||
| } | ||
|
|
||
| public static class DeepTaskDescriptor extends SimulatedBuildStepDescriptor<DummyTask> { | ||
| public DeepTaskDescriptor() { | ||
| super(DummyTask.class); | ||
| } | ||
| } | ||
|
|
||
| @SuppressWarnings({"rawtypes", "unchecked"}) | ||
| public static class ParameterizedDescriptor extends Descriptor<ParameterizedTask<String>> { | ||
| public ParameterizedDescriptor() { | ||
| super((Class) ParameterizedTask.class); | ||
| } | ||
| } | ||
|
|
||
| @SuppressWarnings("rawtypes") | ||
| public static class RawDescriptor extends Descriptor { | ||
| @SuppressWarnings("unchecked") | ||
| public RawDescriptor(Class clazz) { | ||
| super(clazz); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void testMultipleSymbols() { | ||
| DescriptorConfigurator configurator = new DescriptorConfigurator(new MultiSymbolDescriptor()); | ||
|
|
||
| assertEquals("Should use the first symbol as primary name", "primary", configurator.getName()); | ||
| assertEquals( | ||
| "Should return all symbols as aliases", Arrays.asList("primary", "alias"), configurator.getNames()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testNameResolvedFromGenericExtraction() { | ||
| DescriptorConfigurator configurator = new DescriptorConfigurator(new DummyTaskDescriptor()); | ||
|
|
||
| assertEquals("Should extract 'DummyTask' and convert to camelCase", "dummyTask", configurator.getName()); | ||
| assertEquals(Collections.singletonList("dummyTask"), configurator.getNames()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testNameResolvedFromParameterizedType() { | ||
| DescriptorConfigurator configurator = new DescriptorConfigurator(new ParameterizedDescriptor()); | ||
|
|
||
| assertEquals( | ||
| "Should unwrap ParameterizedType to its raw class name", "parameterizedTask", configurator.getName()); | ||
| } | ||
|
|
||
| @Test | ||
| public void testNameResolvedFromDeepInheritance() { | ||
| DescriptorConfigurator configurator = new DescriptorConfigurator(new DeepTaskDescriptor()); | ||
|
|
||
| assertEquals( | ||
| "Should bypass type erasure and extract from superclass hierarchy", | ||
| "dummyTask", | ||
| configurator.getName()); | ||
| } | ||
|
|
||
| @Test | ||
| @SuppressWarnings("rawtypes") | ||
| public void testFallbackWithAnonymousTargetClass() { | ||
|
|
||
| Class<?> anonymousTarget = new DummyTask() {}.getClass(); | ||
| Descriptor rawDescriptor = new RawDescriptor(anonymousTarget); | ||
| DescriptorConfigurator configurator = new DescriptorConfigurator(rawDescriptor); | ||
|
|
||
| assertEquals( | ||
| "Should unwrap anonymous target class via the fallback logic", "dummyTask", configurator.getName()); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.