Skip to content

Commit ccd19ce

Browse files
committed
Merge branch '1.3.x'
2 parents 6ed63a6 + 275651e commit ccd19ce

File tree

2 files changed

+59
-20
lines changed

2 files changed

+59
-20
lines changed

spring-boot-samples/spring-boot-sample-data-cassandra/src/test/java/sample/data/cassandra/SampleCassandraApplicationTests.java

+30
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,16 @@
1616

1717
package sample.data.cassandra;
1818

19+
import java.io.File;
20+
1921
import org.cassandraunit.spring.CassandraDataSet;
2022
import org.cassandraunit.spring.EmbeddedCassandra;
2123
import org.junit.ClassRule;
2224
import org.junit.Test;
25+
import org.junit.rules.TestRule;
26+
import org.junit.runner.Description;
2327
import org.junit.runner.RunWith;
28+
import org.junit.runners.model.Statement;
2429

2530
import org.springframework.boot.test.context.SpringBootTest;
2631
import org.springframework.boot.test.rule.OutputCapture;
@@ -44,10 +49,35 @@ public class SampleCassandraApplicationTests {
4449
@ClassRule
4550
public static OutputCapture outputCapture = new OutputCapture();
4651

52+
@ClassRule
53+
public static SkipOnWindows skipOnWindows = new SkipOnWindows();
54+
4755
@Test
4856
public void testDefaultSettings() throws Exception {
4957
String output = SampleCassandraApplicationTests.outputCapture.toString();
5058
assertThat(output).contains("firstName='Alice', lastName='Smith'");
5159
}
5260

61+
static class SkipOnWindows implements TestRule {
62+
63+
@Override
64+
public Statement apply(final Statement base, Description description) {
65+
return new Statement() {
66+
67+
@Override
68+
public void evaluate() throws Throwable {
69+
if (!runningOnWindows()) {
70+
base.evaluate();
71+
}
72+
}
73+
74+
private boolean runningOnWindows() {
75+
return File.separatorChar == '\\';
76+
}
77+
78+
};
79+
}
80+
81+
}
82+
5383
}

spring-boot-samples/spring-boot-sample-data-elasticsearch/src/test/java/sample/data/elasticsearch/SampleElasticsearchApplicationTests.java

+29-20
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,17 @@
1616

1717
package sample.data.elasticsearch;
1818

19-
import java.net.ConnectException;
19+
import java.io.File;
2020

21+
import org.junit.ClassRule;
2122
import org.junit.Rule;
2223
import org.junit.Test;
24+
import org.junit.rules.TestRule;
25+
import org.junit.runner.Description;
26+
import org.junit.runners.model.Statement;
2327

2428
import org.springframework.boot.builder.SpringApplicationBuilder;
2529
import org.springframework.boot.test.rule.OutputCapture;
26-
import org.springframework.core.NestedCheckedException;
2730

2831
import static org.assertj.core.api.Assertions.assertThat;
2932

@@ -33,34 +36,40 @@
3336
* @author Artur Konczak
3437
*/
3538
public class SampleElasticsearchApplicationTests {
39+
3640
@Rule
3741
public OutputCapture outputCapture = new OutputCapture();
3842

43+
@ClassRule
44+
public static SkipOnWindows skipOnWindows = new SkipOnWindows();
45+
3946
@Test
4047
public void testDefaultSettings() throws Exception {
41-
try {
42-
new SpringApplicationBuilder(SampleElasticsearchApplication.class).run();
43-
}
44-
catch (IllegalStateException ex) {
45-
if (serverNotRunning(ex)) {
46-
return;
47-
}
48-
}
48+
new SpringApplicationBuilder(SampleElasticsearchApplication.class).run();
4949
String output = this.outputCapture.toString();
5050
assertThat(output).contains("firstName='Alice', lastName='Smith'");
5151
}
5252

53-
private boolean serverNotRunning(IllegalStateException ex) {
54-
@SuppressWarnings("serial")
55-
NestedCheckedException nested = new NestedCheckedException("failed", ex) {
56-
};
57-
if (nested.contains(ConnectException.class)) {
58-
Throwable root = nested.getRootCause();
59-
if (root.getMessage().contains("Connection refused")) {
60-
return true;
61-
}
53+
static class SkipOnWindows implements TestRule {
54+
55+
@Override
56+
public Statement apply(final Statement base, Description description) {
57+
return new Statement() {
58+
59+
@Override
60+
public void evaluate() throws Throwable {
61+
if (!runningOnWindows()) {
62+
base.evaluate();
63+
}
64+
}
65+
66+
private boolean runningOnWindows() {
67+
return File.separatorChar == '\\';
68+
}
69+
70+
};
6271
}
63-
return false;
72+
6473
}
6574

6675
}

0 commit comments

Comments
 (0)