forked from mockk/mockk
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
mockk#510 | Convert List to Map for SignatureMatchers.
- Loading branch information
Showing
6 changed files
with
52 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 0 additions & 24 deletions
24
mockk/common/src/main/kotlin/io/mockk/impl/recording/SignatureMatchersList.kt
This file was deleted.
Oops, something went wrong.
31 changes: 31 additions & 0 deletions
31
mockk/common/src/main/kotlin/io/mockk/impl/recording/SignatureMatchersMap.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package io.mockk.impl.recording | ||
|
||
import io.mockk.Matcher | ||
|
||
class SignatureMatchersMap { | ||
private var matchers = mutableMapOf<List<Any?>, List<Matcher<*>>>() | ||
|
||
fun add(signature: List<Any?>, matcher: Matcher<*>) { | ||
val signatureMatchers = matchers[signature] ?: emptyList() | ||
matchers[signature] = signatureMatchers.plus(matcher) | ||
} | ||
|
||
fun remove(signature: List<Any?>): Matcher<*>? { | ||
val signatureMatchers = (matchers[signature] ?: emptyList()).toMutableList() | ||
val removedMatcher = if (signatureMatchers.size > 0) signatureMatchers.removeAt(0) else null | ||
|
||
if (signatureMatchers.isEmpty()) { | ||
matchers.remove(signature) } | ||
else { | ||
matchers[signature] = signatureMatchers.toList() | ||
} | ||
|
||
return removedMatcher | ||
} | ||
|
||
fun isNotEmpty() = matchers.isNotEmpty() | ||
|
||
override fun toString(): String { | ||
return matchers.flatMap { it.value }.toString() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters