我在Java中实现了一个嵌套类,我需要从内部类调用外部类方法.
class Outer {
void show() {
System.out.println("outter show");
}
class Inner{
void show() {
System.out.println("inner show");
}
}
}
Run Code Online (Sandbox Code Playgroud)
我怎么称呼这个Outer方法show?
我可以像这样进行测试并将where子句数据表提取到可重用的块中吗?
@Unroll
void "test that doSomething with #a and #b does not fail"(String a, String b) {
when:
doSomethingWithAandB(a, b)
then:
notThrown(Exception)
where:
a | b
"foo" | "bar"
"foo" | "baz"
"foo" | "foo"
}
Run Code Online (Sandbox Code Playgroud)
像这样的东西(伪代码):
@Unroll
void "test that doSomethingElse with #a and #b does not fail"(String a, String b) {
when:
doSomethingElseWithAandB(a, b)
then:
notThrown(Exception)
where:
dataTable()
}
def dataTable(a, b) { // this is now reusable in multiple tests
a | b
"foo" | "bar"
"foo" …Run Code Online (Sandbox Code Playgroud) 我意识到在 SO 上有几个关于这个主题的类似未解决的问题,但是,我在 GitHub 上包含了一个可克隆的 MCVE,因此很容易重现问题场景。
设想
我正在尝试根据 Spring Boot文档实现一个 Spring Boot 退出代码生成器。看起来 Spring Boot 正在调用退出代码生成器,但应用程序以代码 0 退出,而不是给定的退出代码。我错过了什么?
@SpringBootApplication
@Configuration
@Slf4j
class App implements CommandLineRunner {
@Autowired ConfigurableApplicationContext ctx
static void main(String[] args) {
SpringApplication.run(App.class, args)
}
@Override
void run(String... args) throws Exception {
SpringApplication.exit(ctx, new ExitCodeGenerator() {
@Override
int getExitCode() {
log.info 'retrieving exit code.'
return -1
}
})
}
}
Run Code Online (Sandbox Code Playgroud)
输出:
C:\Users\pc\IdeaProjects\spring-exit-code-gen>gradlew bootRepackage
C:\Users\pc\IdeaProjects\spring-exit-code-gen>java -jar build/libs/spring-exit-code-gen-1-0.0.1-SNAPSHOT.jar
2017-09-13 12:26:53.819 INFO 2832 --- [ …Run Code Online (Sandbox Code Playgroud)