@@ -72,7 +72,7 @@ class MuzzleMavenRepoUtilsTest {
7272 versions = " [1.0,)"
7373 }
7474 val attempts = AtomicInteger ()
75- val retryingSystem = repositorySystemThrowingThenResolving (
75+ val retryingSystem = repositorySystemReturningAfterFailures (
7676 failuresBeforeSuccess = 3 ,
7777 result = createVersionRangeResult(" 1.0.0" ),
7878 attempts = attempts
@@ -150,7 +150,7 @@ class MuzzleMavenRepoUtilsTest {
150150 versions = " [1.0,)"
151151 }
152152 val attempts = AtomicInteger ()
153- val throwingSystem = repositorySystemThrowingThenResolving (
153+ val throwingSystem = repositorySystemReturningAfterFailures (
154154 failuresBeforeSuccess = 4 ,
155155 result = createVersionRangeResult(" 1.0.0" ),
156156 attempts = attempts
@@ -180,7 +180,15 @@ class MuzzleMavenRepoUtilsTest {
180180 versions = " [1.0,)"
181181 }
182182 val attempts = AtomicInteger ()
183- val failingSystem = repositorySystemReturningEmptyResultsWithExceptions(attempts)
183+ val emptyResult = createVersionRangeResult().apply {
184+ addException(
185+ IllegalStateException (
186+ " metadata failure" ,
187+ IOException (" download failure" )
188+ )
189+ )
190+ }
191+ val failingSystem = repositorySystemReturningAfterFailures(0 , emptyResult, attempts)
184192
185193 assertThatThrownBy {
186194 MuzzleMavenRepoUtils .resolveVersionRange(
@@ -194,10 +202,8 @@ class MuzzleMavenRepoUtilsTest {
194202 .hasMessageContaining(" Resolution result exceptions:" )
195203 .hasMessageContaining(" Attempt 1:" )
196204 .hasMessageContaining(" Attempt 4:" )
197- .hasMessageContaining(" java.lang.IllegalStateException: metadata failure 1" )
198- .hasMessageContaining(" Caused by: java.io.IOException: download failure 1" )
199- .hasMessageContaining(" java.lang.IllegalStateException: metadata failure 4" )
200- .hasMessageContaining(" Caused by: java.io.IOException: download failure 4" )
205+ .hasMessageContaining(" java.lang.IllegalStateException: metadata failure" )
206+ .hasMessageContaining(" Caused by: java.io.IOException: download failure" )
201207 assertThat(attempts).hasValue(4 )
202208 }
203209
@@ -358,7 +364,7 @@ class MuzzleMavenRepoUtilsTest {
358364 return VersionRangeResult (request).apply { this .versions = versions }
359365 }
360366
361- private fun repositorySystemThrowingThenResolving (
367+ private fun repositorySystemReturningAfterFailures (
362368 failuresBeforeSuccess : Int ,
363369 result : VersionRangeResult ,
364370 attempts : AtomicInteger
@@ -379,33 +385,9 @@ class MuzzleMavenRepoUtilsTest {
379385 }
380386 result
381387 }
382- " toString" -> " repositorySystemThrowingThenResolving "
388+ " toString" -> " repositorySystemReturningAfterFailures "
383389 else -> throw UnsupportedOperationException (method.name)
384390 }
385391 } as RepositorySystem
386392
387- private fun repositorySystemReturningEmptyResultsWithExceptions (
388- attempts : AtomicInteger
389- ): RepositorySystem =
390- Proxy .newProxyInstance(
391- RepositorySystem ::class .java.classLoader,
392- arrayOf(RepositorySystem ::class .java)
393- ) { _, method, args ->
394- when (method.name) {
395- " resolveVersionRange" -> {
396- val attempt = attempts.incrementAndGet()
397- val request = args?.get(1 ) as VersionRangeRequest
398- VersionRangeResult (request).apply {
399- addException(
400- IllegalStateException (
401- " metadata failure $attempt " ,
402- IOException (" download failure $attempt " )
403- )
404- )
405- }
406- }
407- " toString" -> " repositorySystemReturningEmptyResultsWithExceptions"
408- else -> throw UnsupportedOperationException (method.name)
409- }
410- } as RepositorySystem
411393}
0 commit comments