issue with spock visibility of package private members declared in superclass

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

issue with spock visibility of package private members declared in superclass

Emiliano Capoccia
Hello group,

I'm having an issue with a spock test and I believe it's so basic that I must be doing something wrong.
Basically, I'm trying to access a package private (default) member declared in a superclass from a spock test, resulting in 

groovy.lang.MissingPropertyException: No such property: packagePrivate for class: my.pack.SubClass.

However if i define the superclass member to be protected or public it all works fine. (Spec package is same as the super and subclass).

Code below:
package my.pack;

public class BaseClass {
   
int packagePrivate = 3;
}
package my.pack;

public class SubClass extends BaseClass { }
package my.pack
import spock.lang.Specification
class SubClassSpec extends Specification {
   
def "should access package private member declared in superclass"() {
       
given:
           
def obj = new SubClass()
       
expect:
            obj
.packagePrivate == 3
    }
}

What am I doing wrong?

--
You received this message because you are subscribed to the Google Groups "Spock Framework - User" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/spockframework.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: issue with spock visibility of package private members declared in superclass

Russel Winder-2
I suggest that this is a Groovy issue rather than a Spock issue, you
might want to re-ask this on the Groovy users email list.

On Sat, 2016-04-23 at 06:11 -0700, Emiliano Capoccia wrote:

> Hello group,
>
> I'm having an issue with a spock test and I believe it's so basic
> that I 
> must be doing something wrong.
> Basically, I'm trying to access a package private (default) member
> declared 
> in a superclass from a spock test, resulting in 
>
> groovy.lang.MissingPropertyException: No such property:
> packagePrivate for 
> class: my.pack.SubClass.
>
> However if i define the superclass member to be protected or public
> it all 
> works fine. (Spec package is same as the super and subclass).
>
> Code below:
>
> package my.pack;
>
> public class BaseClass {
>     int packagePrivate = 3;
> }
>
> package my.pack;
>
> public class SubClass extends BaseClass { }
>
> package my.pack
> import spock.lang.Specification
> class SubClassSpec extends Specification {
>     def "should access package private member declared in
> superclass"() {
>         given:
>             def obj = new SubClass()
>         expect:
>             obj.packagePrivate == 3
>     }
> }
>
>
> What am I doing wrong?
>
--
Russel.
=============================================================================
Dr Russel Winder      t: +44 20 7585 2200   voip: sip:[hidden email]
41 Buckmaster Road    m: +44 7770 465 077   xmpp: [hidden email]
London SW11 1EN, UK   w: www.russel.org.uk  skype: russel_winder

--
You received this message because you are subscribed to the Google Groups "Spock Framework - User" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at https://groups.google.com/group/spockframework.
For more options, visit https://groups.google.com/d/optout.

signature.asc (836 bytes) Download Attachment
Loading...