@@ -8,6 +8,10 @@ import com.intellij.openapi.components.service
8
8
import com.intellij.openapi.project.Project
9
9
import com.intellij.testFramework.ApplicationRule
10
10
import kotlinx.coroutines.runBlocking
11
+ import org.junit.jupiter.api.extension.AfterEachCallback
12
+ import org.junit.jupiter.api.extension.BeforeEachCallback
13
+ import org.junit.jupiter.api.extension.ExtensionContext
14
+ import org.junit.runner.Description
11
15
import software.aws.toolkits.core.ConnectionSettings
12
16
import software.aws.toolkits.core.credentials.ToolkitCredentialsProvider
13
17
import software.aws.toolkits.core.region.AwsRegion
@@ -99,12 +103,30 @@ class MockResourceCache : AwsResourceCache {
99
103
}
100
104
}
101
105
102
- class MockResourceCacheRule : ApplicationRule () {
103
- private val cache by lazy { MockResourceCache .getInstance() }
106
+ class MockResourceCacheRule : ApplicationRule (), MockResourceCacheInterface by MockResourceCacheInterface.delegate() {
107
+ public override fun before (description : Description ) {
108
+ super .before(description)
109
+ }
104
110
105
- override fun after () {
111
+ public override fun after () {
106
112
runBlocking { cache.clear() }
107
113
}
114
+ }
115
+
116
+ class MockResourceCacheExtension : BeforeEachCallback , AfterEachCallback , MockResourceCacheInterface by MockResourceCacheInterface .delegate() {
117
+ private val rule = MockResourceCacheRule ()
118
+
119
+ override fun beforeEach (context : ExtensionContext ) {
120
+ rule.before(Description .EMPTY )
121
+ }
122
+
123
+ override fun afterEach (context : ExtensionContext ) {
124
+ rule.after()
125
+ }
126
+ }
127
+
128
+ interface MockResourceCacheInterface {
129
+ val cache: MockResourceCache
108
130
109
131
fun addEntry (resourceId : String , regionId : String , credentialsId : String , value : Any ) {
110
132
cache.addEntry(resourceId, regionId, credentialsId, value)
@@ -145,4 +167,10 @@ class MockResourceCacheRule : ApplicationRule() {
145
167
}
146
168
147
169
fun size () = cache.entryCount()
170
+
171
+ companion object {
172
+ fun delegate () = object : MockResourceCacheInterface {
173
+ override val cache by lazy { MockResourceCache .getInstance() }
174
+ }
175
+ }
148
176
}
0 commit comments