move utils test classes to com.sap.piper folder

The folder com.sap.piper was created and the corresponding test classes
were not moved. Furthermore, a new UtilsTest class was created when this
test class did already exist, and the same tests were already
implemented, also this new test class uses the lesfurets testing
framework when it is not needed, so this new test class is removed and
the test class that there was before is kept.
This commit is contained in:
Alejandra Ferreiro Vidal
2018-02-09 18:08:11 +01:00
parent 68c666fab7
commit 5bfb68d24a
4 changed files with 18 additions and 93 deletions
-46
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'
}
}
+18 -47
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'
}
}