Scriptrunner cannot cast service to object correctly

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

class SampleBean {
    private int field = 2
    int count() {
        return field

and my test which looks like this:

class BeanTest extends SrSpecification {

    def "test sample"() {
        MyPluginComponent myPluginComponent = ScriptRunnerImpl.getPluginComponent(MyPluginComponent)
        SampleBean sampleBean = ScriptRunnerImpl.getPluginComponent(SampleBean)
        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)