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/util/BasePiperTest.groovy
Marcus Holl dc9ce9a732 Remove generic gitUtils from BasePiperTest
there is only one test class making use of it left. This test class is the
GitUtilsTest itself.

Hence moving this member downwards in the test class hierarchy into GitUtilsTest.

I doubt it makes sense to make use of a generic git utils mock somewhere else since this basically
means to test the GitUtils class in the conxtext of other examinees. For that there is no need.
The GitUtils class should be tested by the corresponding test class, but not in a transive manner
by other tests. For all other tests a specific git utils mock should be provided mocking the corresponding
method class. This is already the case today, otherwise we would have more test classes making use
of the generic git utils mock.
2018-09-13 16:01:35 +02:00

51 lines
1.5 KiB
Groovy

#!groovy
package util
import com.lesfurets.jenkins.unit.BasePipelineTest
import com.sap.piper.GitUtils
import com.sap.piper.Utils
import org.junit.Before
import org.junit.runner.RunWith
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.test.context.ContextConfiguration
import org.springframework.test.context.TestExecutionListeners
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner
@RunWith(SpringJUnit4ClassRunner)
@ContextConfiguration(classes = [BasePiperTestContext.class])
@TestExecutionListeners(listeners = [LibraryLoadingTestExecutionListener.class], mergeMode = TestExecutionListeners.MergeMode.MERGE_WITH_DEFAULTS)
abstract class BasePiperTest extends BasePipelineTest {
@Autowired
Script nullScript
@Autowired
Utils utils
@Override
@Before
void setUp() throws Exception {
helper = LibraryLoadingTestExecutionListener.singletonInstance
if(!isHelperInitialized()) {
super.setScriptRoots('.', 'vars')
super.setUp()
}
}
boolean isHelperInitialized() {
try {
helper.loadScript('dummy.groovy')
} catch (Exception e) {
if (e.getMessage().startsWith('GroovyScriptEngine is not initialized:'))
return false
}
return true
}
@Deprecated
void prepareObjectInterceptors(Object object) {
LibraryLoadingTestExecutionListener.prepareObjectInterceptors(object)
}
}