Commit ccd19ce2 authored by Andy Wilkinson's avatar Andy Wilkinson

Merge branch '1.3.x'

parents 6ed63a6e 275651e8
......@@ -16,11 +16,16 @@
package sample.data.cassandra;
import java.io.File;
import org.cassandraunit.spring.CassandraDataSet;
import org.cassandraunit.spring.EmbeddedCassandra;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.rules.TestRule;
import org.junit.runner.Description;
import org.junit.runner.RunWith;
import org.junit.runners.model.Statement;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.rule.OutputCapture;
......@@ -44,10 +49,35 @@ public class SampleCassandraApplicationTests {
@ClassRule
public static OutputCapture outputCapture = new OutputCapture();
@ClassRule
public static SkipOnWindows skipOnWindows = new SkipOnWindows();
@Test
public void testDefaultSettings() throws Exception {
String output = SampleCassandraApplicationTests.outputCapture.toString();
assertThat(output).contains("firstName='Alice', lastName='Smith'");
}
static class SkipOnWindows implements TestRule {
@Override
public Statement apply(final Statement base, Description description) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
if (!runningOnWindows()) {
base.evaluate();
}
}
private boolean runningOnWindows() {
return File.separatorChar == '\\';
}
};
}
}
}
......@@ -16,14 +16,17 @@
package sample.data.elasticsearch;
import java.net.ConnectException;
import java.io.File;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TestRule;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.test.rule.OutputCapture;
import org.springframework.core.NestedCheckedException;
import static org.assertj.core.api.Assertions.assertThat;
......@@ -33,34 +36,40 @@ import static org.assertj.core.api.Assertions.assertThat;
* @author Artur Konczak
*/
public class SampleElasticsearchApplicationTests {
@Rule
public OutputCapture outputCapture = new OutputCapture();
@ClassRule
public static SkipOnWindows skipOnWindows = new SkipOnWindows();
@Test
public void testDefaultSettings() throws Exception {
try {
new SpringApplicationBuilder(SampleElasticsearchApplication.class).run();
}
catch (IllegalStateException ex) {
if (serverNotRunning(ex)) {
return;
}
}
new SpringApplicationBuilder(SampleElasticsearchApplication.class).run();
String output = this.outputCapture.toString();
assertThat(output).contains("firstName='Alice', lastName='Smith'");
}
private boolean serverNotRunning(IllegalStateException ex) {
@SuppressWarnings("serial")
NestedCheckedException nested = new NestedCheckedException("failed", ex) {
};
if (nested.contains(ConnectException.class)) {
Throwable root = nested.getRootCause();
if (root.getMessage().contains("Connection refused")) {
return true;
}
static class SkipOnWindows implements TestRule {
@Override
public Statement apply(final Statement base, Description description) {
return new Statement() {
@Override
public void evaluate() throws Throwable {
if (!runningOnWindows()) {
base.evaluate();
}
}
private boolean runningOnWindows() {
return File.separatorChar == '\\';
}
};
}
return false;
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment