classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view


Bernd Schiffer

Several questions about (mock) testing:

1.) Is it possible to mock a class, e.g. File, with the MockFor class or any other Groovy supported mechanism?
    new MockFor(File.class)
does not work, because Groovy does not know which constructor it should chose.

2.) How to mock a method with a closure? Example:
    class Foo {
        def bar() {
            dirs = []
            new File('.').eachDir{ dir -> if( == 'foo') dirs << dir }
            return dirs
More generally spoken, how can I test what is the logic inside the closure when the object the closure was called on has been mocked? Thinking a javaish way does not help me, because I would not use anonymous classes the way I would use it in Groovy...


This way?
    def mock = new MockFor(File.class) // assuming that it would work in some way
    mock.demand.eachDir() { c -> ['foo', 'bar'].each{ c(it) } }
        assertEquals(['foo'], new Foo().bar() }
Any ideas?


Der frühe Vogel fängt den Wurm. Hier gelangen Sie zum neuen Yahoo! Mail:

Telefonate ohne weitere Kosten vom PC zum PC:

To unsubscribe from this list please visit: