diff --git a/spring-boot-cli/pom.xml b/spring-boot-cli/pom.xml index b341437191b..b95d47ede0e 100644 --- a/spring-boot-cli/pom.xml +++ b/spring-boot-cli/pom.xml @@ -137,11 +137,6 @@ javax.servlet-api provided - - junit - junit - provided - org.springframework.boot @@ -154,6 +149,11 @@ spring-boot-test test + + junit + junit + test + diff --git a/spring-boot-cli/src/it/java/org/springframework/boot/cli/CommandLineIT.java b/spring-boot-cli/src/it/java/org/springframework/boot/cli/CommandLineIT.java index 6158cdf79b0..4a5949ee38c 100644 --- a/spring-boot-cli/src/it/java/org/springframework/boot/cli/CommandLineIT.java +++ b/spring-boot-cli/src/it/java/org/springframework/boot/cli/CommandLineIT.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2015 the original author or authors. + * Copyright 2012-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -45,7 +45,7 @@ public class CommandLineIT { assertThat(cli.await(), equalTo(0)); assertThat("Unexpected error: \n" + cli.getErrorOutput(), cli.getErrorOutput().length(), equalTo(0)); - assertThat(cli.getStandardOutputLines().size(), equalTo(11)); + assertThat(cli.getStandardOutputLines().size(), equalTo(10)); } @Test diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/DefaultCommandFactory.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/DefaultCommandFactory.java index 9e7b7104fd8..8c5813e9e76 100644 --- a/spring-boot-cli/src/main/java/org/springframework/boot/cli/DefaultCommandFactory.java +++ b/spring-boot-cli/src/main/java/org/springframework/boot/cli/DefaultCommandFactory.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2014 the original author or authors. + * Copyright 2012-2017 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,7 +30,6 @@ import org.springframework.boot.cli.command.init.InitCommand; import org.springframework.boot.cli.command.install.InstallCommand; import org.springframework.boot.cli.command.install.UninstallCommand; import org.springframework.boot.cli.command.run.RunCommand; -import org.springframework.boot.cli.command.test.TestCommand; /** * Default implementation of {@link CommandFactory}. @@ -40,9 +39,9 @@ import org.springframework.boot.cli.command.test.TestCommand; public class DefaultCommandFactory implements CommandFactory { private static final List DEFAULT_COMMANDS = Arrays.asList( - new VersionCommand(), new RunCommand(), new TestCommand(), new GrabCommand(), - new JarCommand(), new WarCommand(), new InstallCommand(), - new UninstallCommand(), new InitCommand()); + new VersionCommand(), new RunCommand(), new GrabCommand(), new JarCommand(), + new WarCommand(), new InstallCommand(), new UninstallCommand(), + new InitCommand()); @Override public Collection getCommands() { diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/test/TestCommand.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/test/TestCommand.java deleted file mode 100644 index 9a4cdf2ab89..00000000000 --- a/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/test/TestCommand.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright 2012-2016 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.boot.cli.command.test; - -import joptsimple.OptionSet; - -import org.springframework.boot.cli.command.Command; -import org.springframework.boot.cli.command.OptionParsingCommand; -import org.springframework.boot.cli.command.options.CompilerOptionHandler; -import org.springframework.boot.cli.command.options.OptionSetGroovyCompilerConfiguration; -import org.springframework.boot.cli.command.options.SourceOptions; -import org.springframework.boot.cli.command.status.ExitStatus; - -/** - * {@link Command} to run a groovy test script or scripts. - * - * @author Greg Turnquist - * @author Phillip Webb - */ -public class TestCommand extends OptionParsingCommand { - - public TestCommand() { - super("test", "Run a spring groovy script test", new TestOptionHandler()); - } - - @Override - public String getUsageHelp() { - return "[options] [--] [args]"; - } - - private static class TestOptionHandler extends CompilerOptionHandler { - - private TestRunner runner; - - @Override - protected ExitStatus run(OptionSet options) throws Exception { - SourceOptions sourceOptions = new SourceOptions(options); - TestRunnerConfiguration configuration = new TestRunnerConfigurationAdapter( - options, this); - this.runner = new TestRunner(configuration, sourceOptions.getSourcesArray(), - sourceOptions.getArgsArray()); - this.runner.compileAndRunTests(); - return ExitStatus.OK.hangup(); - } - - /** - * Simple adapter class to present the {@link OptionSet} as a - * {@link TestRunnerConfiguration}. - */ - private class TestRunnerConfigurationAdapter extends - OptionSetGroovyCompilerConfiguration implements TestRunnerConfiguration { - - TestRunnerConfigurationAdapter(OptionSet options, - CompilerOptionHandler optionHandler) { - super(options, optionHandler); - } - - } - - } - -} diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/test/TestFailedException.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/test/TestFailedException.java deleted file mode 100644 index 1b925bf124d..00000000000 --- a/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/test/TestFailedException.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright 2012-2014 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.boot.cli.command.test; - -import org.springframework.boot.cli.command.CommandException; - -/** - * Thrown when tests fail to execute. - * - * @author Graeme Rocher - * @since 1.2.0 - */ -public class TestFailedException extends CommandException { - - public TestFailedException(Throwable cause) { - super(cause, Option.HIDE_MESSAGE); - } - -} diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/test/TestRunner.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/test/TestRunner.java deleted file mode 100644 index 3b35d163cd3..00000000000 --- a/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/test/TestRunner.java +++ /dev/null @@ -1,176 +0,0 @@ -/* - * Copyright 2012-2017 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.boot.cli.command.test; - -import java.lang.annotation.Annotation; -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import org.springframework.boot.cli.compiler.GroovyCompiler; -import org.springframework.boot.groovy.DelegateTestRunner; -import org.springframework.util.ReflectionUtils; - -/** - * Compile and run groovy based tests. - * - * @author Phillip Webb - * @author Graeme Rocher - */ -public class TestRunner { - - private static final String JUNIT_TEST_ANNOTATION = "org.junit.Test"; - - private final String[] sources; - - private final GroovyCompiler compiler; - - private volatile Throwable threadException; - - /** - * Create a new {@link TestRunner} instance. - * @param configuration the configuration - * @param sources the sources - * @param args the args - */ - TestRunner(TestRunnerConfiguration configuration, String[] sources, String[] args) { - this.sources = sources.clone(); - this.compiler = new GroovyCompiler(configuration); - } - - public void compileAndRunTests() throws Exception { - Object[] sources = this.compiler.compile(this.sources); - if (sources.length == 0) { - throw new RuntimeException( - "No classes found in '" + Arrays.toString(this.sources) + "'"); - } - - // Run in new thread to ensure that the context classloader is setup - RunThread runThread = new RunThread(sources); - runThread.start(); - runThread.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() { - @Override - public void uncaughtException(Thread t, Throwable ex) { - TestRunner.this.threadException = ex; - } - }); - - runThread.join(); - if (this.threadException != null) { - TestFailedException ex = new TestFailedException(this.threadException); - this.threadException = null; - throw ex; - } - } - - /** - * Thread used to launch the Spring Application with the correct context classloader. - */ - private class RunThread extends Thread { - - private final Class[] testClasses; - - private final Class spockSpecificationClass; - - /** - * Create a new {@link RunThread} instance. - * @param sources the sources to launch - */ - RunThread(Object... sources) { - super("testrunner"); - setDaemon(true); - if (sources.length != 0 && sources[0] instanceof Class) { - setContextClassLoader(((Class) sources[0]).getClassLoader()); - } - this.spockSpecificationClass = loadSpockSpecificationClass( - getContextClassLoader()); - this.testClasses = getTestClasses(sources); - } - - private Class loadSpockSpecificationClass(ClassLoader contextClassLoader) { - try { - return getContextClassLoader().loadClass("spock.lang.Specification"); - } - catch (Exception ex) { - return null; - } - } - - private Class[] getTestClasses(Object[] sources) { - List> testClasses = new ArrayList<>(); - for (Object source : sources) { - if ((source instanceof Class) && isTestable((Class) source)) { - testClasses.add((Class) source); - } - } - return testClasses.toArray(new Class[testClasses.size()]); - } - - private boolean isTestable(Class sourceClass) { - return (isJunitTest(sourceClass) || isSpockTest(sourceClass)); - } - - private boolean isJunitTest(Class sourceClass) { - for (Method method : sourceClass.getMethods()) { - for (Annotation annotation : method.getAnnotations()) { - if (annotation.annotationType().getName() - .equals(JUNIT_TEST_ANNOTATION)) { - return true; - } - } - } - return false; - } - - private boolean isSpockTest(Class sourceClass) { - return (this.spockSpecificationClass != null - && this.spockSpecificationClass.isAssignableFrom(sourceClass)); - } - - @Override - public void run() { - try { - if (this.testClasses.length == 0) { - System.out.println("No tests found"); - } - else { - ClassLoader contextClassLoader = Thread.currentThread() - .getContextClassLoader(); - Class delegateClass = contextClassLoader - .loadClass(DelegateTestRunner.class.getName()); - Class resultClass = contextClassLoader - .loadClass("org.junit.runner.Result"); - Method runMethod = delegateClass.getMethod("run", Class[].class, - resultClass); - Object result = resultClass.newInstance(); - runMethod.invoke(null, this.testClasses, result); - boolean wasSuccessful = (Boolean) resultClass - .getMethod("wasSuccessful").invoke(result); - if (!wasSuccessful) { - throw new RuntimeException("Tests Failed."); - } - } - } - catch (Exception ex) { - ReflectionUtils.rethrowRuntimeException(ex); - } - } - - } - -} diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/test/TestRunnerConfiguration.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/test/TestRunnerConfiguration.java deleted file mode 100644 index 5cf8be8921a..00000000000 --- a/spring-boot-cli/src/main/java/org/springframework/boot/cli/command/test/TestRunnerConfiguration.java +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright 2012-2014 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.boot.cli.command.test; - -import org.springframework.boot.cli.compiler.GroovyCompilerConfiguration; - -/** - * Configuration for {@link TestRunner}. - * - * @author Phillip Webb - */ -public interface TestRunnerConfiguration extends GroovyCompilerConfiguration { - -} diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/autoconfigure/JUnitCompilerAutoConfiguration.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/autoconfigure/JUnitCompilerAutoConfiguration.java deleted file mode 100644 index bcacd76e0bf..00000000000 --- a/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/autoconfigure/JUnitCompilerAutoConfiguration.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright 2012-2016 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.boot.cli.compiler.autoconfigure; - -import org.codehaus.groovy.ast.ClassNode; -import org.codehaus.groovy.control.CompilationFailedException; -import org.codehaus.groovy.control.customizers.ImportCustomizer; - -import org.springframework.boot.cli.compiler.AstUtils; -import org.springframework.boot.cli.compiler.CompilerAutoConfiguration; -import org.springframework.boot.cli.compiler.DependencyCustomizer; - -/** - * {@link CompilerAutoConfiguration} for JUnit. - * - * @author Greg Turnquist - */ -public class JUnitCompilerAutoConfiguration extends CompilerAutoConfiguration { - - @Override - public boolean matches(ClassNode classNode) { - return AstUtils.hasAtLeastOneAnnotation(classNode, "Test"); - } - - @Override - public void applyDependencies(DependencyCustomizer dependencies) - throws CompilationFailedException { - dependencies.add("spring-boot-starter-test"); - } - - @Override - public void applyImports(ImportCustomizer imports) throws CompilationFailedException { - imports.addStarImports("org.junit").addStaticStars("org.junit.Assert") - .addStaticStars("org.hamcrest.MatcherAssert") - .addStaticStars("org.hamcrest.Matchers"); - } - -} diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/autoconfigure/SpockCompilerAutoConfiguration.java b/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/autoconfigure/SpockCompilerAutoConfiguration.java deleted file mode 100644 index 4f1157b27e9..00000000000 --- a/spring-boot-cli/src/main/java/org/springframework/boot/cli/compiler/autoconfigure/SpockCompilerAutoConfiguration.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright 2012-2013 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.boot.cli.compiler.autoconfigure; - -import org.codehaus.groovy.ast.ClassNode; -import org.codehaus.groovy.control.CompilationFailedException; -import org.codehaus.groovy.control.customizers.ImportCustomizer; - -import org.springframework.boot.cli.compiler.AstUtils; -import org.springframework.boot.cli.compiler.CompilerAutoConfiguration; -import org.springframework.boot.cli.compiler.DependencyCustomizer; - -/** - * {@link CompilerAutoConfiguration} for Spock test framework. - * - * @author Greg Turnquist - */ -public class SpockCompilerAutoConfiguration extends CompilerAutoConfiguration { - - @Override - public boolean matches(ClassNode classNode) { - return AstUtils.subclasses(classNode, "Specification"); - } - - @Override - public void applyDependencies(DependencyCustomizer dependencies) - throws CompilationFailedException { - dependencies.add("spock-core").add("junit").add("spring-test") - .add("hamcrest-library"); - } - - @Override - public void applyImports(ImportCustomizer imports) throws CompilationFailedException { - imports.addStarImports("spock.lang").addStarImports("org.junit") - .addStaticStars("org.junit.Assert") - .addStaticStars("org.hamcrest.MatcherAssert") - .addStaticStars("org.hamcrest.Matchers"); - } - -} diff --git a/spring-boot-cli/src/main/java/org/springframework/boot/groovy/DelegateTestRunner.java b/spring-boot-cli/src/main/java/org/springframework/boot/groovy/DelegateTestRunner.java deleted file mode 100644 index 9be59403962..00000000000 --- a/spring-boot-cli/src/main/java/org/springframework/boot/groovy/DelegateTestRunner.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright 2012-2014 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.boot.groovy; - -import org.junit.internal.TextListener; -import org.junit.runner.JUnitCore; -import org.junit.runner.Result; - -import org.springframework.boot.cli.command.test.TestRunner; - -/** - * Delegate test runner to launch tests in user application classpath. - * - * @author Phillip Webb - * @see TestRunner - */ -public final class DelegateTestRunner { - - private DelegateTestRunner() { - } - - public static void run(Class[] testClasses, Result result) { - JUnitCore jUnitCore = new JUnitCore(); - jUnitCore.addListener(new TextListener(System.out)); - jUnitCore.addListener(result.createListener()); - jUnitCore.run(testClasses); - } - -} diff --git a/spring-boot-cli/src/main/resources/META-INF/services/org.springframework.boot.cli.compiler.CompilerAutoConfiguration b/spring-boot-cli/src/main/resources/META-INF/services/org.springframework.boot.cli.compiler.CompilerAutoConfiguration index ca13e5d6e3c..3e699c3b054 100644 --- a/spring-boot-cli/src/main/resources/META-INF/services/org.springframework.boot.cli.compiler.CompilerAutoConfiguration +++ b/spring-boot-cli/src/main/resources/META-INF/services/org.springframework.boot.cli.compiler.CompilerAutoConfiguration @@ -6,8 +6,6 @@ org.springframework.boot.cli.compiler.autoconfigure.RabbitCompilerAutoConfigurat org.springframework.boot.cli.compiler.autoconfigure.CachingCompilerAutoConfiguration org.springframework.boot.cli.compiler.autoconfigure.JdbcCompilerAutoConfiguration org.springframework.boot.cli.compiler.autoconfigure.JmsCompilerAutoConfiguration -org.springframework.boot.cli.compiler.autoconfigure.JUnitCompilerAutoConfiguration -org.springframework.boot.cli.compiler.autoconfigure.SpockCompilerAutoConfiguration org.springframework.boot.cli.compiler.autoconfigure.TransactionManagementCompilerAutoConfiguration org.springframework.boot.cli.compiler.autoconfigure.SpringIntegrationCompilerAutoConfiguration org.springframework.boot.cli.compiler.autoconfigure.SpringSecurityOAuth2CompilerAutoConfiguration diff --git a/spring-boot-cli/src/test/java/org/springframework/boot/cli/CliTester.java b/spring-boot-cli/src/test/java/org/springframework/boot/cli/CliTester.java index b3de1913dd5..08f3bc96c6e 100644 --- a/spring-boot-cli/src/test/java/org/springframework/boot/cli/CliTester.java +++ b/spring-boot-cli/src/test/java/org/springframework/boot/cli/CliTester.java @@ -40,7 +40,6 @@ import org.springframework.boot.cli.command.OptionParsingCommand; import org.springframework.boot.cli.command.archive.JarCommand; import org.springframework.boot.cli.command.grab.GrabCommand; import org.springframework.boot.cli.command.run.RunCommand; -import org.springframework.boot.cli.command.test.TestCommand; import org.springframework.boot.test.rule.OutputCapture; import org.springframework.util.SocketUtils; @@ -77,17 +76,6 @@ public class CliTester implements TestRule { return getOutput(); } - public String test(String... args) throws Exception { - Future future = submitCommand(new TestCommand(), args); - try { - this.commands.add(future.get(this.timeout, TimeUnit.MILLISECONDS)); - return getOutput(); - } - catch (Exception ex) { - return getOutput(); - } - } - public String grab(String... args) throws Exception { Future future = submitCommand(new GrabCommand(), args); this.commands.add(future.get(this.timeout, TimeUnit.MILLISECONDS)); diff --git a/spring-boot-cli/src/test/java/org/springframework/boot/cli/TestCommandIntegrationTests.java b/spring-boot-cli/src/test/java/org/springframework/boot/cli/TestCommandIntegrationTests.java deleted file mode 100644 index 429a7e93857..00000000000 --- a/spring-boot-cli/src/test/java/org/springframework/boot/cli/TestCommandIntegrationTests.java +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright 2012-2016 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.boot.cli; - -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; - -import org.springframework.boot.cli.command.test.TestCommand; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Integration tests to exercise the CLI's test command. - * - * @author Greg Turnquist - * @author Phillip Webb - */ -public class TestCommandIntegrationTests { - - @Rule - public ExpectedException thrown = ExpectedException.none(); - - @Rule - public CliTester cli = new CliTester("test-samples/"); - - @Before - public void setUp() throws Exception { - System.setProperty("disableSpringSnapshotRepos", "false"); - } - - @After - public void tearDown() { - System.clearProperty("disableSpringSnapshotRepos"); - } - - @Test - public void noTests() throws Throwable { - String output = this.cli.test("book.groovy"); - assertThat(output).contains("No tests found"); - } - - @Test - public void empty() throws Exception { - String output = this.cli.test("empty.groovy"); - assertThat(output).contains("No tests found"); - } - - @Test - public void noFile() throws Exception { - TestCommand command = new TestCommand(); - this.thrown.expect(RuntimeException.class); - this.thrown.expectMessage("Can't find nothing.groovy"); - command.run("nothing.groovy"); - } - - @Test - public void appAndTestsInOneFile() throws Exception { - String output = this.cli.test("book_and_tests.groovy"); - assertThat(output).contains("OK (1 test)"); - } - - @Test - public void appInOneFileTestsInAnotherFile() throws Exception { - String output = this.cli.test("book.groovy", "test.groovy"); - assertThat(output).contains("OK (1 test)"); - } - - @Test - public void integrationTest() throws Exception { - String output = this.cli.test("integration.groovy"); - assertThat(output).contains("OK (1 test)"); - } - - @Test - public void integrationAutoConfigEmbeddedTest() throws Exception { - String output = this.cli.test("integration_auto.groovy"); - assertThat(output).contains("OK (1 test)"); - } - - @Test - public void integrationAutoConfigTest() throws Exception { - String output = this.cli.test("integration_auto_test.groovy", "app.groovy"); - assertThat(output).contains("OK (1 test)"); - } - - @Test - public void spockTester() throws Exception { - String output = this.cli.test("spock.groovy"); - assertThat(output).contains("OK (1 test)"); - } - - @Test - public void spockAndJunitTester() throws Exception { - String output = this.cli.test("spock.groovy", "book_and_tests.groovy"); - assertThat(output).contains("OK (2 tests)"); - } - - @Test - public void verifyFailures() throws Exception { - String output = this.cli.test("failures.groovy"); - assertThat(output).contains("Tests run: 5, Failures: 3"); - } - -} diff --git a/spring-boot-cli/src/test/java/org/springframework/boot/cli/command/test/TestRunnerTests.java b/spring-boot-cli/src/test/java/org/springframework/boot/cli/command/test/TestRunnerTests.java deleted file mode 100644 index 85d2e27c98c..00000000000 --- a/spring-boot-cli/src/test/java/org/springframework/boot/cli/command/test/TestRunnerTests.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright 2012-2015 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.boot.cli.command.test; - -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; - -import static org.hamcrest.Matchers.equalTo; -import static org.mockito.BDDMockito.given; -import static org.mockito.Mockito.mock; - -/** - * Tests for {@link TestRunner}. - * - * @author Andy Wilkinson - */ -public class TestRunnerTests { - - @Rule - public ExpectedException thrown = ExpectedException.none(); - - @Test - public void exceptionMessageWhenSourcesContainsNoClasses() throws Exception { - TestRunnerConfiguration configuration = mock(TestRunnerConfiguration.class); - given(configuration.getClasspath()).willReturn(new String[0]); - this.thrown.expect(RuntimeException.class); - this.thrown.expectMessage(equalTo("No classes found in '[foo, bar]'")); - new TestRunner(configuration, new String[] { "foo", "bar" }, new String[0]) - .compileAndRunTests(); - } - -} diff --git a/spring-boot-dependencies/pom.xml b/spring-boot-dependencies/pom.xml index a7c317713ca..550bb867190 100644 --- a/spring-boot-dependencies/pom.xml +++ b/spring-boot-dependencies/pom.xml @@ -152,7 +152,6 @@ 1.7.25 1.18 6.5.0 - 1.0-groovy-2.4 5.0.0.BUILD-SNAPSHOT 2.0.0.BUILD-SNAPSHOT 2.0.0.BUILD-SNAPSHOT diff --git a/spring-boot-docs/src/main/asciidoc/spring-boot-cli.adoc b/spring-boot-docs/src/main/asciidoc/spring-boot-cli.adoc index c6225833a6a..cddf6c22c3c 100644 --- a/spring-boot-docs/src/main/asciidoc/spring-boot-cli.adoc +++ b/spring-boot-docs/src/main/asciidoc/spring-boot-cli.adoc @@ -252,41 +252,6 @@ http://platform.spring.io/[Spring IO Platform], e.g. -[[cli-testing]] -=== Testing your code -The `test` command allows you to compile and run tests for your application. Typical -usage looks like this: - -[indent=0] ----- - $ spring test app.groovy tests.groovy - Total: 1, Success: 1, : Failures: 0 - Passed? true ----- - -In this example, `tests.groovy` contains JUnit `@Test` methods or Spock `Specification` -classes. All the common framework annotations and static methods should be available to -you without having to `import` them. - -Here is the `tests.groovy` file that we used above (with a JUnit test): - -[source,groovy,indent=0] ----- - class ApplicationTests { - - @Test - void homeSaysHello() { - assertEquals("Hello World!", new WebApplication().home()) - } - - } ----- - -TIP: If you have more than one test source files, you might prefer to organize them -into a `test` directory. - - - [[cli-multiple-source-files]] === Applications with multiple source files You can use "`shell globbing`" with all commands that accept file input. This allows you @@ -297,14 +262,6 @@ to easily use multiple files from a single directory, e.g. $ spring run *.groovy ---- -This technique can also be useful if you want to segregate your "`test`" or "`spec`" code -from the main application code: - -[indent=0] ----- - $ spring test app/*.groovy test/*.groovy ----- - [[cli-jar]] diff --git a/spring-boot-parent/pom.xml b/spring-boot-parent/pom.xml index 843141f2c10..f6a0f4270e4 100644 --- a/spring-boot-parent/pom.xml +++ b/spring-boot-parent/pom.xml @@ -25,6 +25,7 @@ UTF-8 UTF-8 3.1.1 + 1.0-groovy-2.4 http://github.com/spring-projects/spring-boot @@ -209,6 +210,22 @@ plexus-build-api 0.0.7 + + org.spockframework + spock-core + ${spock.version} + + + org.codehaus.groovy + groovy-all + + + + + org.spockframework + spock-spring + ${spock.version} + org.zeroturnaround zt-zip