From 5bfb68d24a386de48cf0763166a90b8b2e1f824c Mon Sep 17 00:00:00 2001 From: Alejandra Ferreiro Vidal Date: Fri, 9 Feb 2018 16:34:39 +0100 Subject: [PATCH] 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. --- test/groovy/UtilsTest.groovy | 46 ------------- .../{ => com/sap/piper}/FileUtilsTest.groovy | 0 test/groovy/com/sap/piper/UtilsTest.groovy | 65 +++++-------------- .../{ => com/sap/piper}/VersionTest.groovy | 0 4 files changed, 18 insertions(+), 93 deletions(-) delete mode 100644 test/groovy/UtilsTest.groovy rename test/groovy/{ => com/sap/piper}/FileUtilsTest.groovy (100%) rename test/groovy/{ => com/sap/piper}/VersionTest.groovy (100%) diff --git a/test/groovy/UtilsTest.groovy b/test/groovy/UtilsTest.groovy deleted file mode 100644 index 085ccd8c3..000000000 --- a/test/groovy/UtilsTest.groovy +++ /dev/null @@ -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' - } -} diff --git a/test/groovy/FileUtilsTest.groovy b/test/groovy/com/sap/piper/FileUtilsTest.groovy similarity index 100% rename from test/groovy/FileUtilsTest.groovy rename to test/groovy/com/sap/piper/FileUtilsTest.groovy diff --git a/test/groovy/com/sap/piper/UtilsTest.groovy b/test/groovy/com/sap/piper/UtilsTest.groovy index 99f9127bb..085ccd8c3 100644 --- a/test/groovy/com/sap/piper/UtilsTest.groovy +++ b/test/groovy/com/sap/piper/UtilsTest.groovy @@ -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' } } diff --git a/test/groovy/VersionTest.groovy b/test/groovy/com/sap/piper/VersionTest.groovy similarity index 100% rename from test/groovy/VersionTest.groovy rename to test/groovy/com/sap/piper/VersionTest.groovy