-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use "get" prefix for configuration attribute getters (#328)
The configuration-as-code plugin expects a plugins configuration attributes to be accessible with setters prefixed with "set" and getters prefixed with "get" or "is". Change and add the getters for the configurations attributes that don't follow this convention so this plugin can be fully configured with configuration as code.
- Loading branch information
Showing
4 changed files
with
52 additions
and
9 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
41 changes: 41 additions & 0 deletions
41
.../jenkins/plugins/bitbucketpushandpullrequest/config/BitBucketPPRConfigAttributesTest.java
This file contains 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,41 @@ | ||
package io.jenkins.plugins.bitbucketpushandpullrequest.config; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.junit.MockitoJUnitRunner; | ||
|
||
import java.lang.reflect.Method; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import static org.junit.Assert.assertTrue; | ||
|
||
@RunWith(MockitoJUnitRunner.class) | ||
public class BitBucketPPRConfigAttributesTest { | ||
|
||
final private Class<BitBucketPPRPluginConfig> config = BitBucketPPRPluginConfig.class; | ||
|
||
@Test | ||
public void settersHaveGetters() { | ||
for (Method method : config.getMethods()) { | ||
final String methodName = method.getName(); | ||
if (method.getParameterCount() != 1 || !methodName.startsWith("set")) { | ||
// Not an accessor, ignore | ||
continue; | ||
} | ||
|
||
final String s = methodName.substring(3); | ||
assertTrue(s, hasGetter(s)); | ||
} | ||
} | ||
|
||
private boolean hasGetter(String s) { | ||
List<String> candidates = Arrays.asList("get" + s, "is" + s); | ||
for (Method m : config.getMethods()) { | ||
if (m.getParameterCount() == 0 && candidates.contains(m.getName())) { | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
} |
This file contains 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