keeganwitt / gmock

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

Improve raises method #10

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Currently, raises can only be passed in an instance of Exception:
    mock.put(1, 2).raises(new IllegalArgumentException())
It is a little verbose by writing the keyword "new" and the parenthesis. 
We can improve it by allowing passing in a Class of Exception:
    mock.put(1, 2).raises(IllegalArgumentException)
    mock.put(1, 2).raises(IllegalArgumentException, "error message") // 
invoke the corresponding constructor
    mock.put(1, 2).raises(IllegalArgumentException, cause) // invoke the 
corresponding constructor

Original issue reported on code.google.com by JohnnyJianHY on 11 Oct 2008 at 3:07

GoogleCodeExporter commented 9 years ago

Original comment by julien.g...@gmail.com on 11 Oct 2008 at 3:29

GoogleCodeExporter commented 9 years ago
Fix in next release.

Original comment by JohnnyJianHY on 12 Oct 2008 at 2:50

GoogleCodeExporter commented 9 years ago

Original comment by JohnnyJianHY on 12 Oct 2008 at 12:30

GoogleCodeExporter commented 9 years ago
I am having a trouble while overloading the raises method like:
    def raises(Throwable exception){
        expectation.returnValue = new ReturnRaiseException(exception)
        return this
    }

    def raises(Class exceptionClass, Object[] params) {
        def exception = exceptionClass.metaClass.invokeConstructor(params)
        return raises(exception)
    }
but when I invoke the raises method like:
    mockLoader.load("key").raises(IllegalArgumentException, "message")
it throws an exception:
    groovy.lang.MissingMethodException: No signature of method: 
org.gmock.ReturnMethodRecorder.raises() is applicable for argument types: 
(java.lang.Class, java.lang.String) values: {class 
java.lang.IllegalArgumentException, "message"}

Is it a bug of Groovy? Are there any solution?

Original comment by JohnnyJianHY on 14 Oct 2008 at 5:08

GoogleCodeExporter commented 9 years ago
OK, I found the problem: I just edited MethodRecorder instead of 
ReturnMethodRecorder. I update ReturnMethodRecorder and the test is passed.

So, should we remove MethodRecorder? It seems ReturnMethodRecorder is renamed 
from 
MethodRecorder.

Original comment by JohnnyJianHY on 14 Oct 2008 at 5:26

GoogleCodeExporter commented 9 years ago
Yes you right MethodRecorder as been renamed to ReturnMethodRecorder. I am 
suprised
it didn't get renamed for you when you updated your project.

It's already deleted/renamed:
http://code.google.com/p/gmock/source/browse/#svn/trunk/src/main/groovy/org/gmoc
k so
we shouldn't have to do anything.

Original comment by julien.g...@gmail.com on 14 Oct 2008 at 6:53

GoogleCodeExporter commented 9 years ago
So I was wrong the file wasn't renamed. Need to be cautious with google's 
repository.

Original comment by julien.g...@gmail.com on 14 Oct 2008 at 7:02

GoogleCodeExporter commented 9 years ago

Original comment by JohnnyJianHY on 14 Oct 2008 at 7:03