Mocks

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

Mocks

Bernd Schiffer
Hi.

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(dir.name == '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...

*idea*

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) } }
    mock.use{
        assertEquals(['foo'], new Foo().bar() }
    }
Any ideas?

   Bernd
 
--
Blog: http://berndschiffer.blogspot.com






   
       
___________________________________________________________
Der frühe Vogel fängt den Wurm. Hier gelangen Sie zum neuen Yahoo! Mail: http://mail.yahoo.de





               
___________________________________________________________
Telefonate ohne weitere Kosten vom PC zum PC: http://messenger.yahoo.de

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email