Move spring-boot tests utilities to main spring-boot.jar
Fixes gh-233
This commit is contained in:
		
							parent
							
								
									d53a52cf1a
								
							
						
					
					
						commit
						5627caa724
					
				| 
						 | 
				
			
			@ -130,23 +130,6 @@
 | 
			
		|||
			<scope>provided</scope>
 | 
			
		||||
		</dependency>
 | 
			
		||||
		<!-- Test -->
 | 
			
		||||
		<dependency>
 | 
			
		||||
			<groupId>${project.groupId}</groupId>
 | 
			
		||||
			<artifactId>spring-boot</artifactId>
 | 
			
		||||
			<version>${project.version}</version>
 | 
			
		||||
			<classifier>tests</classifier>
 | 
			
		||||
			<scope>test</scope>
 | 
			
		||||
			<exclusions>
 | 
			
		||||
				<exclusion>
 | 
			
		||||
					<groupId>${project.groupId}</groupId>
 | 
			
		||||
					<artifactId>spring-boot</artifactId>
 | 
			
		||||
				</exclusion>
 | 
			
		||||
				<exclusion>
 | 
			
		||||
					<groupId>commons-logging</groupId>
 | 
			
		||||
					<artifactId>commons-logging</artifactId>
 | 
			
		||||
				</exclusion>
 | 
			
		||||
			</exclusions>
 | 
			
		||||
		</dependency>
 | 
			
		||||
		<dependency>
 | 
			
		||||
			<groupId>org.javassist</groupId>
 | 
			
		||||
			<artifactId>javassist</artifactId>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -32,12 +32,12 @@ import org.junit.Assume;
 | 
			
		|||
import org.junit.rules.TestRule;
 | 
			
		||||
import org.junit.runner.Description;
 | 
			
		||||
import org.junit.runners.model.Statement;
 | 
			
		||||
import org.springframework.boot.OutputCapture;
 | 
			
		||||
import org.springframework.boot.cli.command.AbstractCommand;
 | 
			
		||||
import org.springframework.boot.cli.command.OptionParsingCommand;
 | 
			
		||||
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.cli.util.OutputCapture;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * {@link TestRule} that can be used to invoke CLI commands.
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -0,0 +1,127 @@
 | 
			
		|||
/*
 | 
			
		||||
 * 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.util;
 | 
			
		||||
 | 
			
		||||
import java.io.ByteArrayOutputStream;
 | 
			
		||||
import java.io.IOException;
 | 
			
		||||
import java.io.OutputStream;
 | 
			
		||||
import java.io.PrintStream;
 | 
			
		||||
 | 
			
		||||
import org.junit.rules.TestRule;
 | 
			
		||||
import org.junit.runner.Description;
 | 
			
		||||
import org.junit.runners.model.Statement;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Capture output from System.out and System.err.
 | 
			
		||||
 * 
 | 
			
		||||
 * @author Phillip Webb
 | 
			
		||||
 */
 | 
			
		||||
public class OutputCapture implements TestRule {
 | 
			
		||||
 | 
			
		||||
	private CaptureOutputStream captureOut;
 | 
			
		||||
 | 
			
		||||
	private CaptureOutputStream captureErr;
 | 
			
		||||
 | 
			
		||||
	private ByteArrayOutputStream copy;
 | 
			
		||||
 | 
			
		||||
	@Override
 | 
			
		||||
	public Statement apply(final Statement base, Description description) {
 | 
			
		||||
		return new Statement() {
 | 
			
		||||
			@Override
 | 
			
		||||
			public void evaluate() throws Throwable {
 | 
			
		||||
				captureOutput();
 | 
			
		||||
				try {
 | 
			
		||||
					base.evaluate();
 | 
			
		||||
				}
 | 
			
		||||
				finally {
 | 
			
		||||
					releaseOutput();
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
		};
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	protected void captureOutput() {
 | 
			
		||||
		this.copy = new ByteArrayOutputStream();
 | 
			
		||||
		this.captureOut = new CaptureOutputStream(System.out, this.copy);
 | 
			
		||||
		this.captureErr = new CaptureOutputStream(System.err, this.copy);
 | 
			
		||||
		System.setOut(new PrintStream(this.captureOut));
 | 
			
		||||
		System.setErr(new PrintStream(this.captureErr));
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	protected void releaseOutput() {
 | 
			
		||||
		System.setOut(this.captureOut.getOriginal());
 | 
			
		||||
		System.setErr(this.captureErr.getOriginal());
 | 
			
		||||
		this.copy = null;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public void flush() {
 | 
			
		||||
		try {
 | 
			
		||||
			this.captureOut.flush();
 | 
			
		||||
			this.captureErr.flush();
 | 
			
		||||
		}
 | 
			
		||||
		catch (IOException ex) {
 | 
			
		||||
			// ignore
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@Override
 | 
			
		||||
	public String toString() {
 | 
			
		||||
		flush();
 | 
			
		||||
		return this.copy.toString();
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	private static class CaptureOutputStream extends OutputStream {
 | 
			
		||||
 | 
			
		||||
		private final PrintStream original;
 | 
			
		||||
 | 
			
		||||
		private final OutputStream copy;
 | 
			
		||||
 | 
			
		||||
		public CaptureOutputStream(PrintStream original, OutputStream copy) {
 | 
			
		||||
			this.original = original;
 | 
			
		||||
			this.copy = copy;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		@Override
 | 
			
		||||
		public void write(int b) throws IOException {
 | 
			
		||||
			this.copy.write(b);
 | 
			
		||||
			this.original.write(b);
 | 
			
		||||
			this.original.flush();
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		@Override
 | 
			
		||||
		public void write(byte[] b) throws IOException {
 | 
			
		||||
			write(b, 0, b.length);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		@Override
 | 
			
		||||
		public void write(byte[] b, int off, int len) throws IOException {
 | 
			
		||||
			this.copy.write(b, off, len);
 | 
			
		||||
			this.original.write(b, off, len);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		public PrintStream getOriginal() {
 | 
			
		||||
			return this.original;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		@Override
 | 
			
		||||
		public void flush() throws IOException {
 | 
			
		||||
			this.copy.flush();
 | 
			
		||||
			this.original.flush();
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -20,9 +20,9 @@ import org.junit.After;
 | 
			
		|||
import org.junit.Before;
 | 
			
		||||
import org.junit.Rule;
 | 
			
		||||
import org.junit.Test;
 | 
			
		||||
import org.springframework.boot.OutputCapture;
 | 
			
		||||
import sample.aop.SampleAopApplication;
 | 
			
		||||
import org.springframework.boot.test.OutputCapture;
 | 
			
		||||
 | 
			
		||||
import sample.aop.SampleAopApplication;
 | 
			
		||||
import static org.junit.Assert.assertTrue;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -18,8 +18,8 @@ package sample.batch;
 | 
			
		|||
 | 
			
		||||
import org.junit.Rule;
 | 
			
		||||
import org.junit.Test;
 | 
			
		||||
import org.springframework.boot.OutputCapture;
 | 
			
		||||
import org.springframework.boot.SpringApplication;
 | 
			
		||||
import org.springframework.boot.test.OutputCapture;
 | 
			
		||||
 | 
			
		||||
import static org.junit.Assert.assertEquals;
 | 
			
		||||
import static org.junit.Assert.assertTrue;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -22,7 +22,7 @@ import java.io.IOException;
 | 
			
		|||
 | 
			
		||||
import org.junit.Rule;
 | 
			
		||||
import org.junit.Test;
 | 
			
		||||
import org.springframework.boot.OutputCapture;
 | 
			
		||||
import org.springframework.boot.test.OutputCapture;
 | 
			
		||||
import org.springframework.core.NestedCheckedException;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -18,7 +18,7 @@ package sample.data.redis;
 | 
			
		|||
 | 
			
		||||
import org.junit.Rule;
 | 
			
		||||
import org.junit.Test;
 | 
			
		||||
import org.springframework.boot.OutputCapture;
 | 
			
		||||
import org.springframework.boot.test.OutputCapture;
 | 
			
		||||
import org.springframework.data.redis.RedisConnectionFailureException;
 | 
			
		||||
 | 
			
		||||
import static org.junit.Assert.assertTrue;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -20,7 +20,7 @@ import org.junit.After;
 | 
			
		|||
import org.junit.Before;
 | 
			
		||||
import org.junit.Rule;
 | 
			
		||||
import org.junit.Test;
 | 
			
		||||
import org.springframework.boot.OutputCapture;
 | 
			
		||||
import org.springframework.boot.test.OutputCapture;
 | 
			
		||||
 | 
			
		||||
import static org.junit.Assert.assertTrue;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -20,7 +20,7 @@ import org.junit.After;
 | 
			
		|||
import org.junit.Before;
 | 
			
		||||
import org.junit.Rule;
 | 
			
		||||
import org.junit.Test;
 | 
			
		||||
import org.springframework.boot.OutputCapture;
 | 
			
		||||
import org.springframework.boot.test.OutputCapture;
 | 
			
		||||
 | 
			
		||||
import static org.junit.Assert.assertTrue;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -18,7 +18,7 @@ package sample.xml;
 | 
			
		|||
 | 
			
		||||
import org.junit.Rule;
 | 
			
		||||
import org.junit.Test;
 | 
			
		||||
import org.springframework.boot.OutputCapture;
 | 
			
		||||
import org.springframework.boot.test.OutputCapture;
 | 
			
		||||
 | 
			
		||||
import static org.junit.Assert.assertTrue;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -32,12 +32,6 @@
 | 
			
		|||
				<artifactId>spring-boot</artifactId>
 | 
			
		||||
				<version>0.5.0.BUILD-SNAPSHOT</version>
 | 
			
		||||
			</dependency>
 | 
			
		||||
			<dependency>
 | 
			
		||||
				<groupId>org.springframework.boot</groupId>
 | 
			
		||||
				<artifactId>spring-boot</artifactId>
 | 
			
		||||
				<version>0.5.0.BUILD-SNAPSHOT</version>
 | 
			
		||||
				<classifier>tests</classifier>
 | 
			
		||||
			</dependency>
 | 
			
		||||
			<dependency>
 | 
			
		||||
				<groupId>org.springframework.boot</groupId>
 | 
			
		||||
				<artifactId>spring-boot-starter</artifactId>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -18,12 +18,6 @@
 | 
			
		|||
			<artifactId>spring-boot-starter-logging</artifactId>
 | 
			
		||||
			<version>${project.version}</version>
 | 
			
		||||
		</dependency>
 | 
			
		||||
		<dependency>
 | 
			
		||||
			<groupId>${project.groupId}</groupId>
 | 
			
		||||
			<artifactId>spring-boot</artifactId>
 | 
			
		||||
			<classifier>tests</classifier>
 | 
			
		||||
			<version>${project.version}</version>
 | 
			
		||||
		</dependency>
 | 
			
		||||
		<dependency>
 | 
			
		||||
			<groupId>junit</groupId>
 | 
			
		||||
			<artifactId>junit</artifactId>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -39,6 +39,11 @@
 | 
			
		|||
			<artifactId>javax.servlet-api</artifactId>
 | 
			
		||||
			<optional>true</optional>
 | 
			
		||||
		</dependency>
 | 
			
		||||
		<dependency>
 | 
			
		||||
			<groupId>junit</groupId>
 | 
			
		||||
			<artifactId>junit</artifactId>
 | 
			
		||||
			<optional>true</optional>
 | 
			
		||||
		</dependency>
 | 
			
		||||
		<dependency>
 | 
			
		||||
			<groupId>log4j</groupId>
 | 
			
		||||
			<artifactId>log4j</artifactId>
 | 
			
		||||
| 
						 | 
				
			
			@ -89,6 +94,11 @@
 | 
			
		|||
			<artifactId>jul-to-slf4j</artifactId>
 | 
			
		||||
			<optional>true</optional>
 | 
			
		||||
		</dependency>
 | 
			
		||||
		<dependency>
 | 
			
		||||
			<groupId>org.springframework</groupId>
 | 
			
		||||
			<artifactId>spring-test</artifactId>
 | 
			
		||||
			<optional>true</optional>
 | 
			
		||||
		</dependency>
 | 
			
		||||
		<dependency>
 | 
			
		||||
			<groupId>org.springframework</groupId>
 | 
			
		||||
			<artifactId>spring-web</artifactId>
 | 
			
		||||
| 
						 | 
				
			
			@ -115,11 +125,6 @@
 | 
			
		|||
			<artifactId>tomcat-embed-logging-juli</artifactId>
 | 
			
		||||
			<scope>test</scope>
 | 
			
		||||
		</dependency>
 | 
			
		||||
		<dependency>
 | 
			
		||||
			<groupId>org.springframework</groupId>
 | 
			
		||||
			<artifactId>spring-test</artifactId>
 | 
			
		||||
			<scope>test</scope>
 | 
			
		||||
		</dependency>
 | 
			
		||||
		<dependency>
 | 
			
		||||
			<groupId>org.springframework</groupId>
 | 
			
		||||
			<artifactId>spring-webmvc</artifactId>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -14,7 +14,7 @@
 | 
			
		|||
 * limitations under the License.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
package org.springframework.boot;
 | 
			
		||||
package org.springframework.boot.test;
 | 
			
		||||
 | 
			
		||||
import java.io.ByteArrayOutputStream;
 | 
			
		||||
import java.io.IOException;
 | 
			
		||||
| 
						 | 
				
			
			@ -22,6 +22,7 @@ import java.util.List;
 | 
			
		|||
 | 
			
		||||
import org.junit.Rule;
 | 
			
		||||
import org.junit.Test;
 | 
			
		||||
import org.springframework.boot.test.OutputCapture;
 | 
			
		||||
import org.springframework.context.annotation.Configuration;
 | 
			
		||||
import org.springframework.util.ClassUtils;
 | 
			
		||||
import org.springframework.util.StringUtils;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -27,12 +27,12 @@ import org.junit.Before;
 | 
			
		|||
import org.junit.Rule;
 | 
			
		||||
import org.junit.Test;
 | 
			
		||||
import org.junit.rules.TemporaryFolder;
 | 
			
		||||
import org.springframework.boot.OutputCapture;
 | 
			
		||||
import org.springframework.boot.SpringApplication;
 | 
			
		||||
import org.springframework.boot.SpringApplicationStartEvent;
 | 
			
		||||
import org.springframework.boot.logging.LogLevel;
 | 
			
		||||
import org.springframework.boot.logging.java.JavaLoggingSystem;
 | 
			
		||||
import org.springframework.boot.test.EnvironmentTestUtils;
 | 
			
		||||
import org.springframework.boot.test.OutputCapture;
 | 
			
		||||
import org.springframework.context.support.GenericApplicationContext;
 | 
			
		||||
 | 
			
		||||
import static org.hamcrest.Matchers.containsString;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -23,8 +23,8 @@ import org.junit.After;
 | 
			
		|||
import org.junit.Before;
 | 
			
		||||
import org.junit.Rule;
 | 
			
		||||
import org.junit.Test;
 | 
			
		||||
import org.springframework.boot.OutputCapture;
 | 
			
		||||
import org.springframework.boot.logging.LogLevel;
 | 
			
		||||
import org.springframework.boot.test.OutputCapture;
 | 
			
		||||
import org.springframework.util.ClassUtils;
 | 
			
		||||
import org.springframework.util.StringUtils;
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -21,8 +21,8 @@ import org.junit.After;
 | 
			
		|||
import org.junit.Before;
 | 
			
		||||
import org.junit.Rule;
 | 
			
		||||
import org.junit.Test;
 | 
			
		||||
import org.springframework.boot.OutputCapture;
 | 
			
		||||
import org.springframework.boot.logging.LogLevel;
 | 
			
		||||
import org.springframework.boot.test.OutputCapture;
 | 
			
		||||
import org.springframework.util.StringUtils;
 | 
			
		||||
 | 
			
		||||
import static org.hamcrest.Matchers.equalTo;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -22,8 +22,8 @@ import org.junit.After;
 | 
			
		|||
import org.junit.Before;
 | 
			
		||||
import org.junit.Rule;
 | 
			
		||||
import org.junit.Test;
 | 
			
		||||
import org.springframework.boot.OutputCapture;
 | 
			
		||||
import org.springframework.boot.logging.LogLevel;
 | 
			
		||||
import org.springframework.boot.test.OutputCapture;
 | 
			
		||||
import org.springframework.util.StringUtils;
 | 
			
		||||
 | 
			
		||||
import static org.hamcrest.Matchers.equalTo;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue