Skip to content

Commit 43b5440

Browse files
eduardboschkoral--
authored andcommitted
fix: ANY http method takes preference when comparing
1 parent d144099 commit 43b5440

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

dispatcher/src/main/kotlin/pl/droidsonroids/testing/mockwebserver/condition/PathQueryCondition.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ data class PathQueryCondition(
1919

2020
override fun compareTo(other: Condition) = when {
2121
other == this -> 0
22+
other is PathQueryCondition && httpMethod == HTTPMethod.ANY && httpMethod != other.httpMethod -> -1
2223
other is PathQueryCondition && score == other.score -> path.compareTo(other.path)
2324
other is PathQueryCondition && score > other.score -> -1
2425
else -> 1

dispatcher/src/test/kotlin/pl/droidsonroids/testing/mockwebserver/PathQueryConditionTest.kt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import org.assertj.core.api.Assertions.assertThat
77
import org.junit.Before
88
import org.junit.Test
99
import pl.droidsonroids.testing.mockwebserver.condition.Condition
10+
import pl.droidsonroids.testing.mockwebserver.condition.HTTPMethod
1011
import pl.droidsonroids.testing.mockwebserver.condition.PathQueryCondition
1112
import pl.droidsonroids.testing.mockwebserver.condition.PathQueryConditionFactory
1213

@@ -153,6 +154,17 @@ class PathQueryConditionTest {
153154
.isGreaterThan(0)
154155
}
155156

157+
@Test
158+
fun `compareTo should return -1 when the first condition has ANY http method and the second is different`() {
159+
val firstCondition = PathQueryConditionFactory()
160+
.withPathSuffix("/abc", HTTPMethod.ANY)
161+
val secondCondition = PathQueryConditionFactory()
162+
.withPathSuffix("/abc", HTTPMethod.GET)
163+
164+
assertThat(firstCondition.compareTo(secondCondition))
165+
.isEqualTo(-1)
166+
}
167+
156168
@Test
157169
fun `compareTo should return -1 when the first condition has a parameter name and the second one does not`() {
158170
val firstCondition = PathQueryConditionFactory()

0 commit comments

Comments
 (0)