kiml | 6 Sep 10:06
Favicon

[groovy-user] =~ and Assert.assertTrue -> invokeStaticMissingMethod


Hello,

  I am beginner to groovy. I did some experiments with =~
I have problem with following code:

// runs well without problems
assert '12345' =~ /\d+/
boolean Fb_val = '12345' =~ /\d+/
Assert.assertTrue(Fb_val)

// throws MissingMethodException
Assert.assertTrue('12345' =~ /\d+/)

What is wrong ?

Greetings, Jiri
--

-- 
View this message in context: http://www.nabble.com/%3D%7E-and-Assert.assertTrue--%3E-invokeStaticMissingMethod-tp19344086p19344086.html
Sent from the groovy - user mailing list archive at Nabble.com.

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

    http://xircles.codehaus.org/manage_email

Roshan Dawrani | 6 Sep 10:28

Re: [groovy-user] =~ and Assert.assertTrue -> invokeStaticMissingMethod

It is because the expression '12345' =~ /\d+/ returns a matcher object and
assertTrue(Matcher) is not available on Assert class and that is why you see a method not found exception. What is available is Assert.assertTrue(Boolean).

So, for understanding's sake, instead of trying Assert.assertTrue('12345' =~ /\d+/), which is trying to invoke Assert.assertTrue(Matcher), if you try
Assert.assertTrue((boolean)('12345' =~ /\d+/)), it will now invoke Assert.assertTrue(Boolean), which goes through.

-- Roshan

On Sat, Sep 6, 2008 at 1:39 PM, kiml <jiri.kiml-SgvXgqTD8kc@public.gmane.org> wrote:

Hello,

 I am beginner to groovy. I did some experiments with =~
I have problem with following code:

// runs well without problems
assert '12345' =~ /\d+/
boolean Fb_val = '12345' =~ /\d+/
Assert.assertTrue(Fb_val)

// throws MissingMethodException
Assert.assertTrue('12345' =~ /\d+/)

What is wrong ?

Greetings, Jiri
--
View this message in context: http://www.nabble.com/%3D%7E-and-Assert.assertTrue--%3E-invokeStaticMissingMethod-tp19344086p19344086.html
Sent from the groovy - user mailing list archive at Nabble.com.


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

   http://xircles.codehaus.org/manage_email



Roshan Dawrani | 6 Sep 13:56

Re: [groovy-user] =~ and Assert.assertTrue -> invokeStaticMissingMethod

When you explicitly cast the matcher returned by '12345' =~ /\d+/ to boolean, internally groovy returns the value of matcher.find() which is a boolean and hence, with the boolean cast, the Assert.assertTrue() goes through whereas without it, it is like calling assertTrue(Matcher) - a method that does not exist.

HTH.
Roshan

On Sat, Sep 6, 2008 at 1:58 PM, Roshan Dawrani <roshandawrani-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
It is because the expression '12345' =~ /\d+/ returns a matcher object and
assertTrue(Matcher) is not available on Assert class and that is why you see a method not found exception. What is available is Assert.assertTrue(Boolean).

So, for understanding's sake, instead of trying Assert.assertTrue('12345' =~ /\d+/), which is trying to invoke Assert.assertTrue(Matcher), if you try
Assert.assertTrue((boolean)('12345' =~ /\d+/)), it will now invoke Assert.assertTrue(Boolean), which goes through.

-- Roshan


On Sat, Sep 6, 2008 at 1:39 PM, kiml <jiri.kiml-SgvXgqTD8kc@public.gmane.org> wrote:

Hello,

 I am beginner to groovy. I did some experiments with =~
I have problem with following code:

// runs well without problems
assert '12345' =~ /\d+/
boolean Fb_val = '12345' =~ /\d+/
Assert.assertTrue(Fb_val)

// throws MissingMethodException
Assert.assertTrue('12345' =~ /\d+/)

What is wrong ?

Greetings, Jiri
--
View this message in context: http://www.nabble.com/%3D%7E-and-Assert.assertTrue--%3E-invokeStaticMissingMethod-tp19344086p19344086.html
Sent from the groovy - user mailing list archive at Nabble.com.


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

   http://xircles.codehaus.org/manage_email





Gmane