| career | drupal | java | mac | mysql | perl | scala | uml | unix  

Groovy example source code file (Groovy3139Bug.groovy)

This example Groovy source code file (Groovy3139Bug.groovy) is included in the "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Groovy tags/keywords

dummy, get2, get2, groovy3139bug, groovytestcase, string, string, stubfor, stubfor, url, url

The Groovy Groovy3139Bug.groovy source code

package groovy.bugs

import groovy.mock.interceptor.StubFor

class Groovy3139Bug extends GroovyTestCase {

    void testStubbingIssueDueToCachingWhenUsing2Stubs() {
        def urlStub1 = new StubFor(URL)
        urlStub1.demand.openConnection {""}
        urlStub1.use {
           def get = new Get2(url: "http://localhost")
           def result = get.text            

        def urlStub2 = new StubFor(URL)
        // the following stubbed call is on urlStub2 and its demand cound should be separate.
        // Currently due to caching of MockProxyMetaClass, it gets counted towards urlStub1 demands 
        // and throws "End of demands" exception
        urlStub2.demand.openConnection {""}
        urlStub2.use {
           def get = new Get2(url: "http://localhost")
           def result = get.text

class Get2{
    String url
    String getText() {
            def aUrl = new URL(toString())
            def conn = aUrl.openConnection()
            return "DUMMY"
    String toString(){
        return url

Other Groovy examples (source code examples)

Here is a short list of links related to this Groovy Groovy3139Bug.groovy source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller


new blog posts


Copyright 1998-2021 Alvin Alexander,
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.