Scriptrunner cannot cast service to object correctly

I have my standard example generated by amps and another one in groovy:

@ExportAsService(SampleBean.class)
@Named("sampleBean")
class SampleBean {
    private int field = 2
    int count() {
        return field
    }
}

and my test which looks like this:

@WithPlugin("com.aptitude.aptitude-scriptrunner-plugin")
class BeanTest extends SrSpecification {

    def "test sample"() {
        when:
        MyPluginComponent myPluginComponent = ScriptRunnerImpl.getPluginComponent(MyPluginComponent)
        SampleBean sampleBean = ScriptRunnerImpl.getPluginComponent(SampleBean)
        then:
        myPluginComponent != null
        sampleBean != null
    }
}

And I keep getting error:

java.lang.Exception: Cannot cast object 'com.aptitude.bean.SampleBean@233e62ec' with class 'com.aptitude.bean.SampleBean' to class 'com.aptitude.bean.SampleBean'

But after small change everything works fine

def sampleBean = ScriptRunnerImpl.getPluginComponent(SampleBean)