Created
April 27, 2011 07:36
-
-
Save kimukou/943859 to your computer and use it in GitHub Desktop.
JavaのprivateなインナークラスをGroovyで何事も無かったかのようにテスト
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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