spock-mockable
spock-mockable copied to clipboard
Overriding final of AtomicBoolean type doesn't work
I have been experimenting with Spock lately as a potential replacement for JUnit / Mockito in some unit tests I am working on and have been struggling with mocking of classes that have final fields and methods. I was hoping this Spock plugin might address at least some of my problems, but I can not get a very simple POC Spock test to work properly. The simplest example test I've found is shown below:
import java.util.concurrent.atomic.AtomicBoolean
@Mockable(AtomicBoolean)
class SampleTestSpec extends Specification {
def "Test Final Mock" () {
given:
AtomicBoolean activeFlag = Mock(AtomicBoolean.class)
activeFlag.get() >> [true, false]
expect:
// First true
activeFlag.get()
// Then false
!activeFlag.get()
}
}
I am quite new to Java and Spock so I am wondering if I am just doing something fundamentally wrong here, or if this is perhaps a bug with this plugin?