github.com/ouraigua/jenkins-library@v0.0.0-20231028010029-fbeaf2f3aa9b/test/groovy/util/JenkinsResetDefaultCacheRule.groovy (about)

     1  package util
     2  
     3  import org.junit.rules.TestRule
     4  import org.junit.runner.Description
     5  import org.junit.runners.model.Statement
     6  
     7  import com.lesfurets.jenkins.unit.BasePipelineTest
     8  import com.sap.piper.DefaultValueCache
     9  
    10  class JenkinsResetDefaultCacheRule implements TestRule {
    11  
    12  
    13      JenkinsResetDefaultCacheRule() {
    14          this(null)
    15      }
    16  
    17      //
    18      // Actually not needed. Only provided for the sake of consistency
    19      // with our other rules which comes with an constructor having the
    20      // test case contained in the signature.
    21      JenkinsResetDefaultCacheRule(BasePipelineTest testInstance) {
    22      }
    23  
    24      @Override
    25      Statement apply(Statement base, Description description) {
    26          return new Statement() {
    27              @Override
    28              void evaluate() throws Throwable {
    29                  DefaultValueCache.reset()
    30                  base.evaluate()
    31              }
    32          }
    33      }
    34  }