keeganwitt / gmock

Automatically exported from code.google.com/p/gmock
6 stars 2 forks source link

constructor mocking does not work for Java code #88

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
I think constructor mocking is not working if the constructor is called from 
Java code, but the 
same thing from Groovy code seems to work:

// FooTest.groovy
package foo;
class FooTest extends org.gmock.GMockTestCase
{
    void testIt()
    {
        File java = mock(File, constructor('a.txt'))
        File groovy = mock(File, constructor('b.txt'))
        play {
            new Foo().foo()
            new File('b.txt')
        }
    }
}

// Foo.java
package foo;
public class Foo
{
    public void foo()
    {
        new java.io.File("a.txt");
    }
}

Running GMock 0.8.0 with Groovy 1.6.3 and 1.6.4 on Linux.

Original issue reported on code.google.com by mar...@better.se on 2 Sep 2009 at 9:06

GoogleCodeExporter commented 9 years ago
Gmock doesn't support mocking constructor for Java code, but support for Groovy 
code.

We do not plan to support it as it is hard to implement and is not necessary.

Original comment by JohnnyJianHY on 2 Sep 2009 at 9:15