|
1 | 1 | package org.mockito
|
2 | 2 |
|
3 |
| -import org.mockito.WhenMacro._ |
4 | 3 | import org.mockito.stubbing.{ ScalaFirstStubbing, ScalaOngoingStubbing }
|
5 | 4 | import org.mockito.verification.VerificationMode
|
6 | 5 |
|
@@ -84,151 +83,12 @@ object IdiomaticMockitoBase {
|
84 | 83 | class ThrowActions[T](os: ScalaFirstStubbing[T]) {
|
85 | 84 | def apply[E <: Throwable](e: E*): ScalaOngoingStubbing[T] = os thenThrow (e: _*)
|
86 | 85 | }
|
87 |
| -} |
88 |
| - |
89 |
| -trait IdiomaticMockitoBase extends MockitoEnhancer with ScalacticSerialisableHack { |
90 |
| - import org.mockito.IdiomaticMockitoBase._ |
91 |
| - |
92 |
| - type Verification |
93 |
| - |
94 |
| - def verification(v: => Any): Verification |
95 |
| - |
96 |
| - implicit class StubbingOps[T](stubbing: T) { |
97 |
| - def shouldReturn: ReturnActions[T] = macro WhenMacro.shouldReturn[T] |
98 |
| - def mustReturn: ReturnActions[T] = macro WhenMacro.shouldReturn[T] |
99 |
| - def returns: ReturnActions[T] = macro WhenMacro.shouldReturn[T] |
100 |
| - |
101 |
| - def shouldCall(crm: RealMethod.type): ScalaOngoingStubbing[T] = macro WhenMacro.shouldCallRealMethod[T] |
102 |
| - def mustCall(crm: RealMethod.type): ScalaOngoingStubbing[T] = macro WhenMacro.shouldCallRealMethod[T] |
103 |
| - def calls(crm: RealMethod.type): ScalaOngoingStubbing[T] = macro WhenMacro.shouldCallRealMethod[T] |
104 |
| - |
105 |
| - def shouldThrow: ThrowActions[T] = macro WhenMacro.shouldThrow[T] |
106 |
| - def mustThrow: ThrowActions[T] = macro WhenMacro.shouldThrow[T] |
107 |
| - def throws: ThrowActions[T] = macro WhenMacro.shouldThrow[T] |
108 |
| - |
109 |
| - def shouldAnswer: AnswerActions[T] = macro WhenMacro.shouldAnswer[T] |
110 |
| - def mustAnswer: AnswerActions[T] = macro WhenMacro.shouldAnswer[T] |
111 |
| - def answers: AnswerActions[T] = macro WhenMacro.shouldAnswer[T] |
112 |
| - |
113 |
| - def shouldAnswerPF: AnswerPFActions[T] = macro WhenMacro.shouldAnswerPF[T] |
114 |
| - def mustAnswerPF: AnswerPFActions[T] = macro WhenMacro.shouldAnswerPF[T] |
115 |
| - def answersPF: AnswerPFActions[T] = macro WhenMacro.shouldAnswerPF[T] |
116 |
| - |
117 |
| - //noinspection AccessorLikeMethodIsUnit |
118 |
| - def isLenient(): Unit = macro WhenMacro.isLenient[T] |
119 |
| - |
120 |
| - def shouldDoNothing(): Unit = macro DoSomethingMacro.doesNothing |
121 |
| - def mustDoNothing(): Unit = macro DoSomethingMacro.doesNothing |
122 |
| - def doesNothing(): Unit = macro DoSomethingMacro.doesNothing |
123 |
| - } |
124 |
| - |
125 |
| - implicit class VerifyingOps[T](stubbing: T) { |
126 |
| - def was(called: Called.type)(implicit order: VerifyOrder): Verification = macro VerifyMacro.wasMacro[T, Verification] |
127 |
| - |
128 |
| - def wasNever(called: Called.type)(implicit order: VerifyOrder): Verification = macro VerifyMacro.wasMacro[T, Verification] |
129 |
| - |
130 |
| - def wasNever(called: CalledAgain)(implicit $ev: T <:< AnyRef): Verification = |
131 |
| - macro VerifyMacro.wasNeverCalledAgainMacro[T, Verification] |
132 |
| - |
133 |
| - def wasCalled(called: ScalaVerificationMode)(implicit order: VerifyOrder): Verification = macro VerifyMacro.wasMacro[T, Verification] |
134 |
| - } |
135 |
| - |
136 |
| - val called: Called.type = Called |
137 |
| - val thrown: Thrown.type = Thrown |
138 |
| - val returned: Returned.type = Returned |
139 |
| - val answered: Answered.type = Answered |
140 |
| - val theRealMethod: RealMethod.type = RealMethod |
141 |
| - |
142 |
| - implicit class DoSomethingOps[R](v: R) { |
143 |
| - def willBe(r: Returned.type): ReturnedBy[R] = ReturnedBy[R]() |
144 |
| - def willBe(a: Answered.type): AnsweredBy[R] = AnsweredBy[R]() |
145 |
| - } |
146 | 86 |
|
147 |
| - implicit class DoSomethingOps0[R](v: () => R) { |
148 |
| - def willBe(a: Answered.type): AnsweredBy[R] = AnsweredBy[R]() |
149 |
| - } |
150 |
| - implicit class DoSomethingOps1[P0, R](v: P0 => R) { |
151 |
| - def willBe(a: Answered.type): AnsweredBy[R] = AnsweredBy[R]() |
152 |
| - } |
153 |
| - implicit class DoSomethingOps2[P0, P1, R](v: (P0, P1) => R) { |
154 |
| - def willBe(a: Answered.type): AnsweredBy[R] = AnsweredBy[R]() |
155 |
| - } |
156 |
| - implicit class DoSomethingOps3[P0, P1, P2, R](v: (P0, P1, P2) => R) { |
157 |
| - def willBe(a: Answered.type): AnsweredBy[R] = AnsweredBy[R]() |
158 |
| - } |
159 |
| - implicit class DoSomethingOps4[P0, P1, P2, P3, R](v: (P0, P1, P2, P3) => R) { |
160 |
| - def willBe(a: Answered.type): AnsweredBy[R] = AnsweredBy[R]() |
161 |
| - } |
162 |
| - implicit class DoSomethingOps5[P0, P1, P2, P3, P4, R](v: (P0, P1, P2, P3, P4) => R) { |
163 |
| - def willBe(a: Answered.type): AnsweredBy[R] = AnsweredBy[R]() |
164 |
| - } |
165 |
| - implicit class DoSomethingOps6[P0, P1, P2, P3, P4, P5, R](v: (P0, P1, P2, P3, P4, P5) => R) { |
166 |
| - def willBe(a: Answered.type): AnsweredBy[R] = AnsweredBy[R]() |
167 |
| - } |
168 |
| - implicit class DoSomethingOps7[P0, P1, P2, P3, P4, P5, P6, R](v: (P0, P1, P2, P3, P4, P5, P6) => R) { |
169 |
| - def willBe(a: Answered.type): AnsweredBy[R] = AnsweredBy[R]() |
170 |
| - } |
171 |
| - implicit class DoSomethingOps8[P0, P1, P2, P3, P4, P5, P6, P7, R](v: (P0, P1, P2, P3, P4, P5, P6, P7) => R) { |
172 |
| - def willBe(a: Answered.type): AnsweredBy[R] = AnsweredBy[R]() |
173 |
| - } |
174 |
| - implicit class DoSomethingOps9[P0, P1, P2, P3, P4, P5, P6, P7, P8, R](v: (P0, P1, P2, P3, P4, P5, P6, P7, P8) => R) { |
175 |
| - def willBe(a: Answered.type): AnsweredBy[R] = AnsweredBy[R]() |
176 |
| - } |
177 |
| - implicit class DoSomethingOps10[P0, P1, P2, P3, P4, P5, P6, P7, P8, P9, R](v: (P0, P1, P2, P3, P4, P5, P6, P7, P8, P9) => R) { |
178 |
| - def willBe(a: Answered.type): AnsweredBy[R] = AnsweredBy[R]() |
179 |
| - } |
180 |
| - |
181 |
| - implicit class ThrowSomethingOps[E](v: E) { |
182 |
| - def willBe(thrown: Thrown.type): ThrownBy[E] = new ThrownBy[E] |
183 |
| - } |
184 |
| - |
185 |
| - val calledAgain: CalledAgain.type = CalledAgain |
186 |
| - val ignoringStubs: IgnoringStubs.type = IgnoringStubs |
187 |
| - |
188 |
| - val realMethod: RealMethod.type = RealMethod |
189 |
| - |
190 |
| - val on: On.type = On |
191 |
| - val onlyHere: OnlyOn.type = OnlyOn |
192 |
| - val once: Times = Times(1) |
193 |
| - val twice: Times = Times(2) |
194 |
| - val thrice: Times = Times(3) |
195 |
| - val threeTimes: Times = Times(3) |
196 |
| - val fourTimes: Times = Times(4) |
197 |
| - val fiveTimes: Times = Times(5) |
198 |
| - val sixTimes: Times = Times(6) |
199 |
| - val sevenTimes: Times = Times(7) |
200 |
| - val eightTimes: Times = Times(8) |
201 |
| - val nineTimes: Times = Times(9) |
202 |
| - val tenTimes: Times = Times(10) |
203 |
| - val atLeastOnce: AtLeast = AtLeast(1) |
204 |
| - val atLeastTwice: AtLeast = AtLeast(2) |
205 |
| - val atLeastThrice: AtLeast = AtLeast(3) |
206 |
| - val atLeastThreeTimes: AtLeast = AtLeast(3) |
207 |
| - val atLeastFourTimes: AtLeast = AtLeast(4) |
208 |
| - val atLeastFiveTimes: AtLeast = AtLeast(5) |
209 |
| - val atLeastSixTimes: AtLeast = AtLeast(6) |
210 |
| - val atLeastSevenTimes: AtLeast = AtLeast(7) |
211 |
| - val atLeastEightTimes: AtLeast = AtLeast(8) |
212 |
| - val atLeastNineTimes: AtLeast = AtLeast(9) |
213 |
| - val atLeastTenTimes: AtLeast = AtLeast(10) |
214 |
| - val atMostOnce: AtMost = AtMost(1) |
215 |
| - val atMostTwice: AtMost = AtMost(2) |
216 |
| - val atMostThrice: AtMost = AtMost(3) |
217 |
| - val atMostThreeTimes: AtMost = AtMost(3) |
218 |
| - val atMostFourTimes: AtMost = AtMost(4) |
219 |
| - val atMostFiveTimes: AtMost = AtMost(5) |
220 |
| - val atMostSixTimes: AtMost = AtMost(6) |
221 |
| - val atMostSevenTimes: AtMost = AtMost(7) |
222 |
| - val atMostEightTimes: AtMost = AtMost(8) |
223 |
| - val atMostNineTimes: AtMost = AtMost(9) |
224 |
| - val atMostTenTimes: AtMost = AtMost(10) |
225 |
| - |
226 |
| - def InOrder(mocks: AnyRef*)(verifications: VerifyInOrder => Verification): Verification = verifications(VerifyInOrder(mocks)) |
227 |
| - |
228 |
| - def atLeast(t: Times): AtLeast = AtLeast(t.times) |
229 |
| - def atMost(t: Times): AtMost = AtMost(t.times) |
230 |
| - |
231 |
| - implicit class IntOps(i: Int) { |
232 |
| - def times: Times = Times(i) |
| 87 | + // types for postfix verifications |
| 88 | + object CallWord |
| 89 | + object CallsWord { |
| 90 | + def apply(ignoringStubsWord: IgnoringStubs.type): CallsWord.type = this |
233 | 91 | }
|
234 | 92 | }
|
| 93 | + |
| 94 | +trait IdiomaticMockitoBase extends IdiomaticStubbing with PostfixVerifications |
0 commit comments