Skip to content

Instantly share code, notes, and snippets.

@kimukou
Created April 27, 2011 07:36
Show Gist options
  • Save kimukou/943859 to your computer and use it in GitHub Desktop.
Save kimukou/943859 to your computer and use it in GitHub Desktop.
JavaのprivateなインナークラスをGroovyで何事も無かったかのようにテスト
package foobar;
public class A {
private static class B {
private static String staticMethod() {
return "static method";
}
private String instanceMethod() {
return "instance method";
}
}
private class C {
private String instanceMethod() {
return "instance method";
}
}
}
//
// using Groovy Console Java WebStart
//
@Grab('org.spockframework:spock-core:0.5-groovy-1.7')
@Grab(group='junit', module='junit', version='4.8.2')
public class A {
private static class B {
private static String staticMethod() {
return "static method";
}
private String instanceMethod() {
return "instance method";
}
}
private class C {
private String instanceMethod() {
return "instance method";
}
}
}
import spock.lang.*
class ASpec extends Specification{
def "private static class#static method"() {
expect:
A.B.staticMethod() == 'static method'
}
def "private static class#instance method"() {
expect:
new A.B().instanceMethod() == 'instance method'
}
def "private class#instance method"() {
expect:
new A.C().instanceMethod() == 'instance method'
}
}
new org.junit.runner.JUnitCore().run(ASpec).failureCount
apply plugin: 'groovy'
apply plugin: 'java'
repositories {
mavenLocal()
mavenCentral()
}
dependencies {
groovy 'org.codehaus.groovy:groovy-all:1.7.10'
testCompile 'org.spockframework:spock-core:0.5-groovy-1.7'
}
package foobar;
import spock.lang.*
class ASpec extends Specification {
def "private static class#static method"() {
expect:
A.B.staticMethod() == 'static method'
}
def "private static class#instance method"() {
expect:
new A.B().instanceMethod() == 'instance method'
}
def "private class#instance method"() {
expect:
new A.C().instanceMethod() == 'instance method'
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment