Skip to content

Commit c8029ed

Browse files
committed
Add preconditions in BundledDependenciesTest
Ensure added dependencies exist in standard repos before running some tests in BundledDependenciesTest that would write other files we kepp track of.
1 parent 7dff49c commit c8029ed

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

plugins/dependencies/src/test/kotlin/de/fayard/refreshVersions/BundledDependenciesTest.kt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,16 @@ import kotlinx.coroutines.runBlocking
2828
import okhttp3.OkHttpClient
2929
import okhttp3.logging.HttpLoggingInterceptor
3030
import org.junit.jupiter.api.BeforeAll
31+
import org.junit.jupiter.api.MethodOrderer
32+
import org.junit.jupiter.api.Order
3133
import org.junit.jupiter.api.Test
34+
import org.junit.jupiter.api.TestMethodOrder
35+
import org.opentest4j.TestAbortedException
3236
import testutils.getVersionCandidates
3337
import testutils.isInCi
3438
import testutils.parseRemovedDependencyNotations
3539

40+
@TestMethodOrder(MethodOrderer.OrderAnnotation::class)
3641
class BundledDependenciesTest {
3742

3843
private object Files {
@@ -85,6 +90,14 @@ class BundledDependenciesTest {
8590
.joinToString(separator = "\n\n", postfix = "\n")
8691
if (file.readText() != content) file.writeText(content)
8792
}
93+
94+
private var dependenciesExistInStandardMavenReposPassed = false
95+
96+
@JvmStatic // Required for @BeforeAll
97+
@BeforeAll
98+
fun reset() {
99+
dependenciesExistInStandardMavenReposPassed = false
100+
}
88101
}
89102

90103
@Test
@@ -97,7 +110,9 @@ class BundledDependenciesTest {
97110
}
98111

99112
@Test
113+
@Order(2)
100114
fun `Removed dependency notations should be tracked`() {
115+
checkDependenciesExistInStandardRepos()
101116

102117
val existingMapping = Files.validatedMappingFile.useLines { lines ->
103118
lines.withoutComments().mapNotNull { DependencyMapping.fromLine(it) }.toSet()
@@ -177,7 +192,9 @@ class BundledDependenciesTest {
177192
}
178193

179194
@Test
195+
@Order(2)
180196
fun `Version keys should be up to date`() {
197+
checkDependenciesExistInStandardRepos()
181198
val versionKeyReader = ArtifactVersionKeyReader.fromRules(rulesDir.listFiles()!!.map { it.readText() })
182199

183200
val existingMapping = existingKeys.useLines { lines ->
@@ -216,7 +233,9 @@ class BundledDependenciesTest {
216233
}
217234

218235
@Test
236+
@Order(2)
219237
fun `Dependencies should not be in the 'dependencies' package`() {
238+
checkDependenciesExistInStandardRepos()
220239
getArtifactNameToConstantMapping().forEach {
221240
if (it.constantName.startsWith("dependencies.")) {
222241
fail("This dependency should not be in the dependencies package: ${it.constantName}")
@@ -225,7 +244,14 @@ class BundledDependenciesTest {
225244
}
226245
}
227246

247+
private fun checkDependenciesExistInStandardRepos() {
248+
if (dependenciesExistInStandardMavenReposPassed.not()) {
249+
throw TestAbortedException("Some dependencies don't exist in standard maven repos")
250+
}
251+
}
252+
228253
@Test
254+
@Order(1)
229255
fun `test bundled dependencies exist in standard repositories`() {
230256
val validatedDependencyMapping = validatedDependencyMappingFile.useLines { lines ->
231257
lines.withoutComments().toSet()
@@ -275,6 +301,7 @@ class BundledDependenciesTest {
275301
validatedDependencyMappingFile.writeText(mappings)
276302
}
277303
}
304+
dependenciesExistInStandardMavenReposPassed = true
278305
}
279306

280307
private val defaultHttpClient by lazy { createTestHttpClient() }

0 commit comments

Comments
 (0)