Skip to content

Commit 3c145df

Browse files
authored
Refactor: extract MacroConstants from Utils (#613)
1 parent 614ad21 commit 3c145df

2 files changed

Lines changed: 65 additions & 52 deletions

File tree

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package org.mockito
2+
3+
import scala.util.matching.Regex
4+
5+
/**
6+
* Constants used by macro implementations. Shared across Scala 2 and Scala 3.
7+
*/
8+
object MacroConstants {
9+
10+
val MockitoMatchers: Set[String] = Set(
11+
"anyByte",
12+
"anyBoolean",
13+
"anyChar",
14+
"anyDouble",
15+
"anyInt",
16+
"anyFloat",
17+
"anyShort",
18+
"anyLong",
19+
"anyList",
20+
"anySeq",
21+
"anyIterable",
22+
"anySet",
23+
"anyMap",
24+
"any",
25+
"anyVal",
26+
"$times", // *
27+
"isNull",
28+
"isNotNull",
29+
"eqTo",
30+
"eqToVal",
31+
"same",
32+
"isA",
33+
"refEq",
34+
"function0",
35+
"matches",
36+
"startsWith",
37+
"contains",
38+
"endsWith",
39+
"argThat",
40+
"byteThat",
41+
"booleanThat",
42+
"charThat",
43+
"doubleThat",
44+
"intThat",
45+
"floatThat",
46+
"shortThat",
47+
"longThat",
48+
"argMatching",
49+
"$greater", // >
50+
"$greater$eq", // >=
51+
"$less", // <
52+
"$less$eq", // <=
53+
"$eq$tilde", // =~
54+
"Captor.asCapture",
55+
"capture"
56+
)
57+
58+
private val Specs2Implicits: Regex = "(matcher)?[t,T]o(Partial)?FunctionCall(\\d*)".r
59+
60+
def isSpecs2Matcher(methodName: String): Boolean =
61+
Specs2Implicits.pattern.matcher(methodName).matches
62+
}

macro/src/main/scala/org/mockito/Utils.scala

Lines changed: 3 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,13 @@
11
package org.mockito
2+
3+
import org.mockito.MacroConstants.{ isSpecs2Matcher, MockitoMatchers }
4+
25
import scala.reflect.macros.blackbox
3-
import scala.util.matching.Regex
46

57
object Utils {
68
private[mockito] def hasMatchers(c: blackbox.Context)(args: List[c.Tree]): Boolean =
79
args.exists(arg => isMatcher(c)(arg))
810

9-
private val MockitoMatchers = Set(
10-
"anyByte",
11-
"anyBoolean",
12-
"anyChar",
13-
"anyDouble",
14-
"anyInt",
15-
"anyFloat",
16-
"anyShort",
17-
"anyLong",
18-
"anyList",
19-
"anySeq",
20-
"anyIterable",
21-
"anySet",
22-
"anyMap",
23-
"any",
24-
"anyVal",
25-
"$times", // *
26-
"isNull",
27-
"isNotNull",
28-
"eqTo",
29-
"eqToVal",
30-
"same",
31-
"isA",
32-
"refEq",
33-
"function0",
34-
"matches",
35-
"startsWith",
36-
"contains",
37-
"endsWith",
38-
"argThat",
39-
"byteThat",
40-
"booleanThat",
41-
"charThat",
42-
"doubleThat",
43-
"intThat",
44-
"floatThat",
45-
"shortThat",
46-
"longThat",
47-
"argMatching",
48-
"$greater", // >
49-
"$greater$eq", // >=
50-
"$less", // <
51-
"$less$eq", // <=
52-
"$eq$tilde", // =~
53-
"Captor.asCapture",
54-
"capture"
55-
)
56-
57-
private val specs2implicits: Regex = "(matcher)?[t,T]o(Partial)?FunctionCall(\\d*)".r
58-
private def isSpecs2Matcher(methodName: String): Boolean = specs2implicits.pattern.matcher(methodName).matches
59-
6011
private[mockito] def isMatcher(c: blackbox.Context)(arg: c.Tree): Boolean = {
6112
import c.universe.*
6213
if (arg.toString().contains("org.mockito.matchers.MacroMatchers")) true

0 commit comments

Comments
 (0)