Home How can I mock static calls to UUID using Spock
Reply: 1

How can I mock static calls to UUID using Spock

Ben Runchey
1#
Ben Runchey Published in 2018-01-12 20:52:40Z

I am using Grails 3.3.0 and am writing my tests using Spock. I have a UUID being generated within a method I am testing that I need to retrieve the value for in one of my assertions. I am not sure how to retrieve the generated UUID. I don't see anyway to do staticMocking in Spock. I have tried GroovyMock, but since UUID is not a groovy class it is not working well.

Any ideas?

Bryan G Campbell
2#
Bryan G Campbell Reply to 2018-01-12 22:45:04Z

I do this by

UUID.metaClass.'static'.randomUUID = { -> 'abc-def' }

Seems to work fine for me. Make sure you add a

@ConfineMetaClassChanged([UUID])

to your method

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.344173 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO