mirror of
https://github.com/SAP/jenkins-library.git
synced 2025-03-05 15:15:44 +02:00
Merge pull request #237 from SAP/CCFenner-patch-2
ConfigurationHelper: add condition to withMandatoryProperty
This commit is contained in:
commit
43d1576cd3
@ -162,8 +162,13 @@ class ConfigurationHelper implements Serializable {
|
||||
return paramValue
|
||||
}
|
||||
|
||||
def withMandatoryProperty(key, errorMessage = null){
|
||||
getMandatoryProperty(key, null, errorMessage)
|
||||
def withMandatoryProperty(key, errorMessage = null, condition = null){
|
||||
if(condition){
|
||||
if(condition(this.config))
|
||||
getMandatoryProperty(key, null, errorMessage)
|
||||
}else{
|
||||
getMandatoryProperty(key, null, errorMessage)
|
||||
}
|
||||
return this
|
||||
}
|
||||
}
|
||||
|
@ -248,4 +248,25 @@ class ConfigurationHelperTest {
|
||||
public void testWithMandoryParameterDefaultCustomFailureMessageNotProvidedSucceeds() {
|
||||
new ConfigurationHelper([myKey: 'myValue']).withMandatoryProperty('myKey')
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithMandoryWithFalseCondition() {
|
||||
new ConfigurationHelper([verify: false])
|
||||
.withMandatoryProperty('missingKey', null, { c -> return c.get('verify') })
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithMandoryWithTrueConditionMissingValue() {
|
||||
thrown.expect(IllegalArgumentException)
|
||||
thrown.expectMessage('ERROR - NO VALUE AVAILABLE FOR missingKey')
|
||||
|
||||
new ConfigurationHelper([verify: true])
|
||||
.withMandatoryProperty('missingKey', null, { c -> return c.get('verify') })
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithMandoryWithTrueConditionExistingValue() {
|
||||
new ConfigurationHelper([existingKey: 'anyValue', verify: true])
|
||||
.withMandatoryProperty('existingKey', null, { c -> return c.get('verify') })
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user