Replies: 1 comment
-
Is there a reason why you actually use Mockito instead of the integrated mocking / stubbing? @Grab("org.mockito:mockito-core:5.7.0")
import static org.mockito.Mockito.*
@Grab("org.spockframework:spock-core:2.3-groovy-4.0")
import spock.lang.Specification
class Foo extends Specification {
interface Mapper {
boolean tryLockTimeout(String lockKey, long waitTime, long leaseTime) throws InterruptedException;
}
def foo() {
given:
def mapper2 = mock(Mapper)
when:
when(mapper2.tryLockTimeout(anyString(), anyLong(), anyLong())).thenThrow(new InterruptedException("error"))
mapper2.tryLockTimeout("", 0, 0)
then:
thrown(InterruptedException)
}
} Without Mockito, this is also working just fine: @Grab("org.spockframework:spock-core:2.3-groovy-4.0")
import spock.lang.Specification
class Foo extends Specification {
interface Mapper {
boolean tryLockTimeout(String lockKey, long waitTime, long leaseTime) throws InterruptedException;
}
def foo() {
given:
Mapper mapper2 = Mock()
when:
mapper2.tryLockTimeout(*_) >> { throw new InterruptedException("error") }
mapper2.tryLockTimeout("", 0, 0)
then:
thrown(InterruptedException)
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
why no?
Beta Was this translation helpful? Give feedback.
All reactions