1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-14 11:03:09 +02:00

Merge pull request #77 from alejandraferreirovidal/moveUtilsTestClasses

move utils test classes to com.sap.piper folder
This commit is contained in:
Christopher Fenner 2018-02-12 08:41:34 +01:00 committed by GitHub
commit 2d51e0f8a4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 18 additions and 93 deletions

View File

@ -1,46 +0,0 @@
import org.junit.Rule
import org.junit.Before
import org.junit.Test
import org.junit.rules.ExpectedException
import com.sap.piper.Utils
class UtilsTest {
@Rule
public ExpectedException thrown = new ExpectedException().none()
private utils = new Utils()
private parameters
@Before
void setup() {
parameters = [:]
}
@Test
void noValueGetMandatoryParameterTest() {
thrown.expect(Exception)
thrown.expectMessage("ERROR - NO VALUE AVAILABLE FOR test")
utils.getMandatoryParameter(parameters, 'test', null)
}
@Test
void defaultValueGetMandatoryParameterTest() {
assert utils.getMandatoryParameter(parameters, 'test', 'default') == 'default'
}
@Test
void valueGetmandatoryParameterTest() {
parameters.put('test', 'value')
assert utils.getMandatoryParameter(parameters, 'test', null) == 'value'
}
}

View File

@ -1,75 +1,46 @@
package com.sap.piper
import com.lesfurets.jenkins.unit.BasePipelineTest
import org.junit.Before
import org.junit.Rule
import org.junit.Before
import org.junit.Test
import org.junit.rules.ExpectedException
import org.junit.rules.RuleChain
import util.Rules
import util.SharedLibraryCreator
import static org.hamcrest.Matchers.containsString
import static org.hamcrest.Matchers.hasSize
import static org.junit.Assert.assertEquals
import static org.junit.Assert.assertThat
import com.sap.piper.Utils
class UtilsTest extends BasePipelineTest {
class UtilsTest {
@Rule
public ExpectedException exception = ExpectedException.none()
public ExpectedException thrown = new ExpectedException().none()
@Rule
public RuleChain rules = Rules.getCommonRules(this, SharedLibraryCreator.lazyLoadedLibrary)
private utils = new Utils()
private parameters
Utils utils
@Before
void init() throws Exception {
utils = new Utils()
prepareObjectInterceptors(utils)
}
void setup() {
void prepareObjectInterceptors(object) {
object.metaClass.invokeMethod = helper.getMethodInterceptor()
object.metaClass.static.invokeMethod = helper.getMethodInterceptor()
object.metaClass.methodMissing = helper.getMethodMissingInterceptor()
parameters = [:]
}
@Test
void testGetMandatoryParameterValid() {
void noValueGetMandatoryParameterTest() {
def sourceMap = [test1: 'value1', test2: 'value2']
def defaultFallbackMap = [myDefault1: 'default1']
assertEquals('value1', utils.getMandatoryParameter(sourceMap, 'test1', null))
assertEquals('value1', utils.getMandatoryParameter(sourceMap, 'test1', ''))
assertEquals('value1', utils.getMandatoryParameter(sourceMap, 'test1', 'customValue'))
thrown.expect(Exception)
thrown.expectMessage("ERROR - NO VALUE AVAILABLE FOR test")
utils.getMandatoryParameter(parameters, 'test', null)
}
@Test
void testGetMandatoryParameterDefaultFallback() {
void defaultValueGetMandatoryParameterTest() {
def myMap = [test1: 'value1', test2: 'value2']
assertEquals('', utils.getMandatoryParameter(myMap, 'test3', ''))
assertEquals('customValue', utils.getMandatoryParameter(myMap, 'test3', 'customValue'))
assert utils.getMandatoryParameter(parameters, 'test', 'default') == 'default'
}
@Test
void testGetMandatoryParameterFail() {
void valueGetmandatoryParameterTest() {
def myMap = [test1: 'value1', test2: 'value2']
parameters.put('test', 'value')
exception.expect(Exception.class)
exception.expectMessage("ERROR - NO VALUE AVAILABLE FOR")
utils.getMandatoryParameter(myMap, 'test3', null)
assert utils.getMandatoryParameter(parameters, 'test', null) == 'value'
}
}