diff --git a/spring-boot-samples/spring-boot-sample-data-cassandra/src/test/java/sample/data/cassandra/SampleCassandraApplicationTests.java b/spring-boot-samples/spring-boot-sample-data-cassandra/src/test/java/sample/data/cassandra/SampleCassandraApplicationTests.java index 74e9aa015f..b968ffa89e 100644 --- a/spring-boot-samples/spring-boot-sample-data-cassandra/src/test/java/sample/data/cassandra/SampleCassandraApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-data-cassandra/src/test/java/sample/data/cassandra/SampleCassandraApplicationTests.java @@ -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 == '\\'; + } + + }; + } + + } + } diff --git a/spring-boot-samples/spring-boot-sample-data-elasticsearch/src/test/java/sample/data/elasticsearch/SampleElasticsearchApplicationTests.java b/spring-boot-samples/spring-boot-sample-data-elasticsearch/src/test/java/sample/data/elasticsearch/SampleElasticsearchApplicationTests.java index c94efe24e9..a54119e955 100644 --- a/spring-boot-samples/spring-boot-sample-data-elasticsearch/src/test/java/sample/data/elasticsearch/SampleElasticsearchApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-data-elasticsearch/src/test/java/sample/data/elasticsearch/SampleElasticsearchApplicationTests.java @@ -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; + } }