1
0
mirror of https://github.com/SAP/jenkins-library.git synced 2024-12-14 11:03:09 +02:00
sap-jenkins-library/test/groovy/com/sap/piper/MapUtilsTest.groovy
Christopher Fenner 257308298d extract map merging to MapUtils (#156)
* Update MapUtils.groovy

* Update ConfigurationMerger.groovy

* tests

* forward skipNull

* Fix indent in tests

* More tests.

* MapUtils simplified wrt deep merge and pruneNulls

* Add test for isMap with null value
2018-06-20 10:15:36 +02:00

47 lines
1.1 KiB
Groovy

package com.sap.piper
import org.junit.Assert
import org.junit.Test
class MapUtilsTest {
@Test
void testIsMap(){
Assert.assertTrue('Map is not recognized as Map', MapUtils.isMap([:]))
Assert.assertTrue('String is recognized as Map', !MapUtils.isMap('I am not a Map'))
Assert.assertFalse('Null value is recognized as Map', MapUtils.isMap(null))
}
@Test
void testMergeMapStraigtForward(){
Map a = [a: '1',
c: [d: '1',
e: '2']],
b = [b: '2',
c: [d: 'x']];
Map merged = MapUtils.merge(a, b)
assert merged == [a: '1',
b: '2',
c: [d: 'x', e: '2']]
}
@Test
void testPruneNulls() {
Map m = [a: '1',
b: 2,
c: [ d: 'abc',
e: '',
n2: null],
n1: null]
assert MapUtils.pruneNulls(m) == [ a: '1',
b: 2,
c: [ d: 'abc',
e: '']]
}
}