Commit 1cc1fc64 authored by Phillip Webb's avatar Phillip Webb

Use AssertJ in spring-boot-samples

See gh-5083
parent 962a5985
...@@ -27,7 +27,7 @@ import org.springframework.boot.test.OutputCapture; ...@@ -27,7 +27,7 @@ import org.springframework.boot.test.OutputCapture;
import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import static org.junit.Assert.assertTrue; import static org.assertj.core.api.Assertions.assertThat;
/** /**
* Integration tests for demo application. * Integration tests for demo application.
...@@ -48,7 +48,7 @@ public class SampleActiveMqTests { ...@@ -48,7 +48,7 @@ public class SampleActiveMqTests {
public void sendSimpleMessage() throws InterruptedException, JMSException { public void sendSimpleMessage() throws InterruptedException, JMSException {
this.producer.send("Test message"); this.producer.send("Test message");
Thread.sleep(1000L); Thread.sleep(1000L);
assertTrue(this.outputCapture.toString().contains("Test message")); assertThat(this.outputCapture.toString().contains("Test message")).isTrue();
} }
} }
...@@ -30,7 +30,7 @@ import org.springframework.http.ResponseEntity; ...@@ -30,7 +30,7 @@ import org.springframework.http.ResponseEntity;
import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import static org.junit.Assert.assertEquals; import static org.assertj.core.api.Assertions.assertThat;
/** /**
* Basic integration tests for service demo application. * Basic integration tests for service demo application.
...@@ -51,10 +51,10 @@ public class SampleActuatorApplicationTests { ...@@ -51,10 +51,10 @@ public class SampleActuatorApplicationTests {
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
ResponseEntity<Map> entity = new TestRestTemplate() ResponseEntity<Map> entity = new TestRestTemplate()
.getForEntity("http://localhost:" + port, Map.class); .getForEntity("http://localhost:" + port, Map.class);
assertEquals(HttpStatus.OK, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Map<String, Object> body = entity.getBody(); Map<String, Object> body = entity.getBody();
assertEquals("Hello Daniel", body.get("message")); assertThat(body.get("message")).isEqualTo("Hello Daniel");
} }
} }
...@@ -25,7 +25,7 @@ import org.springframework.boot.test.SpringApplicationConfiguration; ...@@ -25,7 +25,7 @@ import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import static org.junit.Assert.assertNotNull; import static org.assertj.core.api.Assertions.assertThat;
/** /**
* Basic integration tests for service demo application. * Basic integration tests for service demo application.
...@@ -42,7 +42,7 @@ public class SampleActuatorNoWebApplicationTests { ...@@ -42,7 +42,7 @@ public class SampleActuatorNoWebApplicationTests {
@Test @Test
public void endpointsExist() throws Exception { public void endpointsExist() throws Exception {
assertNotNull(this.endpoint); assertThat(this.endpoint).isNotNull();
} }
} }
...@@ -30,7 +30,7 @@ import org.springframework.http.ResponseEntity; ...@@ -30,7 +30,7 @@ import org.springframework.http.ResponseEntity;
import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import static org.junit.Assert.assertEquals; import static org.assertj.core.api.Assertions.assertThat;
/** /**
* Integration tests for separate management and main service ports. * Integration tests for separate management and main service ports.
...@@ -53,7 +53,7 @@ public class SampleActuatorUiApplicationPortTests { ...@@ -53,7 +53,7 @@ public class SampleActuatorUiApplicationPortTests {
public void testHome() throws Exception { public void testHome() throws Exception {
ResponseEntity<String> entity = new TestRestTemplate() ResponseEntity<String> entity = new TestRestTemplate()
.getForEntity("http://localhost:" + this.port, String.class); .getForEntity("http://localhost:" + this.port, String.class);
assertEquals(HttpStatus.OK, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
} }
@Test @Test
...@@ -61,15 +61,15 @@ public class SampleActuatorUiApplicationPortTests { ...@@ -61,15 +61,15 @@ public class SampleActuatorUiApplicationPortTests {
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
ResponseEntity<Map> entity = new TestRestTemplate().getForEntity( ResponseEntity<Map> entity = new TestRestTemplate().getForEntity(
"http://localhost:" + this.managementPort + "/metrics", Map.class); "http://localhost:" + this.managementPort + "/metrics", Map.class);
assertEquals(HttpStatus.UNAUTHORIZED, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
} }
@Test @Test
public void testHealth() throws Exception { public void testHealth() throws Exception {
ResponseEntity<String> entity = new TestRestTemplate().getForEntity( ResponseEntity<String> entity = new TestRestTemplate().getForEntity(
"http://localhost:" + this.managementPort + "/health", String.class); "http://localhost:" + this.managementPort + "/health", String.class);
assertEquals(HttpStatus.OK, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertEquals("{\"status\":\"UP\"}", entity.getBody()); assertThat(entity.getBody()).isEqualTo("{\"status\":\"UP\"}");
} }
} }
...@@ -35,8 +35,7 @@ import org.springframework.http.ResponseEntity; ...@@ -35,8 +35,7 @@ import org.springframework.http.ResponseEntity;
import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import static org.junit.Assert.assertEquals; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertTrue;
/** /**
* Basic integration tests for demo application. * Basic integration tests for demo application.
...@@ -59,17 +58,16 @@ public class SampleActuatorUiApplicationTests { ...@@ -59,17 +58,16 @@ public class SampleActuatorUiApplicationTests {
ResponseEntity<String> entity = new TestRestTemplate().exchange( ResponseEntity<String> entity = new TestRestTemplate().exchange(
"http://localhost:" + this.port, HttpMethod.GET, "http://localhost:" + this.port, HttpMethod.GET,
new HttpEntity<Void>(headers), String.class); new HttpEntity<Void>(headers), String.class);
assertEquals(HttpStatus.OK, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertTrue("Wrong body (title doesn't match):\n" + entity.getBody(), assertThat(entity.getBody()).contains("<title>Hello");
entity.getBody().contains("<title>Hello"));
} }
@Test @Test
public void testCss() throws Exception { public void testCss() throws Exception {
ResponseEntity<String> entity = new TestRestTemplate().getForEntity( ResponseEntity<String> entity = new TestRestTemplate().getForEntity(
"http://localhost:" + this.port + "/css/bootstrap.min.css", String.class); "http://localhost:" + this.port + "/css/bootstrap.min.css", String.class);
assertEquals(HttpStatus.OK, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertTrue("Wrong body:\n" + entity.getBody(), entity.getBody().contains("body")); assertThat(entity.getBody()).contains("body");
} }
@Test @Test
...@@ -77,7 +75,7 @@ public class SampleActuatorUiApplicationTests { ...@@ -77,7 +75,7 @@ public class SampleActuatorUiApplicationTests {
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
ResponseEntity<Map> entity = new TestRestTemplate() ResponseEntity<Map> entity = new TestRestTemplate()
.getForEntity("http://localhost:" + this.port + "/metrics", Map.class); .getForEntity("http://localhost:" + this.port + "/metrics", Map.class);
assertEquals(HttpStatus.UNAUTHORIZED, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
} }
@Test @Test
...@@ -87,13 +85,9 @@ public class SampleActuatorUiApplicationTests { ...@@ -87,13 +85,9 @@ public class SampleActuatorUiApplicationTests {
ResponseEntity<String> entity = new TestRestTemplate().exchange( ResponseEntity<String> entity = new TestRestTemplate().exchange(
"http://localhost:" + this.port + "/error", HttpMethod.GET, "http://localhost:" + this.port + "/error", HttpMethod.GET,
new HttpEntity<Void>(headers), String.class); new HttpEntity<Void>(headers), String.class);
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
assertTrue("Wrong body:\n" + entity.getBody(), assertThat(entity.getBody()).contains("<html>").contains("<body>")
entity.getBody().contains("<html>")); .contains("Please contact the operator with the above information");
assertTrue("Wrong body:\n" + entity.getBody(),
entity.getBody().contains("<body>"));
assertTrue("Wrong body:\n" + entity.getBody(), entity.getBody()
.contains("Please contact the operator with the above information"));
} }
} }
...@@ -33,8 +33,7 @@ import org.springframework.test.annotation.DirtiesContext; ...@@ -33,8 +33,7 @@ import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import static org.junit.Assert.assertEquals; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertTrue;
/** /**
* Integration tests for endpoints configuration. * Integration tests for endpoints configuration.
...@@ -59,11 +58,11 @@ public class EndpointsPropertiesSampleActuatorApplicationTests { ...@@ -59,11 +58,11 @@ public class EndpointsPropertiesSampleActuatorApplicationTests {
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
ResponseEntity<Map> entity = new TestRestTemplate("user", getPassword()) ResponseEntity<Map> entity = new TestRestTemplate("user", getPassword())
.getForEntity("http://localhost:" + this.port + "/oops", Map.class); .getForEntity("http://localhost:" + this.port + "/oops", Map.class);
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Map<String, Object> body = entity.getBody(); Map<String, Object> body = entity.getBody();
assertEquals("None", body.get("error")); assertThat(body.get("error")).isEqualTo("None");
assertEquals(999, body.get("status")); assertThat(body.get("status")).isEqualTo(999);
} }
@Test @Test
...@@ -71,12 +70,9 @@ public class EndpointsPropertiesSampleActuatorApplicationTests { ...@@ -71,12 +70,9 @@ public class EndpointsPropertiesSampleActuatorApplicationTests {
ResponseEntity<String> entity = new TestRestTemplate("user", getPassword()) ResponseEntity<String> entity = new TestRestTemplate("user", getPassword())
.getForEntity("http://localhost:" + this.port + "/admin/health", .getForEntity("http://localhost:" + this.port + "/admin/health",
String.class); String.class);
assertEquals(HttpStatus.OK, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertTrue("Wrong body: " + entity.getBody(), assertThat(entity.getBody()).contains("\"status\":\"UP\"");
entity.getBody().contains("\"status\":\"UP\"")); assertThat(entity.getBody()).contains("\"hello\":\"world\"");
System.err.println(entity.getBody());
assertTrue("Wrong body: " + entity.getBody(),
entity.getBody().contains("\"hello\":\"world\""));
} }
private String getPassword() { private String getPassword() {
......
...@@ -32,8 +32,7 @@ import org.springframework.http.ResponseEntity; ...@@ -32,8 +32,7 @@ import org.springframework.http.ResponseEntity;
import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import static org.junit.Assert.assertEquals; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertTrue;
/** /**
* Integration tests for separate management and main service ports. * Integration tests for separate management and main service ports.
...@@ -61,10 +60,10 @@ public class InsecureManagementPortAndPathSampleActuatorApplicationTests { ...@@ -61,10 +60,10 @@ public class InsecureManagementPortAndPathSampleActuatorApplicationTests {
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
ResponseEntity<Map> entity = new TestRestTemplate("user", getPassword()) ResponseEntity<Map> entity = new TestRestTemplate("user", getPassword())
.getForEntity("http://localhost:" + this.port, Map.class); .getForEntity("http://localhost:" + this.port, Map.class);
assertEquals(HttpStatus.OK, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Map<String, Object> body = entity.getBody(); Map<String, Object> body = entity.getBody();
assertEquals("Hello Phil", body.get("message")); assertThat(body.get("message")).isEqualTo("Hello Phil");
} }
@Test @Test
...@@ -73,7 +72,7 @@ public class InsecureManagementPortAndPathSampleActuatorApplicationTests { ...@@ -73,7 +72,7 @@ public class InsecureManagementPortAndPathSampleActuatorApplicationTests {
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
ResponseEntity<Map> entity = new TestRestTemplate().getForEntity( ResponseEntity<Map> entity = new TestRestTemplate().getForEntity(
"http://localhost:" + this.managementPort + "/admin/metrics", Map.class); "http://localhost:" + this.managementPort + "/admin/metrics", Map.class);
assertEquals(HttpStatus.OK, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
} }
@Test @Test
...@@ -81,9 +80,8 @@ public class InsecureManagementPortAndPathSampleActuatorApplicationTests { ...@@ -81,9 +80,8 @@ public class InsecureManagementPortAndPathSampleActuatorApplicationTests {
ResponseEntity<String> entity = new TestRestTemplate().getForEntity( ResponseEntity<String> entity = new TestRestTemplate().getForEntity(
"http://localhost:" + this.managementPort + "/admin/health", "http://localhost:" + this.managementPort + "/admin/health",
String.class); String.class);
assertEquals(HttpStatus.OK, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertTrue("Wrong body: " + entity.getBody(), assertThat(entity.getBody()).contains("\"status\":\"UP\"");
entity.getBody().contains("\"status\":\"UP\""));
} }
@Test @Test
...@@ -91,9 +89,8 @@ public class InsecureManagementPortAndPathSampleActuatorApplicationTests { ...@@ -91,9 +89,8 @@ public class InsecureManagementPortAndPathSampleActuatorApplicationTests {
ResponseEntity<String> entity = new TestRestTemplate().getForEntity( ResponseEntity<String> entity = new TestRestTemplate().getForEntity(
"http://localhost:" + this.managementPort + "/admin/missing", "http://localhost:" + this.managementPort + "/admin/missing",
String.class); String.class);
assertEquals(HttpStatus.NOT_FOUND, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
assertTrue("Wrong body: " + entity.getBody(), assertThat(entity.getBody()).contains("\"status\":404");
entity.getBody().contains("\"status\":404"));
} }
private String getPassword() { private String getPassword() {
......
...@@ -31,9 +31,7 @@ import org.springframework.test.annotation.DirtiesContext; ...@@ -31,9 +31,7 @@ import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import static org.junit.Assert.assertEquals; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
/** /**
* Integration tests for insecured service endpoints (even with Spring Security on * Integration tests for insecured service endpoints (even with Spring Security on
...@@ -56,12 +54,11 @@ public class InsecureManagementSampleActuatorApplicationTests { ...@@ -56,12 +54,11 @@ public class InsecureManagementSampleActuatorApplicationTests {
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
ResponseEntity<Map> entity = new TestRestTemplate() ResponseEntity<Map> entity = new TestRestTemplate()
.getForEntity("http://localhost:" + this.port, Map.class); .getForEntity("http://localhost:" + this.port, Map.class);
assertEquals(HttpStatus.UNAUTHORIZED, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Map<String, Object> body = entity.getBody(); Map<String, Object> body = entity.getBody();
assertEquals("Wrong body: " + body, "Unauthorized", body.get("error")); assertThat(body.get("error")).isEqualTo("Unauthorized");
assertFalse("Wrong headers: " + entity.getHeaders(), assertThat(entity.getHeaders()).doesNotContainKey("Set-Cookie");
entity.getHeaders().containsKey("Set-Cookie"));
} }
@Test @Test
...@@ -75,11 +72,10 @@ public class InsecureManagementSampleActuatorApplicationTests { ...@@ -75,11 +72,10 @@ public class InsecureManagementSampleActuatorApplicationTests {
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
ResponseEntity<Map> entity = new TestRestTemplate() ResponseEntity<Map> entity = new TestRestTemplate()
.getForEntity("http://localhost:" + this.port + "/metrics", Map.class); .getForEntity("http://localhost:" + this.port + "/metrics", Map.class);
assertEquals(HttpStatus.OK, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Map<String, Object> body = entity.getBody(); Map<String, Object> body = entity.getBody();
assertTrue("Wrong body: " + body, assertThat(body).containsKey("counter.status.401.unmapped");
body.containsKey("counter.status.401.unmapped"));
} }
} }
...@@ -30,8 +30,7 @@ import org.springframework.http.ResponseEntity; ...@@ -30,8 +30,7 @@ import org.springframework.http.ResponseEntity;
import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import static org.junit.Assert.assertEquals; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertFalse;
/** /**
* Integration tests for insecured service endpoints (even with Spring Security on * Integration tests for insecured service endpoints (even with Spring Security on
...@@ -53,12 +52,11 @@ public class InsecureSampleActuatorApplicationTests { ...@@ -53,12 +52,11 @@ public class InsecureSampleActuatorApplicationTests {
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
ResponseEntity<Map> entity = new TestRestTemplate() ResponseEntity<Map> entity = new TestRestTemplate()
.getForEntity("http://localhost:" + this.port, Map.class); .getForEntity("http://localhost:" + this.port, Map.class);
assertEquals(HttpStatus.OK, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Map<String, Object> body = entity.getBody(); Map<String, Object> body = entity.getBody();
assertEquals("Hello Phil", body.get("message")); assertThat(body.get("message")).isEqualTo("Hello Phil");
assertFalse("Wrong headers: " + entity.getHeaders(), assertThat(entity.getHeaders()).doesNotContainKey("Set-Cookie");
entity.getHeaders().containsKey("Set-Cookie"));
} }
} }
...@@ -30,8 +30,7 @@ import org.springframework.http.ResponseEntity; ...@@ -30,8 +30,7 @@ import org.springframework.http.ResponseEntity;
import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import static org.junit.Assert.assertEquals; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertTrue;
/** /**
* Integration tests for separate management and main service ports. * Integration tests for separate management and main service ports.
...@@ -56,7 +55,7 @@ public class ManagementAddressActuatorApplicationTests { ...@@ -56,7 +55,7 @@ public class ManagementAddressActuatorApplicationTests {
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
ResponseEntity<Map> entity = new TestRestTemplate() ResponseEntity<Map> entity = new TestRestTemplate()
.getForEntity("http://localhost:" + this.port, Map.class); .getForEntity("http://localhost:" + this.port, Map.class);
assertEquals(HttpStatus.UNAUTHORIZED, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
} }
@Test @Test
...@@ -64,9 +63,8 @@ public class ManagementAddressActuatorApplicationTests { ...@@ -64,9 +63,8 @@ public class ManagementAddressActuatorApplicationTests {
ResponseEntity<String> entity = new TestRestTemplate().getForEntity( ResponseEntity<String> entity = new TestRestTemplate().getForEntity(
"http://localhost:" + this.managementPort + "/admin/health", "http://localhost:" + this.managementPort + "/admin/health",
String.class); String.class);
assertEquals(HttpStatus.OK, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertTrue("Wrong body: " + entity.getBody(), assertThat(entity.getBody()).contains("\"status\":\"UP\"");
entity.getBody().contains("\"status\":\"UP\""));
} }
} }
...@@ -30,9 +30,7 @@ import org.springframework.http.ResponseEntity; ...@@ -30,9 +30,7 @@ import org.springframework.http.ResponseEntity;
import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import static org.junit.Assert.assertEquals; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
/** /**
* Integration tests for endpoints configuration. * Integration tests for endpoints configuration.
...@@ -52,9 +50,8 @@ public class ManagementPathSampleActuatorApplicationTests { ...@@ -52,9 +50,8 @@ public class ManagementPathSampleActuatorApplicationTests {
public void testHealth() throws Exception { public void testHealth() throws Exception {
ResponseEntity<String> entity = new TestRestTemplate().getForEntity( ResponseEntity<String> entity = new TestRestTemplate().getForEntity(
"http://localhost:" + this.port + "/admin/health", String.class); "http://localhost:" + this.port + "/admin/health", String.class);
assertEquals(HttpStatus.OK, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertTrue("Wrong body: " + entity.getBody(), assertThat(entity.getBody()).contains("\"status\":\"UP\"");
entity.getBody().contains("\"status\":\"UP\""));
} }
@Test @Test
...@@ -62,12 +59,11 @@ public class ManagementPathSampleActuatorApplicationTests { ...@@ -62,12 +59,11 @@ public class ManagementPathSampleActuatorApplicationTests {
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
ResponseEntity<Map> entity = new TestRestTemplate() ResponseEntity<Map> entity = new TestRestTemplate()
.getForEntity("http://localhost:" + this.port, Map.class); .getForEntity("http://localhost:" + this.port, Map.class);
assertEquals(HttpStatus.UNAUTHORIZED, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Map<String, Object> body = entity.getBody(); Map<String, Object> body = entity.getBody();
assertEquals("Wrong body: " + body, "Unauthorized", body.get("error")); assertThat(body.get("error")).isEqualTo("Unauthorized");
assertFalse("Wrong headers: " + entity.getHeaders(), assertThat(entity.getHeaders()).doesNotContainKey("Set-Cookie");
entity.getHeaders().containsKey("Set-Cookie"));
} }
} }
...@@ -32,8 +32,7 @@ import org.springframework.http.ResponseEntity; ...@@ -32,8 +32,7 @@ import org.springframework.http.ResponseEntity;
import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import static org.junit.Assert.assertEquals; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertTrue;
/** /**
* Integration tests for separate management and main service ports. * Integration tests for separate management and main service ports.
...@@ -61,10 +60,10 @@ public class ManagementPortAndPathSampleActuatorApplicationTests { ...@@ -61,10 +60,10 @@ public class ManagementPortAndPathSampleActuatorApplicationTests {
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
ResponseEntity<Map> entity = new TestRestTemplate("user", getPassword()) ResponseEntity<Map> entity = new TestRestTemplate("user", getPassword())
.getForEntity("http://localhost:" + this.port, Map.class); .getForEntity("http://localhost:" + this.port, Map.class);
assertEquals(HttpStatus.OK, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Map<String, Object> body = entity.getBody(); Map<String, Object> body = entity.getBody();
assertEquals("Hello Phil", body.get("message")); assertThat(body.get("message")).isEqualTo("Hello Phil");
} }
@Test @Test
...@@ -73,7 +72,7 @@ public class ManagementPortAndPathSampleActuatorApplicationTests { ...@@ -73,7 +72,7 @@ public class ManagementPortAndPathSampleActuatorApplicationTests {
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
ResponseEntity<Map> entity = new TestRestTemplate().getForEntity( ResponseEntity<Map> entity = new TestRestTemplate().getForEntity(
"http://localhost:" + this.managementPort + "/admin/metrics", Map.class); "http://localhost:" + this.managementPort + "/admin/metrics", Map.class);
assertEquals(HttpStatus.UNAUTHORIZED, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
} }
@Test @Test
...@@ -81,9 +80,8 @@ public class ManagementPortAndPathSampleActuatorApplicationTests { ...@@ -81,9 +80,8 @@ public class ManagementPortAndPathSampleActuatorApplicationTests {
ResponseEntity<String> entity = new TestRestTemplate().getForEntity( ResponseEntity<String> entity = new TestRestTemplate().getForEntity(
"http://localhost:" + this.managementPort + "/admin/health", "http://localhost:" + this.managementPort + "/admin/health",
String.class); String.class);
assertEquals(HttpStatus.OK, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertTrue("Wrong body: " + entity.getBody(), assertThat(entity.getBody()).contains("\"status\":\"UP\"");
entity.getBody().contains("\"status\":\"UP\""));
} }
@Test @Test
...@@ -92,9 +90,8 @@ public class ManagementPortAndPathSampleActuatorApplicationTests { ...@@ -92,9 +90,8 @@ public class ManagementPortAndPathSampleActuatorApplicationTests {
.getForEntity( .getForEntity(
"http://localhost:" + this.managementPort + "/admin/missing", "http://localhost:" + this.managementPort + "/admin/missing",
String.class); String.class);
assertEquals(HttpStatus.NOT_FOUND, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
assertTrue("Wrong body: " + entity.getBody(), assertThat(entity.getBody()).contains("\"status\":404");
entity.getBody().contains("\"status\":404"));
} }
@Test @Test
...@@ -102,10 +99,10 @@ public class ManagementPortAndPathSampleActuatorApplicationTests { ...@@ -102,10 +99,10 @@ public class ManagementPortAndPathSampleActuatorApplicationTests {
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
ResponseEntity<Map> entity = new TestRestTemplate() ResponseEntity<Map> entity = new TestRestTemplate()
.getForEntity("http://localhost:" + this.port + "/error", Map.class); .getForEntity("http://localhost:" + this.port + "/error", Map.class);
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Map<String, Object> body = entity.getBody(); Map<String, Object> body = entity.getBody();
assertEquals(999, body.get("status")); assertThat(body.get("status")).isEqualTo(999);
} }
@Test @Test
...@@ -113,11 +110,10 @@ public class ManagementPortAndPathSampleActuatorApplicationTests { ...@@ -113,11 +110,10 @@ public class ManagementPortAndPathSampleActuatorApplicationTests {
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
ResponseEntity<Map> entity = new TestRestTemplate().getForEntity( ResponseEntity<Map> entity = new TestRestTemplate().getForEntity(
"http://localhost:" + this.managementPort + "/error", Map.class); "http://localhost:" + this.managementPort + "/error", Map.class);
// TODO: should be 500? assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertEquals(HttpStatus.OK, entity.getStatusCode());
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Map<String, Object> body = entity.getBody(); Map<String, Object> body = entity.getBody();
assertEquals(999, body.get("status")); assertThat(body.get("status")).isEqualTo(999);
} }
private String getPassword() { private String getPassword() {
......
...@@ -32,8 +32,7 @@ import org.springframework.http.ResponseEntity; ...@@ -32,8 +32,7 @@ import org.springframework.http.ResponseEntity;
import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import static org.junit.Assert.assertEquals; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertTrue;
/** /**
* Integration tests for separate management and main service ports. * Integration tests for separate management and main service ports.
...@@ -60,10 +59,10 @@ public class ManagementPortSampleActuatorApplicationTests { ...@@ -60,10 +59,10 @@ public class ManagementPortSampleActuatorApplicationTests {
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
ResponseEntity<Map> entity = new TestRestTemplate("user", getPassword()) ResponseEntity<Map> entity = new TestRestTemplate("user", getPassword())
.getForEntity("http://localhost:" + this.port, Map.class); .getForEntity("http://localhost:" + this.port, Map.class);
assertEquals(HttpStatus.OK, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Map<String, Object> body = entity.getBody(); Map<String, Object> body = entity.getBody();
assertEquals("Hello Phil", body.get("message")); assertThat(body.get("message")).isEqualTo("Hello Phil");
} }
@Test @Test
...@@ -72,16 +71,15 @@ public class ManagementPortSampleActuatorApplicationTests { ...@@ -72,16 +71,15 @@ public class ManagementPortSampleActuatorApplicationTests {
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
ResponseEntity<Map> entity = new TestRestTemplate().getForEntity( ResponseEntity<Map> entity = new TestRestTemplate().getForEntity(
"http://localhost:" + this.managementPort + "/metrics", Map.class); "http://localhost:" + this.managementPort + "/metrics", Map.class);
assertEquals(HttpStatus.UNAUTHORIZED, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
} }
@Test @Test
public void testHealth() throws Exception { public void testHealth() throws Exception {
ResponseEntity<String> entity = new TestRestTemplate().getForEntity( ResponseEntity<String> entity = new TestRestTemplate().getForEntity(
"http://localhost:" + this.managementPort + "/health", String.class); "http://localhost:" + this.managementPort + "/health", String.class);
assertEquals(HttpStatus.OK, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertTrue("Wrong body: " + entity.getBody(), assertThat(entity.getBody()).contains("\"status\":\"UP\"");
entity.getBody().contains("\"status\":\"UP\""));
} }
@Test @Test
...@@ -89,10 +87,10 @@ public class ManagementPortSampleActuatorApplicationTests { ...@@ -89,10 +87,10 @@ public class ManagementPortSampleActuatorApplicationTests {
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
ResponseEntity<Map> entity = new TestRestTemplate().getForEntity( ResponseEntity<Map> entity = new TestRestTemplate().getForEntity(
"http://localhost:" + this.managementPort + "/error", Map.class); "http://localhost:" + this.managementPort + "/error", Map.class);
assertEquals(HttpStatus.OK, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Map<String, Object> body = entity.getBody(); Map<String, Object> body = entity.getBody();
assertEquals(999, body.get("status")); assertThat(body.get("status")).isEqualTo(999);
} }
private String getPassword() { private String getPassword() {
......
...@@ -32,7 +32,7 @@ import org.springframework.http.ResponseEntity; ...@@ -32,7 +32,7 @@ import org.springframework.http.ResponseEntity;
import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import static org.junit.Assert.assertEquals; import static org.assertj.core.api.Assertions.assertThat;
/** /**
* Integration tests for switching off management endpoints. * Integration tests for switching off management endpoints.
...@@ -56,10 +56,10 @@ public class NoManagementSampleActuatorApplicationTests { ...@@ -56,10 +56,10 @@ public class NoManagementSampleActuatorApplicationTests {
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
ResponseEntity<Map> entity = new TestRestTemplate("user", getPassword()) ResponseEntity<Map> entity = new TestRestTemplate("user", getPassword())
.getForEntity("http://localhost:" + this.port, Map.class); .getForEntity("http://localhost:" + this.port, Map.class);
assertEquals(HttpStatus.OK, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Map<String, Object> body = entity.getBody(); Map<String, Object> body = entity.getBody();
assertEquals("Hello Phil", body.get("message")); assertThat(body.get("message")).isEqualTo("Hello Phil");
} }
@Test @Test
...@@ -68,7 +68,7 @@ public class NoManagementSampleActuatorApplicationTests { ...@@ -68,7 +68,7 @@ public class NoManagementSampleActuatorApplicationTests {
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
ResponseEntity<Map> entity = new TestRestTemplate("user", getPassword()) ResponseEntity<Map> entity = new TestRestTemplate("user", getPassword())
.getForEntity("http://localhost:" + this.port + "/metrics", Map.class); .getForEntity("http://localhost:" + this.port + "/metrics", Map.class);
assertEquals(HttpStatus.NOT_FOUND, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
} }
private String getPassword() { private String getPassword() {
......
...@@ -28,8 +28,7 @@ import org.springframework.http.ResponseEntity; ...@@ -28,8 +28,7 @@ import org.springframework.http.ResponseEntity;
import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import static org.junit.Assert.assertEquals; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertFalse;
/** /**
* Tests for /health with {@code endpoints.health.sensitive=false}. * Tests for /health with {@code endpoints.health.sensitive=false}.
...@@ -49,9 +48,8 @@ public class NonSensitiveHealthTests { ...@@ -49,9 +48,8 @@ public class NonSensitiveHealthTests {
public void testSecureHealth() throws Exception { public void testSecureHealth() throws Exception {
ResponseEntity<String> entity = new TestRestTemplate() ResponseEntity<String> entity = new TestRestTemplate()
.getForEntity("http://localhost:" + this.port + "/health", String.class); .getForEntity("http://localhost:" + this.port + "/health", String.class);
assertEquals(HttpStatus.OK, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertFalse("Wrong body: " + entity.getBody(), assertThat(entity.getBody()).doesNotContain("\"hello\":1");
entity.getBody().contains("\"hello\":1"));
} }
} }
...@@ -38,10 +38,7 @@ import org.springframework.http.ResponseEntity; ...@@ -38,10 +38,7 @@ import org.springframework.http.ResponseEntity;
import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import static org.junit.Assert.assertEquals; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
/** /**
* Basic integration tests for service demo application. * Basic integration tests for service demo application.
...@@ -65,12 +62,11 @@ public class SampleActuatorApplicationTests { ...@@ -65,12 +62,11 @@ public class SampleActuatorApplicationTests {
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
ResponseEntity<Map> entity = new TestRestTemplate() ResponseEntity<Map> entity = new TestRestTemplate()
.getForEntity("http://localhost:" + this.port, Map.class); .getForEntity("http://localhost:" + this.port, Map.class);
assertEquals(HttpStatus.UNAUTHORIZED, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Map<String, Object> body = entity.getBody(); Map<String, Object> body = entity.getBody();
assertEquals("Wrong body: " + body, "Unauthorized", body.get("error")); assertThat(body.get("error")).isEqualTo("Unauthorized");
assertFalse("Wrong headers: " + entity.getHeaders(), assertThat(entity.getHeaders()).doesNotContainKey("Set-Cookie");
entity.getHeaders().containsKey("Set-Cookie"));
} }
@Test @Test
...@@ -78,16 +74,16 @@ public class SampleActuatorApplicationTests { ...@@ -78,16 +74,16 @@ public class SampleActuatorApplicationTests {
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
ResponseEntity<Map> entity = new TestRestTemplate() ResponseEntity<Map> entity = new TestRestTemplate()
.getForEntity("http://localhost:" + this.port + "/metrics", Map.class); .getForEntity("http://localhost:" + this.port + "/metrics", Map.class);
assertEquals(HttpStatus.UNAUTHORIZED, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
entity = new TestRestTemplate() entity = new TestRestTemplate()
.getForEntity("http://localhost:" + this.port + "/metrics/", Map.class); .getForEntity("http://localhost:" + this.port + "/metrics/", Map.class);
assertEquals(HttpStatus.UNAUTHORIZED, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
entity = new TestRestTemplate().getForEntity( entity = new TestRestTemplate().getForEntity(
"http://localhost:" + this.port + "/metrics/foo", Map.class); "http://localhost:" + this.port + "/metrics/foo", Map.class);
assertEquals(HttpStatus.UNAUTHORIZED, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
entity = new TestRestTemplate().getForEntity( entity = new TestRestTemplate().getForEntity(
"http://localhost:" + this.port + "/metrics.json", Map.class); "http://localhost:" + this.port + "/metrics.json", Map.class);
assertEquals(HttpStatus.UNAUTHORIZED, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
} }
@Test @Test
...@@ -95,10 +91,10 @@ public class SampleActuatorApplicationTests { ...@@ -95,10 +91,10 @@ public class SampleActuatorApplicationTests {
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
ResponseEntity<Map> entity = new TestRestTemplate("user", getPassword()) ResponseEntity<Map> entity = new TestRestTemplate("user", getPassword())
.getForEntity("http://localhost:" + this.port, Map.class); .getForEntity("http://localhost:" + this.port, Map.class);
assertEquals(HttpStatus.OK, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Map<String, Object> body = entity.getBody(); Map<String, Object> body = entity.getBody();
assertEquals("Hello Phil", body.get("message")); assertThat(body.get("message")).isEqualTo("Hello Phil");
} }
@Test @Test
...@@ -107,10 +103,10 @@ public class SampleActuatorApplicationTests { ...@@ -107,10 +103,10 @@ public class SampleActuatorApplicationTests {
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
ResponseEntity<Map> entity = new TestRestTemplate("user", getPassword()) ResponseEntity<Map> entity = new TestRestTemplate("user", getPassword())
.getForEntity("http://localhost:" + this.port + "/metrics", Map.class); .getForEntity("http://localhost:" + this.port + "/metrics", Map.class);
assertEquals(HttpStatus.OK, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Map<String, Object> body = entity.getBody(); Map<String, Object> body = entity.getBody();
assertTrue("Wrong body: " + body, body.containsKey("counter.status.200.root")); assertThat(body).containsKey("counter.status.200.root");
} }
@Test @Test
...@@ -118,49 +114,45 @@ public class SampleActuatorApplicationTests { ...@@ -118,49 +114,45 @@ public class SampleActuatorApplicationTests {
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
ResponseEntity<Map> entity = new TestRestTemplate("user", getPassword()) ResponseEntity<Map> entity = new TestRestTemplate("user", getPassword())
.getForEntity("http://localhost:" + this.port + "/env", Map.class); .getForEntity("http://localhost:" + this.port + "/env", Map.class);
assertEquals(HttpStatus.OK, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Map<String, Object> body = entity.getBody(); Map<String, Object> body = entity.getBody();
assertTrue("Wrong body: " + body, body.containsKey("systemProperties")); assertThat(body).containsKey("systemProperties");
} }
@Test @Test
public void testHealth() throws Exception { public void testHealth() throws Exception {
ResponseEntity<String> entity = new TestRestTemplate() ResponseEntity<String> entity = new TestRestTemplate()
.getForEntity("http://localhost:" + this.port + "/health", String.class); .getForEntity("http://localhost:" + this.port + "/health", String.class);
assertEquals(HttpStatus.OK, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertTrue("Wrong body: " + entity.getBody(), assertThat(entity.getBody()).contains("\"status\":\"UP\"");
entity.getBody().contains("\"status\":\"UP\"")); assertThat(entity.getBody()).doesNotContain("\"hello\":\"1\"");
assertFalse("Wrong body: " + entity.getBody(),
entity.getBody().contains("\"hello\":\"1\""));
} }
@Test @Test
public void testSecureHealth() throws Exception { public void testSecureHealth() throws Exception {
ResponseEntity<String> entity = new TestRestTemplate("user", getPassword()) ResponseEntity<String> entity = new TestRestTemplate("user", getPassword())
.getForEntity("http://localhost:" + this.port + "/health", String.class); .getForEntity("http://localhost:" + this.port + "/health", String.class);
assertEquals(HttpStatus.OK, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertTrue("Wrong body: " + entity.getBody(), assertThat(entity.getBody()).contains("\"hello\":1");
entity.getBody().contains("\"hello\":1"));
} }
@Test @Test
public void testInfo() throws Exception { public void testInfo() throws Exception {
ResponseEntity<String> entity = new TestRestTemplate() ResponseEntity<String> entity = new TestRestTemplate()
.getForEntity("http://localhost:" + this.port + "/info", String.class); .getForEntity("http://localhost:" + this.port + "/info", String.class);
assertEquals(HttpStatus.OK, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertTrue("Wrong body: " + entity.getBody(), entity.getBody() assertThat(entity.getBody())
.contains("\"artifact\":\"spring-boot-sample-actuator\"")); .contains("\"artifact\":\"spring-boot-sample-actuator\"");
} }
@Test @Test
public void testErrorPage() throws Exception { public void testErrorPage() throws Exception {
ResponseEntity<String> entity = new TestRestTemplate("user", getPassword()) ResponseEntity<String> entity = new TestRestTemplate("user", getPassword())
.getForEntity("http://localhost:" + this.port + "/foo", String.class); .getForEntity("http://localhost:" + this.port + "/foo", String.class);
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
String body = entity.getBody(); String body = entity.getBody();
assertNotNull(body); assertThat(body).contains("\"error\":");
assertTrue("Wrong body: " + body, body.contains("\"error\":"));
} }
@Test @Test
...@@ -171,11 +163,10 @@ public class SampleActuatorApplicationTests { ...@@ -171,11 +163,10 @@ public class SampleActuatorApplicationTests {
ResponseEntity<String> entity = new TestRestTemplate("user", getPassword()) ResponseEntity<String> entity = new TestRestTemplate("user", getPassword())
.exchange("http://localhost:" + this.port + "/foo", HttpMethod.GET, .exchange("http://localhost:" + this.port + "/foo", HttpMethod.GET,
request, String.class); request, String.class);
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
String body = entity.getBody(); String body = entity.getBody();
assertNotNull("Body was null", body); assertThat(body).as("Body was null").isNotNull();
assertTrue("Wrong body: " + body, assertThat(body).contains("This application has no explicit mapping for /error");
body.contains("This application has no explicit mapping for /error"));
} }
@Test @Test
...@@ -185,14 +176,14 @@ public class SampleActuatorApplicationTests { ...@@ -185,14 +176,14 @@ public class SampleActuatorApplicationTests {
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
ResponseEntity<List> entity = new TestRestTemplate("user", getPassword()) ResponseEntity<List> entity = new TestRestTemplate("user", getPassword())
.getForEntity("http://localhost:" + this.port + "/trace", List.class); .getForEntity("http://localhost:" + this.port + "/trace", List.class);
assertEquals(HttpStatus.OK, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
List<Map<String, Object>> list = entity.getBody(); List<Map<String, Object>> list = entity.getBody();
Map<String, Object> trace = list.get(list.size() - 1); Map<String, Object> trace = list.get(list.size() - 1);
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Map<String, Object> map = (Map<String, Object>) ((Map<String, Object>) ((Map<String, Object>) trace Map<String, Object> map = (Map<String, Object>) ((Map<String, Object>) ((Map<String, Object>) trace
.get("info")).get("headers")).get("response"); .get("info")).get("headers")).get("response");
assertEquals("200", map.get("status")); assertThat(map.get("status")).isEqualTo("200");
} }
@Test @Test
...@@ -200,24 +191,23 @@ public class SampleActuatorApplicationTests { ...@@ -200,24 +191,23 @@ public class SampleActuatorApplicationTests {
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
ResponseEntity<Map> entity = new TestRestTemplate() ResponseEntity<Map> entity = new TestRestTemplate()
.getForEntity("http://localhost:" + this.port + "/error", Map.class); .getForEntity("http://localhost:" + this.port + "/error", Map.class);
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Map<String, Object> body = entity.getBody(); Map<String, Object> body = entity.getBody();
assertEquals("None", body.get("error")); assertThat(body.get("error")).isEqualTo("None");
assertEquals(999, body.get("status")); assertThat(body.get("status")).isEqualTo(999);
} }
@Test @Test
@SuppressWarnings("unchecked")
public void testBeans() throws Exception { public void testBeans() throws Exception {
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
ResponseEntity<List> entity = new TestRestTemplate("user", getPassword()) ResponseEntity<List> entity = new TestRestTemplate("user", getPassword())
.getForEntity("http://localhost:" + this.port + "/beans", List.class); .getForEntity("http://localhost:" + this.port + "/beans", List.class);
assertEquals(HttpStatus.OK, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertEquals(1, entity.getBody().size()); assertThat(entity.getBody()).hasSize(1);
@SuppressWarnings("unchecked")
Map<String, Object> body = (Map<String, Object>) entity.getBody().get(0); Map<String, Object> body = (Map<String, Object>) entity.getBody().get(0);
assertTrue("Wrong body: " + body, assertThat(((String) body.get("context"))).startsWith("application");
((String) body.get("context")).startsWith("application"));
} }
@Test @Test
...@@ -226,11 +216,10 @@ public class SampleActuatorApplicationTests { ...@@ -226,11 +216,10 @@ public class SampleActuatorApplicationTests {
ResponseEntity<Map> entity = new TestRestTemplate("user", getPassword()) ResponseEntity<Map> entity = new TestRestTemplate("user", getPassword())
.getForEntity("http://localhost:" + this.port + "/configprops", .getForEntity("http://localhost:" + this.port + "/configprops",
Map.class); Map.class);
assertEquals(HttpStatus.OK, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Map<String, Object> body = entity.getBody(); Map<String, Object> body = entity.getBody();
assertTrue("Wrong body: " + body, assertThat(body).containsKey("spring.datasource.CONFIGURATION_PROPERTIES");
body.containsKey("spring.datasource.CONFIGURATION_PROPERTIES"));
} }
private String getPassword() { private String getPassword() {
......
...@@ -30,8 +30,7 @@ import org.springframework.http.ResponseEntity; ...@@ -30,8 +30,7 @@ import org.springframework.http.ResponseEntity;
import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import static org.junit.Assert.assertEquals; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertFalse;
/** /**
* Integration tests for insecured service endpoints (even with Spring Security on * Integration tests for insecured service endpoints (even with Spring Security on
...@@ -54,12 +53,11 @@ public class ServletPathInsecureSampleActuatorApplicationTests { ...@@ -54,12 +53,11 @@ public class ServletPathInsecureSampleActuatorApplicationTests {
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
ResponseEntity<Map> entity = new TestRestTemplate() ResponseEntity<Map> entity = new TestRestTemplate()
.getForEntity("http://localhost:" + this.port + "/spring/", Map.class); .getForEntity("http://localhost:" + this.port + "/spring/", Map.class);
assertEquals(HttpStatus.OK, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Map<String, Object> body = entity.getBody(); Map<String, Object> body = entity.getBody();
assertEquals("Hello Phil", body.get("message")); assertThat(body.get("message")).isEqualTo("Hello Phil");
assertFalse("Wrong headers: " + entity.getHeaders(), assertThat(entity.getHeaders()).doesNotContainKey("Set-Cookie");
entity.getHeaders().containsKey("Set-Cookie"));
} }
@Test @Test
...@@ -67,7 +65,7 @@ public class ServletPathInsecureSampleActuatorApplicationTests { ...@@ -67,7 +65,7 @@ public class ServletPathInsecureSampleActuatorApplicationTests {
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
ResponseEntity<Map> entity = new TestRestTemplate().getForEntity( ResponseEntity<Map> entity = new TestRestTemplate().getForEntity(
"http://localhost:" + this.port + "/spring/metrics", Map.class); "http://localhost:" + this.port + "/spring/metrics", Map.class);
assertEquals(HttpStatus.UNAUTHORIZED, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
} }
} }
...@@ -30,9 +30,7 @@ import org.springframework.http.ResponseEntity; ...@@ -30,9 +30,7 @@ import org.springframework.http.ResponseEntity;
import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import static org.junit.Assert.assertEquals; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
/** /**
* Integration tests for endpoints configuration. * Integration tests for endpoints configuration.
...@@ -54,20 +52,19 @@ public class ServletPathSampleActuatorApplicationTests { ...@@ -54,20 +52,19 @@ public class ServletPathSampleActuatorApplicationTests {
ResponseEntity<Map> entity = new TestRestTemplate("user", "password") ResponseEntity<Map> entity = new TestRestTemplate("user", "password")
.getForEntity("http://localhost:" + this.port + "/spring/error", .getForEntity("http://localhost:" + this.port + "/spring/error",
Map.class); Map.class);
assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Map<String, Object> body = entity.getBody(); Map<String, Object> body = entity.getBody();
assertEquals("None", body.get("error")); assertThat(body.get("error")).isEqualTo("None");
assertEquals(999, body.get("status")); assertThat(body.get("status")).isEqualTo(999);
} }
@Test @Test
public void testHealth() throws Exception { public void testHealth() throws Exception {
ResponseEntity<String> entity = new TestRestTemplate().getForEntity( ResponseEntity<String> entity = new TestRestTemplate().getForEntity(
"http://localhost:" + this.port + "/spring/health", String.class); "http://localhost:" + this.port + "/spring/health", String.class);
assertEquals(HttpStatus.OK, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertTrue("Wrong body: " + entity.getBody(), assertThat(entity.getBody()).contains("\"status\":\"UP\"");
entity.getBody().contains("\"status\":\"UP\""));
} }
@Test @Test
...@@ -75,12 +72,11 @@ public class ServletPathSampleActuatorApplicationTests { ...@@ -75,12 +72,11 @@ public class ServletPathSampleActuatorApplicationTests {
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
ResponseEntity<Map> entity = new TestRestTemplate() ResponseEntity<Map> entity = new TestRestTemplate()
.getForEntity("http://localhost:" + this.port + "/spring/", Map.class); .getForEntity("http://localhost:" + this.port + "/spring/", Map.class);
assertEquals(HttpStatus.UNAUTHORIZED, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Map<String, Object> body = entity.getBody(); Map<String, Object> body = entity.getBody();
assertEquals("Wrong body: " + body, "Unauthorized", body.get("error")); assertThat(body.get("error")).isEqualTo("Unauthorized");
assertFalse("Wrong headers: " + entity.getHeaders(), assertThat(entity.getHeaders()).doesNotContainKey("Set-Cookie");
entity.getHeaders().containsKey("Set-Cookie"));
} }
} }
...@@ -32,8 +32,7 @@ import org.springframework.http.ResponseEntity; ...@@ -32,8 +32,7 @@ import org.springframework.http.ResponseEntity;
import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import static org.junit.Assert.assertEquals; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertTrue;
/** /**
* Integration tests for separate management and main service ports. * Integration tests for separate management and main service ports.
...@@ -57,10 +56,10 @@ public class ShutdownSampleActuatorApplicationTests { ...@@ -57,10 +56,10 @@ public class ShutdownSampleActuatorApplicationTests {
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
ResponseEntity<Map> entity = new TestRestTemplate("user", getPassword()) ResponseEntity<Map> entity = new TestRestTemplate("user", getPassword())
.getForEntity("http://localhost:" + this.port, Map.class); .getForEntity("http://localhost:" + this.port, Map.class);
assertEquals(HttpStatus.OK, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Map<String, Object> body = entity.getBody(); Map<String, Object> body = entity.getBody();
assertEquals("Hello Phil", body.get("message")); assertThat(body.get("message")).isEqualTo("Hello Phil");
} }
@Test @Test
...@@ -69,11 +68,10 @@ public class ShutdownSampleActuatorApplicationTests { ...@@ -69,11 +68,10 @@ public class ShutdownSampleActuatorApplicationTests {
ResponseEntity<Map> entity = new TestRestTemplate("user", getPassword()) ResponseEntity<Map> entity = new TestRestTemplate("user", getPassword())
.postForEntity("http://localhost:" + this.port + "/shutdown", null, .postForEntity("http://localhost:" + this.port + "/shutdown", null,
Map.class); Map.class);
assertEquals(HttpStatus.OK, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Map<String, Object> body = entity.getBody(); Map<String, Object> body = entity.getBody();
assertTrue("Wrong body: " + body, assertThat(((String) body.get("message"))).contains("Shutting down");
((String) body.get("message")).contains("Shutting down"));
} }
private String getPassword() { private String getPassword() {
......
...@@ -16,9 +16,7 @@ ...@@ -16,9 +16,7 @@
package sample.ant; package sample.ant;
import static org.hamcrest.Matchers.containsString; import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;
import java.io.File; import java.io.File;
import java.io.FileFilter; import java.io.FileFilter;
...@@ -48,12 +46,12 @@ public class SampleAntApplicationIT { ...@@ -48,12 +46,12 @@ public class SampleAntApplicationIT {
} }
}); });
assertThat("Number of jars", jarFiles.length, equalTo(1)); assertThat(jarFiles).hasSize(1);
Process process = new JavaExecutable().processBuilder("-jar", jarFiles[0].getName()).directory(target).start(); Process process = new JavaExecutable().processBuilder("-jar", jarFiles[0].getName()).directory(target).start();
process.waitFor(5, TimeUnit.MINUTES); process.waitFor(5, TimeUnit.MINUTES);
assertThat(process.exitValue(), equalTo(0)); assertThat(process.exitValue()).isEqualTo(0);
String output = FileCopyUtils.copyToString(new InputStreamReader(process.getInputStream())); String output = FileCopyUtils.copyToString(new InputStreamReader(process.getInputStream()));
assertThat(output, containsString("Spring Boot Ant Example")); assertThat(output).contains("Spring Boot Ant Example");
} }
} }
...@@ -23,7 +23,7 @@ import org.junit.Test; ...@@ -23,7 +23,7 @@ import org.junit.Test;
import org.springframework.boot.test.OutputCapture; import org.springframework.boot.test.OutputCapture;
import static org.junit.Assert.assertTrue; import static org.assertj.core.api.Assertions.assertThat;
/** /**
* Tests for {@link SampleAopApplication}. * Tests for {@link SampleAopApplication}.
...@@ -57,14 +57,14 @@ public class SampleAopApplicationTests { ...@@ -57,14 +57,14 @@ public class SampleAopApplicationTests {
public void testDefaultSettings() throws Exception { public void testDefaultSettings() throws Exception {
SampleAopApplication.main(new String[0]); SampleAopApplication.main(new String[0]);
String output = this.outputCapture.toString(); String output = this.outputCapture.toString();
assertTrue("Wrong output: " + output, output.contains("Hello Phil")); assertThat(output).contains("Hello Phil");
} }
@Test @Test
public void testCommandLineOverrides() throws Exception { public void testCommandLineOverrides() throws Exception {
SampleAopApplication.main(new String[] { "--name=Gordon" }); SampleAopApplication.main(new String[] { "--name=Gordon" });
String output = this.outputCapture.toString(); String output = this.outputCapture.toString();
assertTrue("Wrong output: " + output, output.contains("Hello Gordon")); assertThat(output).contains("Hello Gordon");
} }
} }
...@@ -42,9 +42,7 @@ import org.springframework.web.socket.client.WebSocketConnectionManager; ...@@ -42,9 +42,7 @@ import org.springframework.web.socket.client.WebSocketConnectionManager;
import org.springframework.web.socket.client.standard.StandardWebSocketClient; import org.springframework.web.socket.client.standard.StandardWebSocketClient;
import org.springframework.web.socket.handler.TextWebSocketHandler; import org.springframework.web.socket.handler.TextWebSocketHandler;
import static org.hamcrest.Matchers.containsString; import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(SampleAtmosphereApplication.class) @SpringApplicationConfiguration(SampleAtmosphereApplication.class)
...@@ -68,9 +66,9 @@ public class SampleAtmosphereApplicationTests { ...@@ -68,9 +66,9 @@ public class SampleAtmosphereApplicationTests {
AtomicReference<String> messagePayloadReference = context AtomicReference<String> messagePayloadReference = context
.getBean(ClientConfiguration.class).messagePayload; .getBean(ClientConfiguration.class).messagePayload;
context.close(); context.close();
assertThat(count, equalTo(0L)); assertThat(count).isEqualTo(0L);
assertThat(messagePayloadReference.get(), assertThat(messagePayloadReference.get())
containsString("{\"message\":\"test\",\"author\":\"test\",\"time\":")); .contains("{\"message\":\"test\",\"author\":\"test\",\"time\":");
} }
@Configuration @Configuration
......
...@@ -22,8 +22,7 @@ import org.junit.Test; ...@@ -22,8 +22,7 @@ import org.junit.Test;
import org.springframework.boot.SpringApplication; import org.springframework.boot.SpringApplication;
import org.springframework.boot.test.OutputCapture; import org.springframework.boot.test.OutputCapture;
import static org.junit.Assert.assertEquals; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertTrue;
public class SampleBatchApplicationTests { public class SampleBatchApplicationTests {
...@@ -32,11 +31,10 @@ public class SampleBatchApplicationTests { ...@@ -32,11 +31,10 @@ public class SampleBatchApplicationTests {
@Test @Test
public void testDefaultSettings() throws Exception { public void testDefaultSettings() throws Exception {
assertEquals(0, SpringApplication assertThat(SpringApplication
.exit(SpringApplication.run(SampleBatchApplication.class))); .exit(SpringApplication.run(SampleBatchApplication.class))).isEqualTo(0);
String output = this.outputCapture.toString(); String output = this.outputCapture.toString();
assertTrue("Wrong output: " + output, assertThat(output).contains("completed with the following parameters");
output.contains("completed with the following parameters"));
} }
} }
...@@ -25,10 +25,7 @@ import org.springframework.cache.Cache; ...@@ -25,10 +25,7 @@ import org.springframework.cache.Cache;
import org.springframework.cache.CacheManager; import org.springframework.cache.CacheManager;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import static org.hamcrest.CoreMatchers.nullValue; import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.core.IsNull.notNullValue;
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(SampleCacheApplication.class) @SpringApplicationConfiguration(SampleCacheApplication.class)
...@@ -43,11 +40,11 @@ public class SampleCacheApplicationTests { ...@@ -43,11 +40,11 @@ public class SampleCacheApplicationTests {
@Test @Test
public void validateCache() { public void validateCache() {
Cache countries = this.cacheManager.getCache("countries"); Cache countries = this.cacheManager.getCache("countries");
assertThat(countries, is(notNullValue())); assertThat(countries).isNotNull();
countries.clear(); // Simple test assuming the cache is empty countries.clear(); // Simple test assuming the cache is empty
assertThat(countries.get("BE"), is(nullValue())); assertThat(countries.get("BE")).isNull();
Country be = this.countryRepository.findByCode("BE"); Country be = this.countryRepository.findByCode("BE");
assertThat((Country) countries.get("BE").get(), is(be)); assertThat((Country) countries.get("BE").get()).isEqualTo(be);
} }
} }
...@@ -30,7 +30,7 @@ import org.springframework.test.context.TestExecutionListeners; ...@@ -30,7 +30,7 @@ import org.springframework.test.context.TestExecutionListeners;
import org.springframework.test.context.TestExecutionListeners.MergeMode; import org.springframework.test.context.TestExecutionListeners.MergeMode;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import static org.junit.Assert.assertTrue; import static org.assertj.core.api.Assertions.assertThat;
/** /**
* Tests for {@link SampleCassandraApplication}. * Tests for {@link SampleCassandraApplication}.
...@@ -51,8 +51,7 @@ public class SampleCassandraApplicationTests { ...@@ -51,8 +51,7 @@ public class SampleCassandraApplicationTests {
@Test @Test
public void testDefaultSettings() throws Exception { public void testDefaultSettings() throws Exception {
String output = SampleCassandraApplicationTests.outputCapture.toString(); String output = SampleCassandraApplicationTests.outputCapture.toString();
assertTrue("Wrong output: " + output, assertThat(output).contains("firstName='Alice', lastName='Smith'");
output.contains("firstName='Alice', lastName='Smith'"));
} }
} }
...@@ -25,7 +25,7 @@ import org.springframework.boot.builder.SpringApplicationBuilder; ...@@ -25,7 +25,7 @@ import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.test.OutputCapture; import org.springframework.boot.test.OutputCapture;
import org.springframework.core.NestedCheckedException; import org.springframework.core.NestedCheckedException;
import static org.junit.Assert.assertTrue; import static org.assertj.core.api.Assertions.assertThat;
/** /**
* Tests for {@link SampleElasticsearchApplication}. * Tests for {@link SampleElasticsearchApplication}.
...@@ -53,8 +53,7 @@ public class SampleElasticsearchApplicationTests { ...@@ -53,8 +53,7 @@ public class SampleElasticsearchApplicationTests {
} }
} }
String output = this.outputCapture.toString(); String output = this.outputCapture.toString();
assertTrue("Wrong output: " + output, assertThat(output).contains("firstName='Alice', lastName='Smith'");
output.contains("firstName='Alice', lastName='Smith'"));
} }
private boolean serverNotRunning(IllegalStateException ex) { private boolean serverNotRunning(IllegalStateException ex) {
......
...@@ -16,8 +16,6 @@ ...@@ -16,8 +16,6 @@
package sample.data.gemfire; package sample.data.gemfire;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicLong;
import org.junit.Before; import org.junit.Before;
...@@ -31,9 +29,7 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -31,9 +29,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import static org.junit.Assert.assertEquals; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
/** /**
* The SampleDataGemFireApplicationTests class is a test suite with test cases testing the * The SampleDataGemFireApplicationTests class is a test suite with test cases testing the
...@@ -50,70 +46,38 @@ public class SampleDataGemFireApplicationTests { ...@@ -50,70 +46,38 @@ public class SampleDataGemFireApplicationTests {
private final AtomicLong ID_GENERATOR = new AtomicLong(0l); private final AtomicLong ID_GENERATOR = new AtomicLong(0l);
protected List<Gemstone> asList(final Iterable<Gemstone> gemstones) {
List<Gemstone> gemstoneList = new ArrayList<Gemstone>();
if (gemstones != null) {
for (Gemstone gemstone : gemstones) {
gemstoneList.add(gemstone);
}
}
return gemstoneList;
}
protected Gemstone createGemstone(final String name) {
return createGemstone(this.ID_GENERATOR.incrementAndGet(), name);
}
protected Gemstone createGemstone(final Long id, final String name) {
return new Gemstone(id, name);
}
protected List<Gemstone> getGemstones(final String... names) {
List<Gemstone> gemstones = new ArrayList<Gemstone>(names.length);
for (String name : names) {
gemstones.add(createGemstone(null, name));
}
return gemstones;
}
@Before @Before
public void setup() { public void setup() {
assertNotNull("A reference to the GemstoneService was not properly configured!", assertThat(this.gemstoneService).isNotNull();
this.gemstoneService);
} }
@Test @Test
public void testGemstonesApp() { public void testGemstonesApp() {
assertEquals(0, this.gemstoneService.count()); assertThat(this.gemstoneService.count()).isEqualTo(0);
assertTrue(asList(this.gemstoneService.list()).isEmpty()); assertThat(this.gemstoneService.list()).isEmpty();
this.gemstoneService.save(createGemstone("Diamond")); this.gemstoneService.save(createGemstone("Diamond"));
this.gemstoneService.save(createGemstone("Ruby")); this.gemstoneService.save(createGemstone("Ruby"));
assertEquals(2, this.gemstoneService.count()); assertThat(this.gemstoneService.count()).isEqualTo(2);
assertTrue(asList(this.gemstoneService.list()) assertThat(this.gemstoneService.list()).contains(getGemstones("Diamond", "Ruby"));
.containsAll(getGemstones("Diamond", "Ruby")));
try { try {
this.gemstoneService.save(createGemstone("Coal")); this.gemstoneService.save(createGemstone("Coal"));
} }
catch (IllegalGemstoneException expected) { catch (IllegalGemstoneException ex) {
// Expected
} }
assertEquals(2, this.gemstoneService.count()); assertThat(this.gemstoneService.count()).isEqualTo(2);
assertTrue(asList(this.gemstoneService.list()) assertThat(this.gemstoneService.list()).contains(getGemstones("Diamond", "Ruby"));
.containsAll(getGemstones("Diamond", "Ruby")));
this.gemstoneService.save(createGemstone("Pearl")); this.gemstoneService.save(createGemstone("Pearl"));
this.gemstoneService.save(createGemstone("Sapphire")); this.gemstoneService.save(createGemstone("Sapphire"));
assertEquals(4, this.gemstoneService.count()); assertThat(this.gemstoneService.count()).isEqualTo(4);
assertTrue(asList(this.gemstoneService.list()) assertThat(this.gemstoneService.list())
.containsAll(getGemstones("Diamond", "Ruby", "Pearl", "Sapphire"))); .contains(getGemstones("Diamond", "Ruby", "Pearl", "Sapphire"));
try { try {
this.gemstoneService.save(createGemstone("Quartz")); this.gemstoneService.save(createGemstone("Quartz"));
...@@ -121,11 +85,28 @@ public class SampleDataGemFireApplicationTests { ...@@ -121,11 +85,28 @@ public class SampleDataGemFireApplicationTests {
catch (IllegalGemstoneException expected) { catch (IllegalGemstoneException expected) {
} }
assertEquals(4, this.gemstoneService.count()); assertThat(this.gemstoneService.count()).isEqualTo(4);
assertTrue(asList(this.gemstoneService.list()) assertThat(this.gemstoneService.list())
.containsAll(getGemstones("Diamond", "Ruby", "Pearl", "Sapphire"))); .contains(getGemstones("Diamond", "Ruby", "Pearl", "Sapphire"));
assertEquals(createGemstone("Diamond"), this.gemstoneService.get("Diamond")); assertThat(this.gemstoneService.get("Diamond"))
assertEquals(createGemstone("Pearl"), this.gemstoneService.get("Pearl")); .isEqualTo(createGemstone("Diamond"));
assertThat(this.gemstoneService.get("Pearl")).isEqualTo(createGemstone("Pearl"));
}
private Gemstone[] getGemstones(String... names) {
Gemstone[] gemstones = new Gemstone[names.length];
for (int i = 0; i < names.length; i++) {
gemstones[i] = createGemstone(null, names[i]);
}
return gemstones;
}
private Gemstone createGemstone(String name) {
return createGemstone(this.ID_GENERATOR.incrementAndGet(), name);
}
private Gemstone createGemstone(Long id, String name) {
return new Gemstone(id, name);
} }
} }
...@@ -34,7 +34,7 @@ import org.springframework.test.web.servlet.MockMvc; ...@@ -34,7 +34,7 @@ import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders; import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext; import org.springframework.web.context.WebApplicationContext;
import static org.junit.Assert.assertEquals; import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
...@@ -74,9 +74,9 @@ public class SampleDataJpaApplicationTests { ...@@ -74,9 +74,9 @@ public class SampleDataJpaApplicationTests {
@Test @Test
public void testJmx() throws Exception { public void testJmx() throws Exception {
assertEquals(1, ManagementFactory.getPlatformMBeanServer() assertThat(ManagementFactory.getPlatformMBeanServer()
.queryMBeans(new ObjectName("jpa.sample:type=ConnectionPool,*"), null) .queryMBeans(new ObjectName("jpa.sample:type=ConnectionPool,*"), null))
.size()); .hasSize(1);
} }
} }
...@@ -26,9 +26,7 @@ import org.springframework.data.domain.Page; ...@@ -26,9 +26,7 @@ import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.PageRequest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import static org.hamcrest.Matchers.greaterThan; import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
/** /**
* Integration tests for {@link CityRepository}. * Integration tests for {@link CityRepository}.
...@@ -46,6 +44,6 @@ public class CityRepositoryIntegrationTests { ...@@ -46,6 +44,6 @@ public class CityRepositoryIntegrationTests {
public void findsFirstPageOfCities() { public void findsFirstPageOfCities() {
Page<City> cities = this.repository.findAll(new PageRequest(0, 10)); Page<City> cities = this.repository.findAll(new PageRequest(0, 10));
assertThat(cities.getTotalElements(), is(greaterThan(20L))); assertThat(cities.getTotalElements()).isGreaterThan(20L);
} }
} }
...@@ -33,10 +33,7 @@ import org.springframework.data.domain.PageRequest; ...@@ -33,10 +33,7 @@ import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort.Direction; import org.springframework.data.domain.Sort.Direction;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import static org.hamcrest.Matchers.greaterThan; import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
/** /**
* Integration tests for {@link HotelRepository}. * Integration tests for {@link HotelRepository}.
...@@ -57,17 +54,17 @@ public class HotelRepositoryIntegrationTests { ...@@ -57,17 +54,17 @@ public class HotelRepositoryIntegrationTests {
City city = this.cityRepository City city = this.cityRepository
.findAll(new PageRequest(0, 1, Direction.ASC, "name")).getContent() .findAll(new PageRequest(0, 1, Direction.ASC, "name")).getContent()
.get(0); .get(0);
assertThat(city.getName(), is("Atlanta")); assertThat(city.getName()).isEqualTo("Atlanta");
Page<HotelSummary> hotels = this.repository.findByCity(city, Page<HotelSummary> hotels = this.repository.findByCity(city,
new PageRequest(0, 10, Direction.ASC, "name")); new PageRequest(0, 10, Direction.ASC, "name"));
Hotel hotel = this.repository.findByCityAndName(city, Hotel hotel = this.repository.findByCityAndName(city,
hotels.getContent().get(0).getName()); hotels.getContent().get(0).getName());
assertThat(hotel.getName(), is("Doubletree")); assertThat(hotel.getName()).isEqualTo("Doubletree");
List<RatingCount> counts = this.repository.findRatingCounts(hotel); List<RatingCount> counts = this.repository.findRatingCounts(hotel);
assertThat(counts, hasSize(1)); assertThat(counts).hasSize(1);
assertThat(counts.get(0).getRating(), is(Rating.AVERAGE)); assertThat(counts.get(0).getRating()).isEqualTo(Rating.AVERAGE);
assertThat(counts.get(0).getCount(), is(greaterThan(1L))); assertThat(counts.get(0).getCount()).isGreaterThan(1L);
} }
} }
...@@ -25,7 +25,7 @@ import org.springframework.boot.test.OutputCapture; ...@@ -25,7 +25,7 @@ import org.springframework.boot.test.OutputCapture;
import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import static org.junit.Assert.assertTrue; import static org.assertj.core.api.Assertions.assertThat;
/** /**
* Tests for {@link SampleMongoApplication}. * Tests for {@link SampleMongoApplication}.
...@@ -44,8 +44,7 @@ public class SampleMongoApplicationTests { ...@@ -44,8 +44,7 @@ public class SampleMongoApplicationTests {
@Test @Test
public void testDefaultSettings() throws Exception { public void testDefaultSettings() throws Exception {
String output = SampleMongoApplicationTests.outputCapture.toString(); String output = SampleMongoApplicationTests.outputCapture.toString();
assertTrue("Wrong output: " + output, assertThat(output).contains("firstName='Alice', lastName='Smith'");
output.contains("firstName='Alice', lastName='Smith'"));
} }
} }
...@@ -22,7 +22,7 @@ import org.junit.Test; ...@@ -22,7 +22,7 @@ import org.junit.Test;
import org.springframework.boot.test.OutputCapture; import org.springframework.boot.test.OutputCapture;
import org.springframework.data.redis.RedisConnectionFailureException; import org.springframework.data.redis.RedisConnectionFailureException;
import static org.junit.Assert.assertTrue; import static org.assertj.core.api.Assertions.assertThat;
/** /**
* Tests for {@link SampleRedisApplication}. * Tests for {@link SampleRedisApplication}.
...@@ -45,8 +45,7 @@ public class SampleRedisApplicationTests { ...@@ -45,8 +45,7 @@ public class SampleRedisApplicationTests {
} }
} }
String output = this.outputCapture.toString(); String output = this.outputCapture.toString();
assertTrue("Wrong output: " + output, assertThat(output).contains("Found key spring.boot.redis.test");
output.contains("Found key spring.boot.redis.test"));
} }
private boolean redisServerRunning(Throwable ex) { private boolean redisServerRunning(Throwable ex) {
......
...@@ -27,11 +27,7 @@ import org.springframework.data.domain.Page; ...@@ -27,11 +27,7 @@ import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.PageRequest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import static org.hamcrest.Matchers.equalTo; import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
import static org.junit.Assert.assertThat;
/** /**
* Integration tests for {@link CityRepository}. * Integration tests for {@link CityRepository}.
...@@ -50,15 +46,15 @@ public class CityRepositoryIntegrationTests { ...@@ -50,15 +46,15 @@ public class CityRepositoryIntegrationTests {
public void findsFirstPageOfCities() { public void findsFirstPageOfCities() {
Page<City> cities = this.repository.findAll(new PageRequest(0, 10)); Page<City> cities = this.repository.findAll(new PageRequest(0, 10));
assertThat(cities.getTotalElements(), is(greaterThan(20L))); assertThat(cities.getTotalElements()).isGreaterThan(20L);
} }
@Test @Test
public void findByNameAndCountry() { public void findByNameAndCountry() {
City city = this.repository.findByNameAndCountryAllIgnoringCase("Melbourne", City city = this.repository.findByNameAndCountryAllIgnoringCase("Melbourne",
"Australia"); "Australia");
assertThat(city, notNullValue()); assertThat(city).isNotNull();
assertThat(city.getName(), is(equalTo("Melbourne"))); assertThat(city.getName()).isEqualTo("Melbourne");
} }
@Test @Test
...@@ -66,6 +62,6 @@ public class CityRepositoryIntegrationTests { ...@@ -66,6 +62,6 @@ public class CityRepositoryIntegrationTests {
Page<City> cities = this.repository Page<City> cities = this.repository
.findByNameContainingAndCountryContainingAllIgnoringCase("", "UK", .findByNameContainingAndCountryContainingAllIgnoringCase("", "UK",
new PageRequest(0, 10)); new PageRequest(0, 10));
assertThat(cities.getTotalElements(), is(equalTo(3L))); assertThat(cities.getTotalElements()).isEqualTo(3L);
} }
} }
...@@ -22,7 +22,7 @@ import org.junit.Test; ...@@ -22,7 +22,7 @@ import org.junit.Test;
import org.springframework.boot.test.OutputCapture; import org.springframework.boot.test.OutputCapture;
import org.springframework.core.NestedCheckedException; import org.springframework.core.NestedCheckedException;
import static org.junit.Assert.assertTrue; import static org.assertj.core.api.Assertions.assertThat;
public class SampleSolrApplicationTests { public class SampleSolrApplicationTests {
...@@ -41,7 +41,7 @@ public class SampleSolrApplicationTests { ...@@ -41,7 +41,7 @@ public class SampleSolrApplicationTests {
} }
} }
String output = this.outputCapture.toString(); String output = this.outputCapture.toString();
assertTrue("Wrong output: " + output, output.contains("name=Sony Playstation")); assertThat(output).contains("name=Sony Playstation");
} }
private boolean serverNotRunning(IllegalStateException ex) { private boolean serverNotRunning(IllegalStateException ex) {
......
...@@ -24,7 +24,7 @@ import org.springframework.boot.test.SpringApplicationConfiguration; ...@@ -24,7 +24,7 @@ import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import static org.junit.Assert.assertEquals; import static org.assertj.core.api.Assertions.assertThat;
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(SampleFlywayApplication.class) @SpringApplicationConfiguration(SampleFlywayApplication.class)
...@@ -35,8 +35,8 @@ public class SampleFlywayApplicationTests { ...@@ -35,8 +35,8 @@ public class SampleFlywayApplicationTests {
@Test @Test
public void testDefaultSettings() throws Exception { public void testDefaultSettings() throws Exception {
assertEquals(new Integer(1), this.template assertThat(this.template.queryForObject("SELECT COUNT(*) from PERSON",
.queryForObject("SELECT COUNT(*) from PERSON", Integer.class)); Integer.class)).isEqualTo(1);
} }
} }
...@@ -33,10 +33,7 @@ import org.springframework.http.RequestEntity; ...@@ -33,10 +33,7 @@ import org.springframework.http.RequestEntity;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import static org.hamcrest.Matchers.containsString; import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.startsWith;
import static org.junit.Assert.assertThat;
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(SampleHateoasApplication.class) @SpringApplicationConfiguration(SampleHateoasApplication.class)
...@@ -50,10 +47,10 @@ public class SampleHateoasApplicationTests { ...@@ -50,10 +47,10 @@ public class SampleHateoasApplicationTests {
public void hasHalLinks() throws Exception { public void hasHalLinks() throws Exception {
ResponseEntity<String> entity = new TestRestTemplate().getForEntity( ResponseEntity<String> entity = new TestRestTemplate().getForEntity(
"http://localhost:" + this.port + "/customers/1", String.class); "http://localhost:" + this.port + "/customers/1", String.class);
assertThat(entity.getStatusCode(), equalTo(HttpStatus.OK)); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(entity.getBody(), startsWith( assertThat(entity.getBody()).startsWith(
"{\"id\":1,\"firstName\":\"Oliver\"" + ",\"lastName\":\"Gierke\"")); "{\"id\":1,\"firstName\":\"Oliver\"" + ",\"lastName\":\"Gierke\"");
assertThat(entity.getBody(), containsString("_links\":{\"self\":{\"href\"")); assertThat(entity.getBody()).contains("_links\":{\"self\":{\"href\"");
} }
@Test @Test
...@@ -64,9 +61,9 @@ public class SampleHateoasApplicationTests { ...@@ -64,9 +61,9 @@ public class SampleHateoasApplicationTests {
URI.create("http://localhost:" + this.port + "/customers/1")); URI.create("http://localhost:" + this.port + "/customers/1"));
ResponseEntity<String> response = new TestRestTemplate().exchange(request, ResponseEntity<String> response = new TestRestTemplate().exchange(request,
String.class); String.class);
assertThat(response.getStatusCode(), equalTo(HttpStatus.OK)); assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(response.getHeaders().getContentType(), assertThat(response.getHeaders().getContentType())
equalTo(MediaType.parseMediaType("application/json;charset=UTF-8"))); .isEqualTo(MediaType.parseMediaType("application/json;charset=UTF-8"));
} }
} }
...@@ -31,7 +31,7 @@ import org.springframework.test.web.servlet.MvcResult; ...@@ -31,7 +31,7 @@ import org.springframework.test.web.servlet.MvcResult;
import org.springframework.test.web.servlet.setup.MockMvcBuilders; import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext; import org.springframework.web.context.WebApplicationContext;
import static org.junit.Assert.assertEquals; import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
...@@ -83,8 +83,8 @@ public class SampleHypermediaJpaApplicationIntegrationTests { ...@@ -83,8 +83,8 @@ public class SampleHypermediaJpaApplicationIntegrationTests {
public void browser() throws Exception { public void browser() throws Exception {
MvcResult response = this.mockMvc.perform(get("/").accept(MediaType.TEXT_HTML)) MvcResult response = this.mockMvc.perform(get("/").accept(MediaType.TEXT_HTML))
.andExpect(status().isFound()).andReturn(); .andExpect(status().isFound()).andReturn();
assertEquals("/browser/index.html#", assertThat(response.getResponse().getHeaders("location").get(0))
response.getResponse().getHeaders("location").get(0)); .isEqualTo("/browser/index.html#");
} }
} }
...@@ -33,7 +33,7 @@ import org.springframework.http.RequestEntity; ...@@ -33,7 +33,7 @@ import org.springframework.http.RequestEntity;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import static org.junit.Assert.assertTrue; import static org.assertj.core.api.Assertions.assertThat;
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(SampleHypermediaUiApplication.class) @SpringApplicationConfiguration(SampleHypermediaUiApplication.class)
...@@ -47,14 +47,14 @@ public class SampleHypermediaUiApplicationTests { ...@@ -47,14 +47,14 @@ public class SampleHypermediaUiApplicationTests {
public void home() { public void home() {
String response = new TestRestTemplate() String response = new TestRestTemplate()
.getForObject("http://localhost:" + this.port, String.class); .getForObject("http://localhost:" + this.port, String.class);
assertTrue("Wrong body: " + response, response.contains("Hello World")); assertThat(response).contains("Hello World");
} }
@Test @Test
public void links() { public void links() {
String response = new TestRestTemplate().getForObject( String response = new TestRestTemplate().getForObject(
"http://localhost:" + this.port + "/actuator", String.class); "http://localhost:" + this.port + "/actuator", String.class);
assertTrue("Wrong body: " + response, response.contains("\"_links\":")); assertThat(response).contains("\"_links\":");
} }
@Test @Test
...@@ -65,7 +65,7 @@ public class SampleHypermediaUiApplicationTests { ...@@ -65,7 +65,7 @@ public class SampleHypermediaUiApplicationTests {
new RequestEntity<Void>(headers, HttpMethod.GET, new RequestEntity<Void>(headers, HttpMethod.GET,
new URI("http://localhost:" + this.port + "/actuator")), new URI("http://localhost:" + this.port + "/actuator")),
String.class); String.class);
assertTrue("Wrong body: " + response, response.getBody().contains("\"_links\":")); assertThat(response.getBody()).contains("\"_links\":");
} }
@Test @Test
...@@ -75,7 +75,7 @@ public class SampleHypermediaUiApplicationTests { ...@@ -75,7 +75,7 @@ public class SampleHypermediaUiApplicationTests {
ResponseEntity<String> response = new TestRestTemplate() ResponseEntity<String> response = new TestRestTemplate()
.exchange(new RequestEntity<Void>(headers, HttpMethod.GET, .exchange(new RequestEntity<Void>(headers, HttpMethod.GET,
new URI("http://localhost:" + this.port)), String.class); new URI("http://localhost:" + this.port)), String.class);
assertTrue("Wrong body: " + response, response.getBody().contains("Hello World")); assertThat(response.getBody()).contains("Hello World");
} }
} }
...@@ -33,7 +33,7 @@ import org.springframework.http.RequestEntity; ...@@ -33,7 +33,7 @@ import org.springframework.http.RequestEntity;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import static org.junit.Assert.assertTrue; import static org.assertj.core.api.Assertions.assertThat;
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(SampleHypermediaApplication.class) @SpringApplicationConfiguration(SampleHypermediaApplication.class)
...@@ -47,7 +47,7 @@ public class SampleHypermediaApplicationHomePageTests { ...@@ -47,7 +47,7 @@ public class SampleHypermediaApplicationHomePageTests {
public void home() { public void home() {
String response = new TestRestTemplate() String response = new TestRestTemplate()
.getForObject("http://localhost:" + this.port, String.class); .getForObject("http://localhost:" + this.port, String.class);
assertTrue("Wrong body: " + response, response.contains("404")); assertThat(response).contains("404");
} }
@Test @Test
...@@ -58,7 +58,7 @@ public class SampleHypermediaApplicationHomePageTests { ...@@ -58,7 +58,7 @@ public class SampleHypermediaApplicationHomePageTests {
new RequestEntity<Void>(headers, HttpMethod.GET, new RequestEntity<Void>(headers, HttpMethod.GET,
new URI("http://localhost:" + this.port + "/actuator")), new URI("http://localhost:" + this.port + "/actuator")),
String.class); String.class);
assertTrue("Wrong body: " + response, response.getBody().contains("\"_links\":")); assertThat(response.getBody()).contains("\"_links\":");
} }
@Test @Test
...@@ -69,7 +69,7 @@ public class SampleHypermediaApplicationHomePageTests { ...@@ -69,7 +69,7 @@ public class SampleHypermediaApplicationHomePageTests {
new RequestEntity<Void>(headers, HttpMethod.GET, new RequestEntity<Void>(headers, HttpMethod.GET,
new URI("http://localhost:" + this.port + "/actuator/")), new URI("http://localhost:" + this.port + "/actuator/")),
String.class); String.class);
assertTrue("Wrong body: " + response, response.getBody().contains("HAL Browser")); assertThat(response.getBody()).contains("HAL Browser");
} }
} }
...@@ -38,7 +38,7 @@ import org.springframework.core.io.support.ResourcePatternUtils; ...@@ -38,7 +38,7 @@ import org.springframework.core.io.support.ResourcePatternUtils;
import org.springframework.util.FileSystemUtils; import org.springframework.util.FileSystemUtils;
import org.springframework.util.StreamUtils; import org.springframework.util.StreamUtils;
import static org.junit.Assert.assertTrue; import static org.assertj.core.api.Assertions.assertThat;
/** /**
* Basic integration tests for service demo application. * Basic integration tests for service demo application.
...@@ -71,7 +71,7 @@ public class SampleIntegrationApplicationTests { ...@@ -71,7 +71,7 @@ public class SampleIntegrationApplicationTests {
public void testVanillaExchange() throws Exception { public void testVanillaExchange() throws Exception {
SpringApplication.run(ProducerApplication.class, "World"); SpringApplication.run(ProducerApplication.class, "World");
String output = getOutput(); String output = getOutput();
assertTrue("Wrong output: " + output, output.contains("Hello World")); assertThat(output).contains("Hello World");
} }
private String getOutput() throws Exception { private String getOutput() throws Exception {
......
...@@ -28,7 +28,7 @@ import org.springframework.http.ResponseEntity; ...@@ -28,7 +28,7 @@ import org.springframework.http.ResponseEntity;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
import static org.junit.Assert.assertEquals; import static org.assertj.core.api.Assertions.assertThat;
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(SampleJerseyApplication.class) @SpringApplicationConfiguration(SampleJerseyApplication.class)
...@@ -44,22 +44,22 @@ public class SampleJerseyApplicationTests { ...@@ -44,22 +44,22 @@ public class SampleJerseyApplicationTests {
public void contextLoads() { public void contextLoads() {
ResponseEntity<String> entity = this.restTemplate ResponseEntity<String> entity = this.restTemplate
.getForEntity("http://localhost:" + this.port + "/hello", String.class); .getForEntity("http://localhost:" + this.port + "/hello", String.class);
assertEquals(HttpStatus.OK, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
} }
@Test @Test
public void reverse() { public void reverse() {
ResponseEntity<String> entity = this.restTemplate.getForEntity( ResponseEntity<String> entity = this.restTemplate.getForEntity(
"http://localhost:" + this.port + "/reverse?input=olleh", String.class); "http://localhost:" + this.port + "/reverse?input=olleh", String.class);
assertEquals(HttpStatus.OK, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertEquals("hello", entity.getBody()); assertThat(entity.getBody()).isEqualTo("hello");
} }
@Test @Test
public void validation() { public void validation() {
ResponseEntity<String> entity = this.restTemplate ResponseEntity<String> entity = this.restTemplate
.getForEntity("http://localhost:" + this.port + "/reverse", String.class); .getForEntity("http://localhost:" + this.port + "/reverse", String.class);
assertEquals(HttpStatus.BAD_REQUEST, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST);
} }
} }
...@@ -25,7 +25,7 @@ import org.springframework.boot.test.TestRestTemplate; ...@@ -25,7 +25,7 @@ import org.springframework.boot.test.TestRestTemplate;
import org.springframework.boot.test.WebIntegrationTest; import org.springframework.boot.test.WebIntegrationTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import static org.junit.Assert.assertEquals; import static org.assertj.core.api.Assertions.assertThat;
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(SampleJersey1Application.class) @SpringApplicationConfiguration(SampleJersey1Application.class)
...@@ -37,8 +37,9 @@ public class SampleJersey1ApplicationTests { ...@@ -37,8 +37,9 @@ public class SampleJersey1ApplicationTests {
@Test @Test
public void contextLoads() { public void contextLoads() {
assertEquals("Hello World", new TestRestTemplate() assertThat(new TestRestTemplate()
.getForObject("http://localhost:" + this.port + "/", String.class)); .getForObject("http://localhost:" + this.port + "/", String.class))
.isEqualTo("Hello World");
} }
} }
...@@ -34,7 +34,7 @@ import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; ...@@ -34,7 +34,7 @@ import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import static org.junit.Assert.assertEquals; import static org.assertj.core.api.Assertions.assertThat;
/** /**
* Basic integration tests for demo application. * Basic integration tests for demo application.
...@@ -64,8 +64,8 @@ public class SampleJettySslApplicationTests { ...@@ -64,8 +64,8 @@ public class SampleJettySslApplicationTests {
.setHttpClient(httpClient); .setHttpClient(httpClient);
ResponseEntity<String> entity = testRestTemplate ResponseEntity<String> entity = testRestTemplate
.getForEntity("https://localhost:" + this.port, String.class); .getForEntity("https://localhost:" + this.port, String.class);
assertEquals(HttpStatus.OK, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertEquals("Hello World", entity.getBody()); assertThat(entity.getBody()).isEqualTo("Hello World");
} }
} }
...@@ -37,7 +37,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; ...@@ -37,7 +37,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.util.StreamUtils; import org.springframework.util.StreamUtils;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
import static org.junit.Assert.assertEquals; import static org.assertj.core.api.Assertions.assertThat;
/** /**
* Basic integration tests for demo application. * Basic integration tests for demo application.
...@@ -58,8 +58,8 @@ public class SampleJettyApplicationTests { ...@@ -58,8 +58,8 @@ public class SampleJettyApplicationTests {
public void testHome() throws Exception { public void testHome() throws Exception {
ResponseEntity<String> entity = new TestRestTemplate() ResponseEntity<String> entity = new TestRestTemplate()
.getForEntity("http://localhost:" + this.port, String.class); .getForEntity("http://localhost:" + this.port, String.class);
assertEquals(HttpStatus.OK, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertEquals("Hello World", entity.getBody()); assertThat(entity.getBody()).isEqualTo("Hello World");
} }
@Test @Test
...@@ -74,13 +74,13 @@ public class SampleJettyApplicationTests { ...@@ -74,13 +74,13 @@ public class SampleJettyApplicationTests {
"http://localhost:" + this.port, HttpMethod.GET, requestEntity, "http://localhost:" + this.port, HttpMethod.GET, requestEntity,
byte[].class); byte[].class);
assertEquals(HttpStatus.OK, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
GZIPInputStream inflater = new GZIPInputStream( GZIPInputStream inflater = new GZIPInputStream(
new ByteArrayInputStream(entity.getBody())); new ByteArrayInputStream(entity.getBody()));
try { try {
assertEquals("Hello World", assertThat(StreamUtils.copyToString(inflater, Charset.forName("UTF-8")))
StreamUtils.copyToString(inflater, Charset.forName("UTF-8"))); .isEqualTo("Hello World");
} }
finally { finally {
inflater.close(); inflater.close();
......
...@@ -34,7 +34,7 @@ import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; ...@@ -34,7 +34,7 @@ import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import static org.junit.Assert.assertEquals; import static org.assertj.core.api.Assertions.assertThat;
/** /**
* Basic integration tests for demo application. * Basic integration tests for demo application.
...@@ -64,8 +64,8 @@ public class SampleJetty8SslApplicationTests { ...@@ -64,8 +64,8 @@ public class SampleJetty8SslApplicationTests {
.setHttpClient(httpClient); .setHttpClient(httpClient);
ResponseEntity<String> entity = testRestTemplate ResponseEntity<String> entity = testRestTemplate
.getForEntity("https://localhost:" + this.port, String.class); .getForEntity("https://localhost:" + this.port, String.class);
assertEquals(HttpStatus.OK, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertEquals("Hello World", entity.getBody()); assertThat(entity.getBody()).isEqualTo("Hello World");
} }
} }
...@@ -37,7 +37,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; ...@@ -37,7 +37,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.util.StreamUtils; import org.springframework.util.StreamUtils;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
import static org.junit.Assert.assertEquals; import static org.assertj.core.api.Assertions.assertThat;
/** /**
* Basic integration tests for demo application. * Basic integration tests for demo application.
...@@ -58,8 +58,8 @@ public class SampleJetty8ApplicationTests { ...@@ -58,8 +58,8 @@ public class SampleJetty8ApplicationTests {
public void testHome() throws Exception { public void testHome() throws Exception {
ResponseEntity<String> entity = new TestRestTemplate() ResponseEntity<String> entity = new TestRestTemplate()
.getForEntity("http://localhost:" + this.port, String.class); .getForEntity("http://localhost:" + this.port, String.class);
assertEquals(HttpStatus.OK, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertEquals("Hello World", entity.getBody()); assertThat(entity.getBody()).isEqualTo("Hello World");
} }
@Test @Test
...@@ -71,12 +71,12 @@ public class SampleJetty8ApplicationTests { ...@@ -71,12 +71,12 @@ public class SampleJetty8ApplicationTests {
ResponseEntity<byte[]> entity = restTemplate.exchange( ResponseEntity<byte[]> entity = restTemplate.exchange(
"http://localhost:" + this.port, HttpMethod.GET, requestEntity, "http://localhost:" + this.port, HttpMethod.GET, requestEntity,
byte[].class); byte[].class);
assertEquals(HttpStatus.OK, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
GZIPInputStream inflater = new GZIPInputStream( GZIPInputStream inflater = new GZIPInputStream(
new ByteArrayInputStream(entity.getBody())); new ByteArrayInputStream(entity.getBody()));
try { try {
assertEquals("Hello World", assertThat(StreamUtils.copyToString(inflater, Charset.forName("UTF-8")))
StreamUtils.copyToString(inflater, Charset.forName("UTF-8"))); .isEqualTo("Hello World");
} }
finally { finally {
inflater.close(); inflater.close();
......
...@@ -37,7 +37,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; ...@@ -37,7 +37,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.util.StreamUtils; import org.springframework.util.StreamUtils;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
import static org.junit.Assert.assertEquals; import static org.assertj.core.api.Assertions.assertThat;
/** /**
* Basic integration tests for demo application. * Basic integration tests for demo application.
...@@ -58,8 +58,8 @@ public class SampleJetty93ApplicationTests { ...@@ -58,8 +58,8 @@ public class SampleJetty93ApplicationTests {
public void testHome() throws Exception { public void testHome() throws Exception {
ResponseEntity<String> entity = new TestRestTemplate() ResponseEntity<String> entity = new TestRestTemplate()
.getForEntity("http://localhost:" + this.port, String.class); .getForEntity("http://localhost:" + this.port, String.class);
assertEquals(HttpStatus.OK, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertEquals("Hello World", entity.getBody()); assertThat(entity.getBody()).isEqualTo("Hello World");
} }
@Test @Test
...@@ -71,12 +71,12 @@ public class SampleJetty93ApplicationTests { ...@@ -71,12 +71,12 @@ public class SampleJetty93ApplicationTests {
ResponseEntity<byte[]> entity = restTemplate.exchange( ResponseEntity<byte[]> entity = restTemplate.exchange(
"http://localhost:" + this.port, HttpMethod.GET, requestEntity, "http://localhost:" + this.port, HttpMethod.GET, requestEntity,
byte[].class); byte[].class);
assertEquals(HttpStatus.OK, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
GZIPInputStream inflater = new GZIPInputStream( GZIPInputStream inflater = new GZIPInputStream(
new ByteArrayInputStream(entity.getBody())); new ByteArrayInputStream(entity.getBody()));
try { try {
assertEquals("Hello World", assertThat(StreamUtils.copyToString(inflater, Charset.forName("UTF-8")))
StreamUtils.copyToString(inflater, Charset.forName("UTF-8"))); .isEqualTo("Hello World");
} }
finally { finally {
inflater.close(); inflater.close();
......
...@@ -21,8 +21,7 @@ import org.junit.Test; ...@@ -21,8 +21,7 @@ import org.junit.Test;
import org.springframework.boot.test.OutputCapture; import org.springframework.boot.test.OutputCapture;
import static org.hamcrest.Matchers.containsString; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertThat;
/** /**
* Integration tests for {@link SampleJooqApplication}. * Integration tests for {@link SampleJooqApplication}.
...@@ -37,11 +36,11 @@ public class SampleJooqApplicationTests { ...@@ -37,11 +36,11 @@ public class SampleJooqApplicationTests {
@Test @Test
public void outputResults() throws Exception { public void outputResults() throws Exception {
SampleJooqApplication.main(NO_ARGS); SampleJooqApplication.main(NO_ARGS);
assertThat(this.out.toString(), containsString("jOOQ Fetch 1 Greg Turnquest")); assertThat(this.out.toString()).contains("jOOQ Fetch 1 Greg Turnquest");
assertThat(this.out.toString(), containsString("jOOQ Fetch 2 Craig Walls")); assertThat(this.out.toString()).contains("jOOQ Fetch 2 Craig Walls");
assertThat(this.out.toString(), assertThat(this.out.toString())
containsString("jOOQ SQL " + "[Learning Spring Boot : Greg Turnquest, " .contains("jOOQ SQL " + "[Learning Spring Boot : Greg Turnquest, "
+ "Spring Boot in Action : Craig Walls]")); + "Spring Boot in Action : Craig Walls]");
} }
} }
...@@ -26,7 +26,7 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -26,7 +26,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import static org.junit.Assert.assertEquals; import static org.assertj.core.api.Assertions.assertThat;
/** /**
* Integration tests for {@link JpaNoteRepository}. * Integration tests for {@link JpaNoteRepository}.
...@@ -43,7 +43,7 @@ public class JpaNoteRepositoryIntegrationTests { ...@@ -43,7 +43,7 @@ public class JpaNoteRepositoryIntegrationTests {
@Test @Test
public void findsAllNotes() { public void findsAllNotes() {
List<Note> notes = this.repository.findAll(); List<Note> notes = this.repository.findAll();
assertEquals(4, notes.size()); assertThat(notes).hasSize(4);
} }
} }
...@@ -26,7 +26,7 @@ import org.springframework.beans.factory.annotation.Autowired; ...@@ -26,7 +26,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import static org.junit.Assert.assertEquals; import static org.assertj.core.api.Assertions.assertThat;
/** /**
* Integration tests for {@link JpaTagRepository}. * Integration tests for {@link JpaTagRepository}.
...@@ -43,7 +43,7 @@ public class JpaTagRepositoryIntegrationTests { ...@@ -43,7 +43,7 @@ public class JpaTagRepositoryIntegrationTests {
@Test @Test
public void findsAllTags() { public void findsAllTags() {
List<Tag> tags = this.repository.findAll(); List<Tag> tags = this.repository.findAll();
assertEquals(3, tags.size()); assertThat(tags).hasSize(3);
} }
} }
...@@ -16,14 +16,13 @@ ...@@ -16,14 +16,13 @@
package sample.atomikos; package sample.atomikos;
import org.hamcrest.Matcher; import org.assertj.core.api.Condition;
import org.hamcrest.core.SubstringMatcher;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.springframework.boot.test.OutputCapture; import org.springframework.boot.test.OutputCapture;
import static org.junit.Assert.assertThat; import static org.assertj.core.api.Assertions.assertThat;
/** /**
* Basic integration tests for demo application. * Basic integration tests for demo application.
...@@ -39,25 +38,22 @@ public class SampleAtomikosApplicationTests { ...@@ -39,25 +38,22 @@ public class SampleAtomikosApplicationTests {
public void testTransactionRollback() throws Exception { public void testTransactionRollback() throws Exception {
SampleAtomikosApplication.main(new String[] {}); SampleAtomikosApplication.main(new String[] {});
String output = this.outputCapture.toString(); String output = this.outputCapture.toString();
assertThat(output, containsString(1, "---->")); assertThat(output).has(substring(1, "---->"));
assertThat(output, containsString(1, "----> josh")); assertThat(output).has(substring(1, "----> josh"));
assertThat(output, containsString(2, "Count is 1")); assertThat(output).has(substring(2, "Count is 1"));
assertThat(output, containsString(1, "Simulated error")); assertThat(output).has(substring(1, "Simulated error"));
} }
private Matcher<? super String> containsString(final int times, String s) { private Condition<String> substring(final int times, final String substring) {
return new SubstringMatcher(s) { return new Condition<String>(
"containing '" + substring + "' " + times + " times") {
@Override @Override
protected String relationship() { public boolean matches(String value) {
return "containing " + times + " times";
}
@Override
protected boolean evalSubstringOf(String s) {
int i = 0; int i = 0;
while (s.contains(this.substring)) { while (value.contains(substring)) {
s = s.substring(s.indexOf(this.substring) + this.substring.length()); int beginIndex = value.indexOf(substring) + substring.length();
value = value.substring(beginIndex);
i++; i++;
} }
return i == times; return i == times;
......
...@@ -17,8 +17,7 @@ ...@@ -17,8 +17,7 @@
package sample.bitronix; package sample.bitronix;
import bitronix.tm.resource.jms.PoolingConnectionFactory; import bitronix.tm.resource.jms.PoolingConnectionFactory;
import org.hamcrest.Matcher; import org.assertj.core.api.Condition;
import org.hamcrest.core.SubstringMatcher;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
...@@ -26,10 +25,7 @@ import org.springframework.boot.SpringApplication; ...@@ -26,10 +25,7 @@ import org.springframework.boot.SpringApplication;
import org.springframework.boot.test.OutputCapture; import org.springframework.boot.test.OutputCapture;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import static org.hamcrest.Matchers.instanceOf; import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.sameInstance;
import static org.junit.Assert.assertThat;
/** /**
* Basic integration tests for demo application. * Basic integration tests for demo application.
...@@ -45,10 +41,10 @@ public class SampleBitronixApplicationTests { ...@@ -45,10 +41,10 @@ public class SampleBitronixApplicationTests {
public void testTransactionRollback() throws Exception { public void testTransactionRollback() throws Exception {
SampleBitronixApplication.main(new String[] {}); SampleBitronixApplication.main(new String[] {});
String output = this.outputCapture.toString(); String output = this.outputCapture.toString();
assertThat(output, containsString(1, "---->")); assertThat(output).has(substring(1, "---->"));
assertThat(output, containsString(1, "----> josh")); assertThat(output).has(substring(1, "----> josh"));
assertThat(output, containsString(2, "Count is 1")); assertThat(output).has(substring(2, "Count is 1"));
assertThat(output, containsString(1, "Simulated error")); assertThat(output).has(substring(1, "Simulated error"));
} }
@Test @Test
...@@ -58,25 +54,22 @@ public class SampleBitronixApplicationTests { ...@@ -58,25 +54,22 @@ public class SampleBitronixApplicationTests {
Object jmsConnectionFactory = context.getBean("jmsConnectionFactory"); Object jmsConnectionFactory = context.getBean("jmsConnectionFactory");
Object xaJmsConnectionFactory = context.getBean("xaJmsConnectionFactory"); Object xaJmsConnectionFactory = context.getBean("xaJmsConnectionFactory");
Object nonXaJmsConnectionFactory = context.getBean("nonXaJmsConnectionFactory"); Object nonXaJmsConnectionFactory = context.getBean("nonXaJmsConnectionFactory");
assertThat(jmsConnectionFactory, sameInstance(xaJmsConnectionFactory)); assertThat(jmsConnectionFactory).isSameAs(xaJmsConnectionFactory);
assertThat(jmsConnectionFactory, instanceOf(PoolingConnectionFactory.class)); assertThat(jmsConnectionFactory).isInstanceOf(PoolingConnectionFactory.class);
assertThat(nonXaJmsConnectionFactory, assertThat(nonXaJmsConnectionFactory)
not(instanceOf(PoolingConnectionFactory.class))); .isNotInstanceOf(PoolingConnectionFactory.class);
} }
private Matcher<? super String> containsString(final int times, String s) { private Condition<String> substring(final int times, final String substring) {
return new SubstringMatcher(s) { return new Condition<String>(
"containing '" + substring + "' " + times + " times") {
@Override @Override
protected String relationship() { public boolean matches(String value) {
return "containing " + times + " times";
}
@Override
protected boolean evalSubstringOf(String s) {
int i = 0; int i = 0;
while (s.contains(this.substring)) { while (value.contains(substring)) {
s = s.substring(s.indexOf(this.substring) + this.substring.length()); int beginIndex = value.indexOf(substring) + substring.length();
value = value.substring(beginIndex);
i++; i++;
} }
return i == times; return i == times;
......
...@@ -24,7 +24,7 @@ import org.junit.Test; ...@@ -24,7 +24,7 @@ import org.junit.Test;
import org.springframework.boot.test.OutputCapture; import org.springframework.boot.test.OutputCapture;
import org.springframework.core.NestedCheckedException; import org.springframework.core.NestedCheckedException;
import static org.junit.Assert.assertTrue; import static org.assertj.core.api.Assertions.assertThat;
public class SampleLiquibaseApplicationTests { public class SampleLiquibaseApplicationTests {
...@@ -42,23 +42,22 @@ public class SampleLiquibaseApplicationTests { ...@@ -42,23 +42,22 @@ public class SampleLiquibaseApplicationTests {
} }
} }
String output = this.outputCapture.toString(); String output = this.outputCapture.toString();
assertTrue("Wrong output: " + output, assertThat(output).contains("Successfully acquired change log lock")
output.contains("Successfully acquired change log lock") .contains("Creating database history "
&& output.contains("Creating database history "
+ "table with name: PUBLIC.DATABASECHANGELOG") + "table with name: PUBLIC.DATABASECHANGELOG")
&& output.contains("Table person created") .contains("Table person created")
&& output.contains("ChangeSet classpath:/db/" .contains("ChangeSet classpath:/db/"
+ "changelog/db.changelog-master.yaml::1::" + "changelog/db.changelog-master.yaml::1::"
+ "marceloverdijk ran successfully") + "marceloverdijk ran successfully")
&& output.contains("New row inserted into person") .contains("New row inserted into person")
&& output.contains("ChangeSet classpath:/db/changelog/" .contains("ChangeSet classpath:/db/changelog/"
+ "db.changelog-master.yaml::2::" + "db.changelog-master.yaml::2::"
+ "marceloverdijk ran successfully") + "marceloverdijk ran successfully")
&& output.contains("Successfully released change log lock")); .contains("Successfully released change log lock");
} }
private boolean serverNotRunning(IllegalStateException ex) {
@SuppressWarnings("serial") @SuppressWarnings("serial")
private boolean serverNotRunning(IllegalStateException ex) {
NestedCheckedException nested = new NestedCheckedException("failed", ex) { NestedCheckedException nested = new NestedCheckedException("failed", ex) {
}; };
if (nested.contains(ConnectException.class)) { if (nested.contains(ConnectException.class)) {
......
...@@ -27,7 +27,7 @@ import org.springframework.boot.test.WebIntegrationTest; ...@@ -27,7 +27,7 @@ import org.springframework.boot.test.WebIntegrationTest;
import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import static org.junit.Assert.assertEquals; import static org.assertj.core.api.Assertions.assertThat;
/** /**
* Basic integration tests for {@link SampleDropwizardMetricsApplication}. * Basic integration tests for {@link SampleDropwizardMetricsApplication}.
...@@ -49,7 +49,7 @@ public class SampleDropwizardMetricsApplicationTests { ...@@ -49,7 +49,7 @@ public class SampleDropwizardMetricsApplicationTests {
@Test @Test
public void timerCreated() { public void timerCreated() {
this.gauges.submit("timer.test", 1234); this.gauges.submit("timer.test", 1234);
assertEquals(1, this.registry.getTimers().get("timer.test").getCount()); assertThat(this.registry.getTimers().get("timer.test").getCount()).isEqualTo(1);
} }
} }
...@@ -23,7 +23,7 @@ import org.junit.Test; ...@@ -23,7 +23,7 @@ import org.junit.Test;
import org.springframework.boot.test.OutputCapture; import org.springframework.boot.test.OutputCapture;
import static org.junit.Assert.assertTrue; import static org.assertj.core.api.Assertions.assertThat;
public class SampleProfileApplicationTests { public class SampleProfileApplicationTests {
...@@ -51,7 +51,7 @@ public class SampleProfileApplicationTests { ...@@ -51,7 +51,7 @@ public class SampleProfileApplicationTests {
public void testDefaultProfile() throws Exception { public void testDefaultProfile() throws Exception {
SampleProfileApplication.main(new String[0]); SampleProfileApplication.main(new String[0]);
String output = this.outputCapture.toString(); String output = this.outputCapture.toString();
assertTrue("Wrong output: " + output, output.contains("Hello Phil")); assertThat(output).contains("Hello Phil");
} }
@Test @Test
...@@ -59,7 +59,7 @@ public class SampleProfileApplicationTests { ...@@ -59,7 +59,7 @@ public class SampleProfileApplicationTests {
System.setProperty("spring.profiles.active", "goodbye"); System.setProperty("spring.profiles.active", "goodbye");
SampleProfileApplication.main(new String[0]); SampleProfileApplication.main(new String[0]);
String output = this.outputCapture.toString(); String output = this.outputCapture.toString();
assertTrue("Wrong output: " + output, output.contains("Goodbye Everyone")); assertThat(output).contains("Goodbye Everyone");
} }
@Test @Test
...@@ -73,7 +73,7 @@ public class SampleProfileApplicationTests { ...@@ -73,7 +73,7 @@ public class SampleProfileApplicationTests {
System.setProperty("spring.profiles.active", "generic"); System.setProperty("spring.profiles.active", "generic");
SampleProfileApplication.main(new String[0]); SampleProfileApplication.main(new String[0]);
String output = this.outputCapture.toString(); String output = this.outputCapture.toString();
assertTrue("Wrong output: " + output, output.contains("Bonjour Phil")); assertThat(output).contains("Bonjour Phil");
} }
@Test @Test
...@@ -81,7 +81,7 @@ public class SampleProfileApplicationTests { ...@@ -81,7 +81,7 @@ public class SampleProfileApplicationTests {
SampleProfileApplication SampleProfileApplication
.main(new String[] { "--spring.profiles.active=goodbye" }); .main(new String[] { "--spring.profiles.active=goodbye" });
String output = this.outputCapture.toString(); String output = this.outputCapture.toString();
assertTrue("Wrong output: " + output, output.contains("Goodbye Everyone")); assertThat(output).contains("Goodbye Everyone");
} }
} }
...@@ -26,7 +26,7 @@ import org.springframework.boot.autoconfigure.web.ServerProperties; ...@@ -26,7 +26,7 @@ import org.springframework.boot.autoconfigure.web.ServerProperties;
import org.springframework.boot.test.EnvironmentTestUtils; import org.springframework.boot.test.EnvironmentTestUtils;
import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import static org.junit.Assert.assertEquals; import static org.assertj.core.api.Assertions.assertThat;
/** /**
* Tests for {@link SamplePropertyValidationApplication}. * Tests for {@link SamplePropertyValidationApplication}.
...@@ -53,8 +53,8 @@ public class SamplePropertyValidationApplicationTests { ...@@ -53,8 +53,8 @@ public class SamplePropertyValidationApplicationTests {
"sample.port:9090"); "sample.port:9090");
this.context.refresh(); this.context.refresh();
SampleProperties properties = this.context.getBean(SampleProperties.class); SampleProperties properties = this.context.getBean(SampleProperties.class);
assertEquals("192.168.0.1", properties.getHost()); assertThat(properties.getHost()).isEqualTo("192.168.0.1");
assertEquals(Integer.valueOf(9090), properties.getPort()); assertThat(properties.getPort()).isEqualTo(Integer.valueOf(9090));
} }
@Test @Test
...@@ -84,8 +84,8 @@ public class SamplePropertyValidationApplicationTests { ...@@ -84,8 +84,8 @@ public class SamplePropertyValidationApplicationTests {
"sample.port:9090"); "sample.port:9090");
this.context.refresh(); this.context.refresh();
SampleProperties properties = this.context.getBean(SampleProperties.class); SampleProperties properties = this.context.getBean(SampleProperties.class);
assertEquals("192.168.0.1", properties.getHost()); assertThat(properties.getHost()).isEqualTo("192.168.0.1");
assertEquals(Integer.valueOf(9090), properties.getPort()); assertThat(properties.getPort()).isEqualTo(Integer.valueOf(9090));
} }
} }
...@@ -20,8 +20,7 @@ import org.springframework.test.web.servlet.MockMvc; ...@@ -20,8 +20,7 @@ import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.MvcResult; import org.springframework.test.web.servlet.MvcResult;
import org.springframework.web.context.WebApplicationContext; import org.springframework.web.context.WebApplicationContext;
import static org.hamcrest.CoreMatchers.is; import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
...@@ -100,11 +99,11 @@ public class SampleSecureOAuth2ApplicationTests { ...@@ -100,11 +99,11 @@ public class SampleSecureOAuth2ApplicationTests {
Flight flight = this.objectMapper.readValue( Flight flight = this.objectMapper.readValue(
flightsAction.getResponse().getContentAsString(), Flight.class); flightsAction.getResponse().getContentAsString(), Flight.class);
assertThat(flight.getOrigin(), is("Nashville")); assertThat(flight.getOrigin()).isEqualTo("Nashville");
assertThat(flight.getDestination(), is("Dallas")); assertThat(flight.getDestination()).isEqualTo("Dallas");
assertThat(flight.getAirline(), is("Spring Ways")); assertThat(flight.getAirline()).isEqualTo("Spring Ways");
assertThat(flight.getFlightNumber(), is("OAUTH2")); assertThat(flight.getFlightNumber()).isEqualTo("OAUTH2");
assertThat(flight.getTraveler(), is("Greg Turnquist")); assertThat(flight.getTraveler()).isEqualTo("Greg Turnquist");
} }
} }
...@@ -35,7 +35,7 @@ import org.springframework.security.core.AuthenticationException; ...@@ -35,7 +35,7 @@ import org.springframework.security.core.AuthenticationException;
import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import static org.junit.Assert.assertEquals; import static org.assertj.core.api.Assertions.assertThat;
/** /**
* Basic integration tests for demo application. * Basic integration tests for demo application.
...@@ -70,25 +70,25 @@ public class SampleSecureApplicationTests { ...@@ -70,25 +70,25 @@ public class SampleSecureApplicationTests {
@Test(expected = AuthenticationException.class) @Test(expected = AuthenticationException.class)
public void secure() throws Exception { public void secure() throws Exception {
assertEquals(this.service.secure(), "Hello Security"); assertThat("Hello Security").isEqualTo(this.service.secure());
} }
@Test @Test
public void authenticated() throws Exception { public void authenticated() throws Exception {
SecurityContextHolder.getContext().setAuthentication(this.authentication); SecurityContextHolder.getContext().setAuthentication(this.authentication);
assertEquals(this.service.secure(), "Hello Security"); assertThat("Hello Security").isEqualTo(this.service.secure());
} }
@Test @Test
public void preauth() throws Exception { public void preauth() throws Exception {
SecurityContextHolder.getContext().setAuthentication(this.authentication); SecurityContextHolder.getContext().setAuthentication(this.authentication);
assertEquals(this.service.authorized(), "Hello World"); assertThat("Hello World").isEqualTo(this.service.authorized());
} }
@Test(expected = AccessDeniedException.class) @Test(expected = AccessDeniedException.class)
public void denied() throws Exception { public void denied() throws Exception {
SecurityContextHolder.getContext().setAuthentication(this.authentication); SecurityContextHolder.getContext().setAuthentication(this.authentication);
assertEquals(this.service.denied(), "Goodbye World"); assertThat("Goodbye World").isEqualTo(this.service.denied());
} }
@PropertySource("classpath:test.properties") @PropertySource("classpath:test.properties")
......
...@@ -30,7 +30,7 @@ import org.springframework.http.ResponseEntity; ...@@ -30,7 +30,7 @@ import org.springframework.http.ResponseEntity;
import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import static org.junit.Assert.assertEquals; import static org.assertj.core.api.Assertions.assertThat;
/** /**
* Basic integration tests for demo application. * Basic integration tests for demo application.
...@@ -53,15 +53,15 @@ public class SampleServletApplicationTests { ...@@ -53,15 +53,15 @@ public class SampleServletApplicationTests {
public void testHomeIsSecure() throws Exception { public void testHomeIsSecure() throws Exception {
ResponseEntity<String> entity = new TestRestTemplate() ResponseEntity<String> entity = new TestRestTemplate()
.getForEntity("http://localhost:" + this.port, String.class); .getForEntity("http://localhost:" + this.port, String.class);
assertEquals(HttpStatus.UNAUTHORIZED, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
} }
@Test @Test
public void testHome() throws Exception { public void testHome() throws Exception {
ResponseEntity<String> entity = new TestRestTemplate("user", getPassword()) ResponseEntity<String> entity = new TestRestTemplate("user", getPassword())
.getForEntity("http://localhost:" + this.port, String.class); .getForEntity("http://localhost:" + this.port, String.class);
assertEquals(HttpStatus.OK, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertEquals("Hello World", entity.getBody()); assertThat(entity.getBody()).isEqualTo("Hello World");
} }
private String getPassword() { private String getPassword() {
......
...@@ -30,10 +30,7 @@ import org.springframework.http.RequestEntity; ...@@ -30,10 +30,7 @@ import org.springframework.http.RequestEntity;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
import static org.hamcrest.Matchers.equalTo; import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
import static org.junit.Assert.assertThat;
/** /**
* Tests for {@link SampleSessionRedisApplication}. * Tests for {@link SampleSessionRedisApplication}.
...@@ -73,12 +70,12 @@ public class SampleSessionRedisApplicationTests { ...@@ -73,12 +70,12 @@ public class SampleSessionRedisApplicationTests {
HttpMethod.GET, uri); HttpMethod.GET, uri);
String uuid2 = restTemplate.exchange(request, String.class).getBody(); String uuid2 = restTemplate.exchange(request, String.class).getBody();
assertThat(uuid1, is(equalTo(uuid2))); assertThat(uuid1).isEqualTo(uuid2);
Thread.sleep(5000); Thread.sleep(5000);
String uuid3 = restTemplate.exchange(request, String.class).getBody(); String uuid3 = restTemplate.exchange(request, String.class).getBody();
assertThat(uuid2, is(not(equalTo(uuid3)))); assertThat(uuid2).isNotEqualTo(uuid3);
} }
private boolean redisServerRunning(Throwable ex) { private boolean redisServerRunning(Throwable ex) {
......
...@@ -23,7 +23,7 @@ import org.junit.Test; ...@@ -23,7 +23,7 @@ import org.junit.Test;
import org.springframework.boot.test.OutputCapture; import org.springframework.boot.test.OutputCapture;
import static org.junit.Assert.assertTrue; import static org.assertj.core.api.Assertions.assertThat;
/** /**
* Tests for {@link SampleSimpleApplication}. * Tests for {@link SampleSimpleApplication}.
...@@ -57,14 +57,14 @@ public class SampleSimpleApplicationTests { ...@@ -57,14 +57,14 @@ public class SampleSimpleApplicationTests {
public void testDefaultSettings() throws Exception { public void testDefaultSettings() throws Exception {
SampleSimpleApplication.main(new String[0]); SampleSimpleApplication.main(new String[0]);
String output = this.outputCapture.toString(); String output = this.outputCapture.toString();
assertTrue("Wrong output: " + output, output.contains("Hello Phil")); assertThat(output).contains("Hello Phil");
} }
@Test @Test
public void testCommandLineOverrides() throws Exception { public void testCommandLineOverrides() throws Exception {
SampleSimpleApplication.main(new String[] { "--name=Gordon" }); SampleSimpleApplication.main(new String[] { "--name=Gordon" });
String output = this.outputCapture.toString(); String output = this.outputCapture.toString();
assertTrue("Wrong output: " + output, output.contains("Hello Gordon")); assertThat(output).contains("Hello Gordon");
} }
} }
...@@ -24,8 +24,7 @@ import org.springframework.boot.test.SpringApplicationConfiguration; ...@@ -24,8 +24,7 @@ import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import static org.junit.Assert.assertNotNull; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertTrue;
/** /**
* Tests for {@link SampleSimpleApplication}. * Tests for {@link SampleSimpleApplication}.
...@@ -41,9 +40,9 @@ public class SpringTestSampleSimpleApplicationTests { ...@@ -41,9 +40,9 @@ public class SpringTestSampleSimpleApplicationTests {
@Test @Test
public void testContextLoads() throws Exception { public void testContextLoads() throws Exception {
assertNotNull(this.ctx); assertThat(this.ctx).isNotNull();
assertTrue(this.ctx.containsBean("helloWorldService")); assertThat(this.ctx.containsBean("helloWorldService")).isTrue();
assertTrue(this.ctx.containsBean("sampleSimpleApplication")); assertThat(this.ctx.containsBean("sampleSimpleApplication")).isTrue();
} }
} }
...@@ -40,6 +40,10 @@ ...@@ -40,6 +40,10 @@
<artifactId>testng</artifactId> <artifactId>testng</artifactId>
<version>6.8.13</version> <version>6.8.13</version>
</dependency> </dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
</dependency>
</dependencies> </dependencies>
<build> <build>
<plugins> <plugins>
......
...@@ -27,7 +27,7 @@ import org.springframework.http.ResponseEntity; ...@@ -27,7 +27,7 @@ import org.springframework.http.ResponseEntity;
import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests; import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import static org.testng.Assert.assertEquals; import static org.assertj.core.api.Assertions.assertThat;
/** /**
* Basic integration tests for demo application. * Basic integration tests for demo application.
...@@ -46,8 +46,8 @@ public class SampleTestNGApplicationTests extends AbstractTestNGSpringContextTes ...@@ -46,8 +46,8 @@ public class SampleTestNGApplicationTests extends AbstractTestNGSpringContextTes
public void testHome() throws Exception { public void testHome() throws Exception {
ResponseEntity<String> entity = new TestRestTemplate() ResponseEntity<String> entity = new TestRestTemplate()
.getForEntity("http://localhost:" + this.port, String.class); .getForEntity("http://localhost:" + this.port, String.class);
assertEquals(HttpStatus.OK, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertEquals("Hello World", entity.getBody()); assertThat(entity.getBody()).isEqualTo("Hello World");
} }
} }
...@@ -28,8 +28,7 @@ import org.springframework.http.ResponseEntity; ...@@ -28,8 +28,7 @@ import org.springframework.http.ResponseEntity;
import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import static org.junit.Assert.assertEquals; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertTrue;
/** /**
* Basic integration tests for JSP application. * Basic integration tests for JSP application.
...@@ -49,9 +48,8 @@ public class SampleWebJspApplicationTests { ...@@ -49,9 +48,8 @@ public class SampleWebJspApplicationTests {
public void testJspWithEl() throws Exception { public void testJspWithEl() throws Exception {
ResponseEntity<String> entity = new TestRestTemplate() ResponseEntity<String> entity = new TestRestTemplate()
.getForEntity("http://localhost:" + this.port, String.class); .getForEntity("http://localhost:" + this.port, String.class);
assertEquals(HttpStatus.OK, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertTrue("Wrong body:\n" + entity.getBody(), assertThat(entity.getBody()).contains("/resources/text.txt");
entity.getBody().contains("/resources/text.txt"));
} }
} }
...@@ -42,7 +42,7 @@ import org.springframework.test.annotation.DirtiesContext; ...@@ -42,7 +42,7 @@ import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
import static org.junit.Assert.assertEquals; import static org.assertj.core.api.Assertions.assertThat;
/** /**
* Basic integration tests for {@link SampleTomcatTwoConnectorsApplication}. * Basic integration tests for {@link SampleTomcatTwoConnectorsApplication}.
...@@ -111,13 +111,13 @@ public class SampleTomcatTwoConnectorsApplicationTests { ...@@ -111,13 +111,13 @@ public class SampleTomcatTwoConnectorsApplicationTests {
ResponseEntity<String> entity = template.getForEntity( ResponseEntity<String> entity = template.getForEntity(
"http://localhost:" + this.context.getBean("port") + "/hello", "http://localhost:" + this.context.getBean("port") + "/hello",
String.class); String.class);
assertEquals(HttpStatus.OK, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertEquals("hello", entity.getBody()); assertThat(entity.getBody()).isEqualTo("hello");
ResponseEntity<String> httpsEntity = template ResponseEntity<String> httpsEntity = template
.getForEntity("https://localhost:" + this.port + "/hello", String.class); .getForEntity("https://localhost:" + this.port + "/hello", String.class);
assertEquals(HttpStatus.OK, httpsEntity.getStatusCode()); assertThat(httpsEntity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertEquals("hello", httpsEntity.getBody()); assertThat(httpsEntity.getBody()).isEqualTo("hello");
} }
......
...@@ -23,19 +23,19 @@ import org.apache.http.impl.client.HttpClients; ...@@ -23,19 +23,19 @@ import org.apache.http.impl.client.HttpClients;
import org.apache.http.ssl.SSLContextBuilder; import org.apache.http.ssl.SSLContextBuilder;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.boot.test.WebIntegrationTest;
import sample.tomcat.ssl.SampleTomcatSslApplication; import sample.tomcat.ssl.SampleTomcatSslApplication;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.boot.test.TestRestTemplate; import org.springframework.boot.test.TestRestTemplate;
import org.springframework.boot.test.WebIntegrationTest;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import static org.junit.Assert.assertEquals; import static org.assertj.core.api.Assertions.assertThat;
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(SampleTomcatSslApplication.class) @SpringApplicationConfiguration(SampleTomcatSslApplication.class)
...@@ -60,8 +60,8 @@ public class SampleTomcatSslApplicationTests { ...@@ -60,8 +60,8 @@ public class SampleTomcatSslApplicationTests {
.setHttpClient(httpClient); .setHttpClient(httpClient);
ResponseEntity<String> entity = testRestTemplate ResponseEntity<String> entity = testRestTemplate
.getForEntity("https://localhost:" + this.port, String.class); .getForEntity("https://localhost:" + this.port, String.class);
assertEquals(HttpStatus.OK, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertEquals("Hello, world", entity.getBody()); assertThat(entity.getBody()).isEqualTo("Hello, world");
} }
} }
...@@ -18,7 +18,6 @@ package sample.tomcat; ...@@ -18,7 +18,6 @@ package sample.tomcat;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.boot.test.WebIntegrationTest;
import sample.tomcat.NonAutoConfigurationSampleTomcatApplicationTests.NonAutoConfigurationSampleTomcatApplication; import sample.tomcat.NonAutoConfigurationSampleTomcatApplicationTests.NonAutoConfigurationSampleTomcatApplication;
import sample.tomcat.service.HelloWorldService; import sample.tomcat.service.HelloWorldService;
import sample.tomcat.web.SampleController; import sample.tomcat.web.SampleController;
...@@ -33,6 +32,7 @@ import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfigurat ...@@ -33,6 +32,7 @@ import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfigurat
import org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration; import org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration;
import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.boot.test.TestRestTemplate; import org.springframework.boot.test.TestRestTemplate;
import org.springframework.boot.test.WebIntegrationTest;
import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import; import org.springframework.context.annotation.Import;
...@@ -41,7 +41,7 @@ import org.springframework.http.ResponseEntity; ...@@ -41,7 +41,7 @@ import org.springframework.http.ResponseEntity;
import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import static org.junit.Assert.assertEquals; import static org.assertj.core.api.Assertions.assertThat;
/** /**
* Basic integration tests for demo application. * Basic integration tests for demo application.
...@@ -77,8 +77,8 @@ public class NonAutoConfigurationSampleTomcatApplicationTests { ...@@ -77,8 +77,8 @@ public class NonAutoConfigurationSampleTomcatApplicationTests {
public void testHome() throws Exception { public void testHome() throws Exception {
ResponseEntity<String> entity = new TestRestTemplate() ResponseEntity<String> entity = new TestRestTemplate()
.getForEntity("http://localhost:" + this.port, String.class); .getForEntity("http://localhost:" + this.port, String.class);
assertEquals(HttpStatus.OK, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertEquals("Hello World", entity.getBody()); assertThat(entity.getBody()).isEqualTo("Hello World");
} }
} }
...@@ -37,7 +37,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; ...@@ -37,7 +37,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.util.StreamUtils; import org.springframework.util.StreamUtils;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
import static org.junit.Assert.assertEquals; import static org.assertj.core.api.Assertions.assertThat;
/** /**
* Basic integration tests for demo application. * Basic integration tests for demo application.
...@@ -58,8 +58,8 @@ public class SampleTomcatApplicationTests { ...@@ -58,8 +58,8 @@ public class SampleTomcatApplicationTests {
public void testHome() throws Exception { public void testHome() throws Exception {
ResponseEntity<String> entity = new TestRestTemplate() ResponseEntity<String> entity = new TestRestTemplate()
.getForEntity("http://localhost:" + this.port, String.class); .getForEntity("http://localhost:" + this.port, String.class);
assertEquals(HttpStatus.OK, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertEquals("Hello World", entity.getBody()); assertThat(entity.getBody()).isEqualTo("Hello World");
} }
@Test @Test
...@@ -71,12 +71,12 @@ public class SampleTomcatApplicationTests { ...@@ -71,12 +71,12 @@ public class SampleTomcatApplicationTests {
ResponseEntity<byte[]> entity = restTemplate.exchange( ResponseEntity<byte[]> entity = restTemplate.exchange(
"http://localhost:" + this.port, HttpMethod.GET, requestEntity, "http://localhost:" + this.port, HttpMethod.GET, requestEntity,
byte[].class); byte[].class);
assertEquals(HttpStatus.OK, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
GZIPInputStream inflater = new GZIPInputStream( GZIPInputStream inflater = new GZIPInputStream(
new ByteArrayInputStream(entity.getBody())); new ByteArrayInputStream(entity.getBody()));
try { try {
assertEquals("Hello World", assertThat(StreamUtils.copyToString(inflater, Charset.forName("UTF-8")))
StreamUtils.copyToString(inflater, Charset.forName("UTF-8"))); .isEqualTo("Hello World");
} }
finally { finally {
inflater.close(); inflater.close();
......
...@@ -28,8 +28,7 @@ import org.springframework.http.ResponseEntity; ...@@ -28,8 +28,7 @@ import org.springframework.http.ResponseEntity;
import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import static org.junit.Assert.assertEquals; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertTrue;
/** /**
* Basic integration tests for JSP application. * Basic integration tests for JSP application.
...@@ -49,9 +48,8 @@ public class SampleWebJspApplicationTests { ...@@ -49,9 +48,8 @@ public class SampleWebJspApplicationTests {
public void testJspWithEl() throws Exception { public void testJspWithEl() throws Exception {
ResponseEntity<String> entity = new TestRestTemplate() ResponseEntity<String> entity = new TestRestTemplate()
.getForEntity("http://localhost:" + this.port, String.class); .getForEntity("http://localhost:" + this.port, String.class);
assertEquals(HttpStatus.OK, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertTrue("Wrong body:\n" + entity.getBody(), assertThat(entity.getBody()).contains("/resources/text.txt");
entity.getBody().contains("/resources/text.txt"));
} }
} }
...@@ -28,8 +28,7 @@ import org.springframework.http.ResponseEntity; ...@@ -28,8 +28,7 @@ import org.springframework.http.ResponseEntity;
import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import static org.junit.Assert.assertEquals; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertTrue;
/** /**
* Basic integration tests for demo application. * Basic integration tests for demo application.
...@@ -49,20 +48,18 @@ public class SampleTraditionalApplicationTests { ...@@ -49,20 +48,18 @@ public class SampleTraditionalApplicationTests {
public void testHomeJsp() throws Exception { public void testHomeJsp() throws Exception {
ResponseEntity<String> entity = new TestRestTemplate() ResponseEntity<String> entity = new TestRestTemplate()
.getForEntity("http://localhost:" + this.port, String.class); .getForEntity("http://localhost:" + this.port, String.class);
assertEquals(HttpStatus.OK, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
String body = entity.getBody(); String body = entity.getBody();
assertTrue("Wrong body:\n" + body, body.contains("<html>")); assertThat(body).contains("<html>").contains("<h1>Home</h1>");
assertTrue("Wrong body:\n" + body, body.contains("<h1>Home</h1>"));
} }
@Test @Test
public void testStaticPage() throws Exception { public void testStaticPage() throws Exception {
ResponseEntity<String> entity = new TestRestTemplate().getForEntity( ResponseEntity<String> entity = new TestRestTemplate().getForEntity(
"http://localhost:" + this.port + "/index.html", String.class); "http://localhost:" + this.port + "/index.html", String.class);
assertEquals(HttpStatus.OK, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
String body = entity.getBody(); String body = entity.getBody();
assertTrue("Wrong body:\n" + body, body.contains("<html>")); assertThat(body).contains("<html>").contains("<h1>Hello</h1>");
assertTrue("Wrong body:\n" + body, body.contains("<h1>Hello</h1>"));
} }
} }
...@@ -34,7 +34,7 @@ import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; ...@@ -34,7 +34,7 @@ import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import static org.junit.Assert.assertEquals; import static org.assertj.core.api.Assertions.assertThat;
/** /**
* Basic integration tests for demo application. * Basic integration tests for demo application.
...@@ -64,8 +64,8 @@ public class SampleUndertowSslApplicationTests { ...@@ -64,8 +64,8 @@ public class SampleUndertowSslApplicationTests {
.setHttpClient(httpClient); .setHttpClient(httpClient);
ResponseEntity<String> entity = testRestTemplate ResponseEntity<String> entity = testRestTemplate
.getForEntity("https://localhost:" + this.port, String.class); .getForEntity("https://localhost:" + this.port, String.class);
assertEquals(HttpStatus.OK, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertEquals("Hello World", entity.getBody()); assertThat(entity.getBody()).isEqualTo("Hello World");
} }
} }
...@@ -37,7 +37,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; ...@@ -37,7 +37,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.util.StreamUtils; import org.springframework.util.StreamUtils;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
import static org.junit.Assert.assertEquals; import static org.assertj.core.api.Assertions.assertThat;
/** /**
* Basic integration tests for demo application. * Basic integration tests for demo application.
...@@ -73,12 +73,12 @@ public class SampleUndertowApplicationTests { ...@@ -73,12 +73,12 @@ public class SampleUndertowApplicationTests {
ResponseEntity<byte[]> entity = restTemplate.exchange( ResponseEntity<byte[]> entity = restTemplate.exchange(
"http://localhost:" + this.port, HttpMethod.GET, requestEntity, "http://localhost:" + this.port, HttpMethod.GET, requestEntity,
byte[].class); byte[].class);
assertEquals(HttpStatus.OK, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
GZIPInputStream inflater = new GZIPInputStream( GZIPInputStream inflater = new GZIPInputStream(
new ByteArrayInputStream(entity.getBody())); new ByteArrayInputStream(entity.getBody()));
try { try {
assertEquals("Hello World", assertThat(StreamUtils.copyToString(inflater, Charset.forName("UTF-8")))
StreamUtils.copyToString(inflater, Charset.forName("UTF-8"))); .isEqualTo("Hello World");
} }
finally { finally {
inflater.close(); inflater.close();
...@@ -88,8 +88,8 @@ public class SampleUndertowApplicationTests { ...@@ -88,8 +88,8 @@ public class SampleUndertowApplicationTests {
private void assertOkResponse(String path, String body) { private void assertOkResponse(String path, String body) {
ResponseEntity<String> entity = new TestRestTemplate() ResponseEntity<String> entity = new TestRestTemplate()
.getForEntity("http://localhost:" + this.port + path, String.class); .getForEntity("http://localhost:" + this.port + path, String.class);
assertEquals(HttpStatus.OK, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertEquals(body, entity.getBody()); assertThat(entity.getBody()).isEqualTo(body);
} }
} }
...@@ -24,7 +24,7 @@ import org.springframework.boot.test.OutputCapture; ...@@ -24,7 +24,7 @@ import org.springframework.boot.test.OutputCapture;
import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import static org.junit.Assert.assertTrue; import static org.assertj.core.api.Assertions.assertThat;
/** /**
* Basic integration tests for Velocity application with no web layer. * Basic integration tests for Velocity application with no web layer.
...@@ -41,7 +41,7 @@ public class SampleVelocityApplicationTests { ...@@ -41,7 +41,7 @@ public class SampleVelocityApplicationTests {
@Test @Test
public void testVelocityTemplate() throws Exception { public void testVelocityTemplate() throws Exception {
String result = SampleVelocityApplicationTests.output.toString(); String result = SampleVelocityApplicationTests.output.toString();
assertTrue("Wrong output: " + result, result.contains("Hello, Andy")); assertThat(result).contains("Hello, Andy");
} }
} }
...@@ -34,8 +34,7 @@ import org.springframework.http.ResponseEntity; ...@@ -34,8 +34,7 @@ import org.springframework.http.ResponseEntity;
import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import static org.junit.Assert.assertEquals; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertTrue;
/** /**
* Basic integration tests for FreeMarker application. * Basic integration tests for FreeMarker application.
...@@ -55,10 +54,9 @@ public class SampleWebFreeMarkerApplicationTests { ...@@ -55,10 +54,9 @@ public class SampleWebFreeMarkerApplicationTests {
@Test @Test
public void testFreeMarkerTemplate() throws Exception { public void testFreeMarkerTemplate() throws Exception {
ResponseEntity<String> entity = new TestRestTemplate() ResponseEntity<String> entity = new TestRestTemplate()
.getForEntity("http://localhost:" + port, String.class); .getForEntity("http://localhost:" + this.port, String.class);
assertEquals(HttpStatus.OK, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertTrue("Wrong body:\n" + entity.getBody(), assertThat(entity.getBody()).contains("Hello, Andy");
entity.getBody().contains("Hello, Andy"));
} }
@Test @Test
...@@ -68,12 +66,12 @@ public class SampleWebFreeMarkerApplicationTests { ...@@ -68,12 +66,12 @@ public class SampleWebFreeMarkerApplicationTests {
HttpEntity<String> requestEntity = new HttpEntity<String>(headers); HttpEntity<String> requestEntity = new HttpEntity<String>(headers);
ResponseEntity<String> responseEntity = new TestRestTemplate().exchange( ResponseEntity<String> responseEntity = new TestRestTemplate().exchange(
"http://localhost:" + port + "/does-not-exist", HttpMethod.GET, "http://localhost:" + this.port + "/does-not-exist", HttpMethod.GET,
requestEntity, String.class); requestEntity, String.class);
assertEquals(HttpStatus.NOT_FOUND, responseEntity.getStatusCode()); assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
assertTrue("Wrong body:\n" + responseEntity.getBody(), assertThat(responseEntity.getBody())
responseEntity.getBody().contains("Something went wrong: 404 Not Found")); .contains("Something went wrong: 404 Not Found");
} }
} }
...@@ -32,9 +32,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; ...@@ -32,9 +32,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap; import org.springframework.util.MultiValueMap;
import static org.junit.Assert.assertEquals; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
/** /**
* Basic integration tests for demo application. * Basic integration tests for demo application.
...@@ -54,11 +52,9 @@ public class SampleGroovyTemplateApplicationTests { ...@@ -54,11 +52,9 @@ public class SampleGroovyTemplateApplicationTests {
public void testHome() throws Exception { public void testHome() throws Exception {
ResponseEntity<String> entity = new TestRestTemplate() ResponseEntity<String> entity = new TestRestTemplate()
.getForEntity("http://localhost:" + this.port, String.class); .getForEntity("http://localhost:" + this.port, String.class);
assertEquals(HttpStatus.OK, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertTrue("Wrong body (title doesn't match):\n" + entity.getBody(), assertThat(entity.getBody()).contains("<title>Messages");
entity.getBody().contains("<title>Messages")); assertThat(entity.getBody()).doesNotContain("layout:fragment");
assertFalse("Wrong body (found layout:fragment):\n" + entity.getBody(),
entity.getBody().contains("layout:fragment"));
} }
@Test @Test
...@@ -68,16 +64,15 @@ public class SampleGroovyTemplateApplicationTests { ...@@ -68,16 +64,15 @@ public class SampleGroovyTemplateApplicationTests {
map.set("summary", "FOO"); map.set("summary", "FOO");
URI location = new TestRestTemplate() URI location = new TestRestTemplate()
.postForLocation("http://localhost:" + this.port, map); .postForLocation("http://localhost:" + this.port, map);
assertTrue("Wrong location:\n" + location, assertThat(location.toString()).contains("localhost:" + this.port);
location.toString().contains("localhost:" + this.port));
} }
@Test @Test
public void testCss() throws Exception { public void testCss() throws Exception {
ResponseEntity<String> entity = new TestRestTemplate().getForEntity( ResponseEntity<String> entity = new TestRestTemplate().getForEntity(
"http://localhost:" + this.port + "/css/bootstrap.min.css", String.class); "http://localhost:" + this.port + "/css/bootstrap.min.css", String.class);
assertEquals(HttpStatus.OK, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertTrue("Wrong body:\n" + entity.getBody(), entity.getBody().contains("body")); assertThat(entity.getBody()).contains("body");
} }
} }
...@@ -28,8 +28,7 @@ import org.springframework.http.ResponseEntity; ...@@ -28,8 +28,7 @@ import org.springframework.http.ResponseEntity;
import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import static org.junit.Assert.assertEquals; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertTrue;
/** /**
* Basic integration tests for JSP application. * Basic integration tests for JSP application.
...@@ -49,9 +48,8 @@ public class SampleWebJspApplicationTests { ...@@ -49,9 +48,8 @@ public class SampleWebJspApplicationTests {
public void testJspWithEl() throws Exception { public void testJspWithEl() throws Exception {
ResponseEntity<String> entity = new TestRestTemplate() ResponseEntity<String> entity = new TestRestTemplate()
.getForEntity("http://localhost:" + this.port, String.class); .getForEntity("http://localhost:" + this.port, String.class);
assertEquals(HttpStatus.OK, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertTrue("Wrong body:\n" + entity.getBody(), assertThat(entity.getBody()).contains("/resources/text.txt");
entity.getBody().contains("/resources/text.txt"));
} }
} }
...@@ -38,8 +38,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; ...@@ -38,8 +38,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap; import org.springframework.util.MultiValueMap;
import static org.junit.Assert.assertEquals; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertTrue;
/** /**
* Basic integration tests for demo application. * Basic integration tests for demo application.
...@@ -62,9 +61,8 @@ public class SampleMethodSecurityApplicationTests { ...@@ -62,9 +61,8 @@ public class SampleMethodSecurityApplicationTests {
ResponseEntity<String> entity = new TestRestTemplate().exchange( ResponseEntity<String> entity = new TestRestTemplate().exchange(
"http://localhost:" + this.port, HttpMethod.GET, "http://localhost:" + this.port, HttpMethod.GET,
new HttpEntity<Void>(headers), String.class); new HttpEntity<Void>(headers), String.class);
assertEquals(HttpStatus.OK, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertTrue("Wrong body (title doesn't match):\n" + entity.getBody(), assertThat(entity.getBody()).contains("<title>Login");
entity.getBody().contains("<title>Login"));
} }
@Test @Test
...@@ -79,9 +77,9 @@ public class SampleMethodSecurityApplicationTests { ...@@ -79,9 +77,9 @@ public class SampleMethodSecurityApplicationTests {
"http://localhost:" + this.port + "/login", HttpMethod.POST, "http://localhost:" + this.port + "/login", HttpMethod.POST,
new HttpEntity<MultiValueMap<String, String>>(form, headers), new HttpEntity<MultiValueMap<String, String>>(form, headers),
String.class); String.class);
assertEquals(HttpStatus.FOUND, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.FOUND);
assertEquals("http://localhost:" + this.port + "/", assertThat(entity.getHeaders().getLocation().toString())
entity.getHeaders().getLocation().toString()); .isEqualTo("http://localhost:" + this.port + "/");
} }
@Test @Test
...@@ -96,36 +94,35 @@ public class SampleMethodSecurityApplicationTests { ...@@ -96,36 +94,35 @@ public class SampleMethodSecurityApplicationTests {
"http://localhost:" + this.port + "/login", HttpMethod.POST, "http://localhost:" + this.port + "/login", HttpMethod.POST,
new HttpEntity<MultiValueMap<String, String>>(form, headers), new HttpEntity<MultiValueMap<String, String>>(form, headers),
String.class); String.class);
assertEquals(HttpStatus.FOUND, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.FOUND);
String cookie = entity.getHeaders().getFirst("Set-Cookie"); String cookie = entity.getHeaders().getFirst("Set-Cookie");
headers.set("Cookie", cookie); headers.set("Cookie", cookie);
ResponseEntity<String> page = new TestRestTemplate().exchange( ResponseEntity<String> page = new TestRestTemplate().exchange(
entity.getHeaders().getLocation(), HttpMethod.GET, entity.getHeaders().getLocation(), HttpMethod.GET,
new HttpEntity<Void>(headers), String.class); new HttpEntity<Void>(headers), String.class);
assertEquals(HttpStatus.FORBIDDEN, page.getStatusCode()); assertThat(page.getStatusCode()).isEqualTo(HttpStatus.FORBIDDEN);
assertTrue("Wrong body (message doesn't match):\n" + entity.getBody(), assertThat(page.getBody()).contains("Access denied");
page.getBody().contains("Access denied"));
} }
@Test @Test
public void testManagementProtected() throws Exception { public void testManagementProtected() throws Exception {
ResponseEntity<String> entity = new TestRestTemplate() ResponseEntity<String> entity = new TestRestTemplate()
.getForEntity("http://localhost:" + this.port + "/beans", String.class); .getForEntity("http://localhost:" + this.port + "/beans", String.class);
assertEquals(HttpStatus.UNAUTHORIZED, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED);
} }
@Test @Test
public void testManagementAuthorizedAccess() throws Exception { public void testManagementAuthorizedAccess() throws Exception {
ResponseEntity<String> entity = new TestRestTemplate("admin", "admin") ResponseEntity<String> entity = new TestRestTemplate("admin", "admin")
.getForEntity("http://localhost:" + this.port + "/beans", String.class); .getForEntity("http://localhost:" + this.port + "/beans", String.class);
assertEquals(HttpStatus.OK, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
} }
@Test @Test
public void testManagementUnauthorizedAccess() throws Exception { public void testManagementUnauthorizedAccess() throws Exception {
ResponseEntity<String> entity = new TestRestTemplate("user", "user") ResponseEntity<String> entity = new TestRestTemplate("user", "user")
.getForEntity("http://localhost:" + this.port + "/beans", String.class); .getForEntity("http://localhost:" + this.port + "/beans", String.class);
assertEquals(HttpStatus.FORBIDDEN, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.FORBIDDEN);
} }
private void getCsrf(MultiValueMap<String, String> form, HttpHeaders headers) { private void getCsrf(MultiValueMap<String, String> form, HttpHeaders headers) {
......
...@@ -34,8 +34,7 @@ import org.springframework.http.ResponseEntity; ...@@ -34,8 +34,7 @@ import org.springframework.http.ResponseEntity;
import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import static org.junit.Assert.assertEquals; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertTrue;
/** /**
* Basic integration tests for Mustache application. * Basic integration tests for Mustache application.
...@@ -56,9 +55,8 @@ public class SampleWebMustacheApplicationTests { ...@@ -56,9 +55,8 @@ public class SampleWebMustacheApplicationTests {
public void testMustacheTemplate() throws Exception { public void testMustacheTemplate() throws Exception {
ResponseEntity<String> entity = new TestRestTemplate() ResponseEntity<String> entity = new TestRestTemplate()
.getForEntity("http://localhost:" + this.port, String.class); .getForEntity("http://localhost:" + this.port, String.class);
assertEquals(HttpStatus.OK, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertTrue("Wrong body:\n" + entity.getBody(), assertThat(entity.getBody()).contains("Hello, Andy");
entity.getBody().contains("Hello, Andy"));
} }
@Test @Test
...@@ -71,9 +69,9 @@ public class SampleWebMustacheApplicationTests { ...@@ -71,9 +69,9 @@ public class SampleWebMustacheApplicationTests {
"http://localhost:" + this.port + "/does-not-exist", HttpMethod.GET, "http://localhost:" + this.port + "/does-not-exist", HttpMethod.GET,
requestEntity, String.class); requestEntity, String.class);
assertEquals(HttpStatus.NOT_FOUND, responseEntity.getStatusCode()); assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
assertTrue("Wrong body:\n" + responseEntity.getBody(), assertThat(responseEntity.getBody())
responseEntity.getBody().contains("Something went wrong: 404 Not Found")); .contains("Something went wrong: 404 Not Found");
} }
} }
...@@ -22,12 +22,12 @@ import java.util.regex.Pattern; ...@@ -22,12 +22,12 @@ import java.util.regex.Pattern;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.boot.test.WebIntegrationTest;
import sample.web.secure.custom.SampleWebSecureCustomApplication; import sample.web.secure.custom.SampleWebSecureCustomApplication;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.boot.test.TestRestTemplate; import org.springframework.boot.test.TestRestTemplate;
import org.springframework.boot.test.WebIntegrationTest;
import org.springframework.http.HttpEntity; import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders; import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod; import org.springframework.http.HttpMethod;
...@@ -39,9 +39,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; ...@@ -39,9 +39,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap; import org.springframework.util.MultiValueMap;
import static org.junit.Assert.assertEquals; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
/** /**
* Basic integration tests for demo application. * Basic integration tests for demo application.
...@@ -64,9 +62,9 @@ public class SampleWebSecureCustomApplicationTests { ...@@ -64,9 +62,9 @@ public class SampleWebSecureCustomApplicationTests {
ResponseEntity<String> entity = new TestRestTemplate().exchange( ResponseEntity<String> entity = new TestRestTemplate().exchange(
"http://localhost:" + this.port, HttpMethod.GET, "http://localhost:" + this.port, HttpMethod.GET,
new HttpEntity<Void>(headers), String.class); new HttpEntity<Void>(headers), String.class);
assertEquals(HttpStatus.FOUND, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.FOUND);
assertTrue("Wrong location:\n" + entity.getHeaders(), assertThat(entity.getHeaders().getLocation().toString())
entity.getHeaders().getLocation().toString().endsWith(port + "/login")); .endsWith(this.port + "/login");
} }
@Test @Test
...@@ -76,9 +74,8 @@ public class SampleWebSecureCustomApplicationTests { ...@@ -76,9 +74,8 @@ public class SampleWebSecureCustomApplicationTests {
ResponseEntity<String> entity = new TestRestTemplate().exchange( ResponseEntity<String> entity = new TestRestTemplate().exchange(
"http://localhost:" + this.port + "/login", HttpMethod.GET, "http://localhost:" + this.port + "/login", HttpMethod.GET,
new HttpEntity<Void>(headers), String.class); new HttpEntity<Void>(headers), String.class);
assertEquals(HttpStatus.OK, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertTrue("Wrong content:\n" + entity.getBody(), assertThat(entity.getBody()).contains("_csrf");
entity.getBody().contains("_csrf"));
} }
@Test @Test
...@@ -93,23 +90,22 @@ public class SampleWebSecureCustomApplicationTests { ...@@ -93,23 +90,22 @@ public class SampleWebSecureCustomApplicationTests {
"http://localhost:" + this.port + "/login", HttpMethod.POST, "http://localhost:" + this.port + "/login", HttpMethod.POST,
new HttpEntity<MultiValueMap<String, String>>(form, headers), new HttpEntity<MultiValueMap<String, String>>(form, headers),
String.class); String.class);
assertEquals(HttpStatus.FOUND, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.FOUND);
assertTrue("Wrong location:\n" + entity.getHeaders(), assertThat(entity.getHeaders().getLocation().toString())
entity.getHeaders().getLocation().toString().endsWith(port + "/")); .endsWith(this.port + "/");
assertNotNull("Missing cookie:\n" + entity.getHeaders(), assertThat(entity.getHeaders().get("Set-Cookie")).isNotNull();
entity.getHeaders().get("Set-Cookie"));
} }
private HttpHeaders getHeaders() { private HttpHeaders getHeaders() {
HttpHeaders headers = new HttpHeaders(); HttpHeaders headers = new HttpHeaders();
ResponseEntity<String> page = new TestRestTemplate() ResponseEntity<String> page = new TestRestTemplate()
.getForEntity("http://localhost:" + this.port + "/login", String.class); .getForEntity("http://localhost:" + this.port + "/login", String.class);
assertEquals(HttpStatus.OK, page.getStatusCode()); assertThat(page.getStatusCode()).isEqualTo(HttpStatus.OK);
String cookie = page.getHeaders().getFirst("Set-Cookie"); String cookie = page.getHeaders().getFirst("Set-Cookie");
headers.set("Cookie", cookie); headers.set("Cookie", cookie);
Matcher matcher = Pattern.compile("(?s).*name=\"_csrf\".*?value=\"([^\"]+).*") Pattern pattern = Pattern.compile("(?s).*name=\"_csrf\".*?value=\"([^\"]+).*");
.matcher(page.getBody()); Matcher matcher = pattern.matcher(page.getBody());
assertTrue("No csrf token: " + page.getBody(), matcher.matches()); assertThat(matcher.matches()).as(page.getBody()).isTrue();
headers.set("X-CSRF-TOKEN", matcher.group(1)); headers.set("X-CSRF-TOKEN", matcher.group(1));
return headers; return headers;
} }
...@@ -118,8 +114,8 @@ public class SampleWebSecureCustomApplicationTests { ...@@ -118,8 +114,8 @@ public class SampleWebSecureCustomApplicationTests {
public void testCss() throws Exception { public void testCss() throws Exception {
ResponseEntity<String> entity = new TestRestTemplate().getForEntity( ResponseEntity<String> entity = new TestRestTemplate().getForEntity(
"http://localhost:" + this.port + "/css/bootstrap.min.css", String.class); "http://localhost:" + this.port + "/css/bootstrap.min.css", String.class);
assertEquals(HttpStatus.OK, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertTrue("Wrong body:\n" + entity.getBody(), entity.getBody().contains("body")); assertThat(entity.getBody()).contains("body");
} }
} }
...@@ -30,10 +30,7 @@ import org.springframework.http.ResponseEntity; ...@@ -30,10 +30,7 @@ import org.springframework.http.ResponseEntity;
import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import static org.hamcrest.Matchers.equalTo; import static org.assertj.core.api.Assertions.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.startsWith;
import static org.junit.Assert.assertThat;
/** /**
* Basic integration tests for GitHub SSO application. * Basic integration tests for GitHub SSO application.
...@@ -55,9 +52,9 @@ public class SampleGithubApplicationTests { ...@@ -55,9 +52,9 @@ public class SampleGithubApplicationTests {
TestRestTemplate restTemplate = new TestRestTemplate(); TestRestTemplate restTemplate = new TestRestTemplate();
ResponseEntity<Void> entity = restTemplate ResponseEntity<Void> entity = restTemplate
.getForEntity("http://localhost:" + this.port, Void.class); .getForEntity("http://localhost:" + this.port, Void.class);
assertThat(entity.getStatusCode(), is(HttpStatus.FOUND)); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.FOUND);
assertThat(entity.getHeaders().getLocation(), assertThat(entity.getHeaders().getLocation())
is(equalTo(URI.create("http://localhost:" + this.port + "/login")))); .isEqualTo(URI.create("http://localhost:" + this.port + "/login"));
} }
@Test @Test
...@@ -65,9 +62,9 @@ public class SampleGithubApplicationTests { ...@@ -65,9 +62,9 @@ public class SampleGithubApplicationTests {
TestRestTemplate restTemplate = new TestRestTemplate(); TestRestTemplate restTemplate = new TestRestTemplate();
ResponseEntity<Void> entity = restTemplate ResponseEntity<Void> entity = restTemplate
.getForEntity("http://localhost:" + this.port + "/login", Void.class); .getForEntity("http://localhost:" + this.port + "/login", Void.class);
assertThat(entity.getStatusCode(), is(HttpStatus.FOUND)); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.FOUND);
assertThat(entity.getHeaders().getLocation().toString(), assertThat(entity.getHeaders().getLocation().toString())
startsWith("https://github.com/login/oauth")); .startsWith("https://github.com/login/oauth");
} }
} }
...@@ -38,9 +38,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; ...@@ -38,9 +38,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap; import org.springframework.util.MultiValueMap;
import static org.junit.Assert.assertEquals; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
/** /**
* Basic integration tests for demo application. * Basic integration tests for demo application.
...@@ -63,9 +61,9 @@ public class SampleWebSecureCustomApplicationTests { ...@@ -63,9 +61,9 @@ public class SampleWebSecureCustomApplicationTests {
ResponseEntity<String> entity = new TestRestTemplate().exchange( ResponseEntity<String> entity = new TestRestTemplate().exchange(
"http://localhost:" + this.port, HttpMethod.GET, "http://localhost:" + this.port, HttpMethod.GET,
new HttpEntity<Void>(headers), String.class); new HttpEntity<Void>(headers), String.class);
assertEquals(HttpStatus.FOUND, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.FOUND);
assertTrue("Wrong location:\n" + entity.getHeaders(), assertThat(entity.getHeaders().getLocation().toString())
entity.getHeaders().getLocation().toString().endsWith(port + "/login")); .endsWith(this.port + "/login");
} }
@Test @Test
...@@ -75,9 +73,8 @@ public class SampleWebSecureCustomApplicationTests { ...@@ -75,9 +73,8 @@ public class SampleWebSecureCustomApplicationTests {
ResponseEntity<String> entity = new TestRestTemplate().exchange( ResponseEntity<String> entity = new TestRestTemplate().exchange(
"http://localhost:" + this.port + "/login", HttpMethod.GET, "http://localhost:" + this.port + "/login", HttpMethod.GET,
new HttpEntity<Void>(headers), String.class); new HttpEntity<Void>(headers), String.class);
assertEquals(HttpStatus.OK, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertTrue("Wrong content:\n" + entity.getBody(), assertThat(entity.getBody()).contains("_csrf");
entity.getBody().contains("_csrf"));
} }
@Test @Test
...@@ -92,23 +89,22 @@ public class SampleWebSecureCustomApplicationTests { ...@@ -92,23 +89,22 @@ public class SampleWebSecureCustomApplicationTests {
"http://localhost:" + this.port + "/login", HttpMethod.POST, "http://localhost:" + this.port + "/login", HttpMethod.POST,
new HttpEntity<MultiValueMap<String, String>>(form, headers), new HttpEntity<MultiValueMap<String, String>>(form, headers),
String.class); String.class);
assertEquals(HttpStatus.FOUND, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.FOUND);
assertTrue("Wrong location:\n" + entity.getHeaders(), assertThat(entity.getHeaders().getLocation().toString())
entity.getHeaders().getLocation().toString().endsWith(port + "/")); .endsWith(this.port + "/");
assertNotNull("Missing cookie:\n" + entity.getHeaders(), assertThat(entity.getHeaders().get("Set-Cookie")).isNotNull();
entity.getHeaders().get("Set-Cookie"));
} }
private HttpHeaders getHeaders() { private HttpHeaders getHeaders() {
HttpHeaders headers = new HttpHeaders(); HttpHeaders headers = new HttpHeaders();
ResponseEntity<String> page = new TestRestTemplate() ResponseEntity<String> page = new TestRestTemplate()
.getForEntity("http://localhost:" + this.port + "/login", String.class); .getForEntity("http://localhost:" + this.port + "/login", String.class);
assertEquals(HttpStatus.OK, page.getStatusCode()); assertThat(page.getStatusCode()).isEqualTo(HttpStatus.OK);
String cookie = page.getHeaders().getFirst("Set-Cookie"); String cookie = page.getHeaders().getFirst("Set-Cookie");
headers.set("Cookie", cookie); headers.set("Cookie", cookie);
Matcher matcher = Pattern.compile("(?s).*name=\"_csrf\".*?value=\"([^\"]+).*") Pattern pattern = Pattern.compile("(?s).*name=\"_csrf\".*?value=\"([^\"]+).*");
.matcher(page.getBody()); Matcher matcher = pattern.matcher(page.getBody());
assertTrue("No csrf token: " + page.getBody(), matcher.matches()); assertThat(matcher.matches()).as(page.getBody()).isTrue();
headers.set("X-CSRF-TOKEN", matcher.group(1)); headers.set("X-CSRF-TOKEN", matcher.group(1));
return headers; return headers;
} }
...@@ -117,8 +113,8 @@ public class SampleWebSecureCustomApplicationTests { ...@@ -117,8 +113,8 @@ public class SampleWebSecureCustomApplicationTests {
public void testCss() throws Exception { public void testCss() throws Exception {
ResponseEntity<String> entity = new TestRestTemplate().getForEntity( ResponseEntity<String> entity = new TestRestTemplate().getForEntity(
"http://localhost:" + this.port + "/css/bootstrap.min.css", String.class); "http://localhost:" + this.port + "/css/bootstrap.min.css", String.class);
assertEquals(HttpStatus.OK, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertTrue("Wrong body:\n" + entity.getBody(), entity.getBody().contains("body")); assertThat(entity.getBody()).contains("body");
} }
} }
...@@ -38,9 +38,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; ...@@ -38,9 +38,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap; import org.springframework.util.MultiValueMap;
import static org.junit.Assert.assertEquals; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
/** /**
* Basic integration tests for demo application. * Basic integration tests for demo application.
...@@ -63,9 +61,9 @@ public class SampleSecureApplicationTests { ...@@ -63,9 +61,9 @@ public class SampleSecureApplicationTests {
ResponseEntity<String> entity = new TestRestTemplate().exchange( ResponseEntity<String> entity = new TestRestTemplate().exchange(
"http://localhost:" + this.port, HttpMethod.GET, "http://localhost:" + this.port, HttpMethod.GET,
new HttpEntity<Void>(headers), String.class); new HttpEntity<Void>(headers), String.class);
assertEquals(HttpStatus.FOUND, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.FOUND);
assertTrue("Wrong location:\n" + entity.getHeaders(), assertThat(entity.getHeaders().getLocation().toString())
entity.getHeaders().getLocation().toString().endsWith(port + "/login")); .endsWith(this.port + "/login");
} }
@Test @Test
...@@ -75,9 +73,8 @@ public class SampleSecureApplicationTests { ...@@ -75,9 +73,8 @@ public class SampleSecureApplicationTests {
ResponseEntity<String> entity = new TestRestTemplate().exchange( ResponseEntity<String> entity = new TestRestTemplate().exchange(
"http://localhost:" + this.port + "/login", HttpMethod.GET, "http://localhost:" + this.port + "/login", HttpMethod.GET,
new HttpEntity<Void>(headers), String.class); new HttpEntity<Void>(headers), String.class);
assertEquals(HttpStatus.OK, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertTrue("Wrong content:\n" + entity.getBody(), assertThat(entity.getBody()).contains("_csrf");
entity.getBody().contains("_csrf"));
} }
@Test @Test
...@@ -92,23 +89,22 @@ public class SampleSecureApplicationTests { ...@@ -92,23 +89,22 @@ public class SampleSecureApplicationTests {
"http://localhost:" + this.port + "/login", HttpMethod.POST, "http://localhost:" + this.port + "/login", HttpMethod.POST,
new HttpEntity<MultiValueMap<String, String>>(form, headers), new HttpEntity<MultiValueMap<String, String>>(form, headers),
String.class); String.class);
assertEquals(HttpStatus.FOUND, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.FOUND);
assertTrue("Wrong location:\n" + entity.getHeaders(), assertThat(entity.getHeaders().getLocation().toString())
entity.getHeaders().getLocation().toString().endsWith(port + "/")); .endsWith(this.port + "/");
assertNotNull("Missing cookie:\n" + entity.getHeaders(), assertThat(entity.getHeaders().get("Set-Cookie")).isNotNull();
entity.getHeaders().get("Set-Cookie"));
} }
private HttpHeaders getHeaders() { private HttpHeaders getHeaders() {
HttpHeaders headers = new HttpHeaders(); HttpHeaders headers = new HttpHeaders();
ResponseEntity<String> page = new TestRestTemplate() ResponseEntity<String> page = new TestRestTemplate()
.getForEntity("http://localhost:" + this.port + "/login", String.class); .getForEntity("http://localhost:" + this.port + "/login", String.class);
assertEquals(HttpStatus.OK, page.getStatusCode()); assertThat(page.getStatusCode()).isEqualTo(HttpStatus.OK);
String cookie = page.getHeaders().getFirst("Set-Cookie"); String cookie = page.getHeaders().getFirst("Set-Cookie");
headers.set("Cookie", cookie); headers.set("Cookie", cookie);
Matcher matcher = Pattern.compile("(?s).*name=\"_csrf\".*?value=\"([^\"]+).*") Pattern pattern = Pattern.compile("(?s).*name=\"_csrf\".*?value=\"([^\"]+).*");
.matcher(page.getBody()); Matcher matcher = pattern.matcher(page.getBody());
assertTrue("No csrf token: " + page.getBody(), matcher.matches()); assertThat(matcher.matches()).as(page.getBody()).isTrue();
headers.set("X-CSRF-TOKEN", matcher.group(1)); headers.set("X-CSRF-TOKEN", matcher.group(1));
return headers; return headers;
} }
...@@ -117,8 +113,8 @@ public class SampleSecureApplicationTests { ...@@ -117,8 +113,8 @@ public class SampleSecureApplicationTests {
public void testCss() throws Exception { public void testCss() throws Exception {
ResponseEntity<String> entity = new TestRestTemplate().getForEntity( ResponseEntity<String> entity = new TestRestTemplate().getForEntity(
"http://localhost:" + this.port + "/css/bootstrap.min.css", String.class); "http://localhost:" + this.port + "/css/bootstrap.min.css", String.class);
assertEquals(HttpStatus.OK, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertTrue("Wrong body:\n" + entity.getBody(), entity.getBody().contains("body")); assertThat(entity.getBody()).contains("body");
} }
} }
...@@ -18,20 +18,19 @@ package sample.webstatic; ...@@ -18,20 +18,19 @@ package sample.webstatic;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.boot.test.WebIntegrationTest;
import sample.web.staticcontent.SampleWebStaticApplication; import sample.web.staticcontent.SampleWebStaticApplication;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.boot.test.TestRestTemplate; import org.springframework.boot.test.TestRestTemplate;
import org.springframework.boot.test.WebIntegrationTest;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import static org.junit.Assert.assertEquals; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertTrue;
/** /**
* Basic integration tests for demo application. * Basic integration tests for demo application.
...@@ -51,9 +50,8 @@ public class SampleWebStaticApplicationTests { ...@@ -51,9 +50,8 @@ public class SampleWebStaticApplicationTests {
public void testHome() throws Exception { public void testHome() throws Exception {
ResponseEntity<String> entity = new TestRestTemplate() ResponseEntity<String> entity = new TestRestTemplate()
.getForEntity("http://localhost:" + this.port, String.class); .getForEntity("http://localhost:" + this.port, String.class);
assertEquals(HttpStatus.OK, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertTrue("Wrong body (title doesn't match):\n" + entity.getBody(), assertThat(entity.getBody()).contains("<title>Static");
entity.getBody().contains("<title>Static"));
} }
@Test @Test
...@@ -63,11 +61,10 @@ public class SampleWebStaticApplicationTests { ...@@ -63,11 +61,10 @@ public class SampleWebStaticApplicationTests {
"http://localhost:" + this.port "http://localhost:" + this.port
+ "/webjars/bootstrap/3.0.3/css/bootstrap.min.css", + "/webjars/bootstrap/3.0.3/css/bootstrap.min.css",
String.class); String.class);
assertEquals(HttpStatus.OK, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertTrue("Wrong body:\n" + entity.getBody(), entity.getBody().contains("body")); assertThat(entity.getBody()).contains("body");
assertEquals("Wrong content type:\n" + entity.getHeaders().getContentType(), assertThat(entity.getHeaders().getContentType())
MediaType.valueOf("text/css;charset=UTF-8"), .isEqualTo(MediaType.valueOf("text/css;charset=UTF-8"));
entity.getHeaders().getContentType());
} }
} }
...@@ -20,12 +20,12 @@ import java.net.URI; ...@@ -20,12 +20,12 @@ import java.net.URI;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.boot.test.WebIntegrationTest;
import sample.web.ui.SampleWebUiApplication; import sample.web.ui.SampleWebUiApplication;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.boot.test.TestRestTemplate; import org.springframework.boot.test.TestRestTemplate;
import org.springframework.boot.test.WebIntegrationTest;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.annotation.DirtiesContext;
...@@ -33,9 +33,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; ...@@ -33,9 +33,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap; import org.springframework.util.MultiValueMap;
import static org.junit.Assert.assertEquals; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
/** /**
* Basic integration tests for demo application. * Basic integration tests for demo application.
...@@ -55,11 +53,9 @@ public class SampleWebUiApplicationTests { ...@@ -55,11 +53,9 @@ public class SampleWebUiApplicationTests {
public void testHome() throws Exception { public void testHome() throws Exception {
ResponseEntity<String> entity = new TestRestTemplate() ResponseEntity<String> entity = new TestRestTemplate()
.getForEntity("http://localhost:" + this.port, String.class); .getForEntity("http://localhost:" + this.port, String.class);
assertEquals(HttpStatus.OK, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertTrue("Wrong body (title doesn't match):\n" + entity.getBody(), assertThat(entity.getBody()).contains("<title>Messages");
entity.getBody().contains("<title>Messages")); assertThat(entity.getBody()).doesNotContain("layout:fragment");
assertFalse("Wrong body (found layout:fragment):\n" + entity.getBody(),
entity.getBody().contains("layout:fragment"));
} }
@Test @Test
...@@ -69,16 +65,15 @@ public class SampleWebUiApplicationTests { ...@@ -69,16 +65,15 @@ public class SampleWebUiApplicationTests {
map.set("summary", "FOO"); map.set("summary", "FOO");
URI location = new TestRestTemplate() URI location = new TestRestTemplate()
.postForLocation("http://localhost:" + this.port, map); .postForLocation("http://localhost:" + this.port, map);
assertTrue("Wrong location:\n" + location, assertThat(location.toString()).contains("localhost:" + this.port);
location.toString().contains("localhost:" + this.port));
} }
@Test @Test
public void testCss() throws Exception { public void testCss() throws Exception {
ResponseEntity<String> entity = new TestRestTemplate().getForEntity( ResponseEntity<String> entity = new TestRestTemplate().getForEntity(
"http://localhost:" + this.port + "/css/bootstrap.min.css", String.class); "http://localhost:" + this.port + "/css/bootstrap.min.css", String.class);
assertEquals(HttpStatus.OK, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertTrue("Wrong body:\n" + entity.getBody(), entity.getBody().contains("body")); assertThat(entity.getBody()).contains("body");
} }
} }
...@@ -34,8 +34,7 @@ import org.springframework.http.ResponseEntity; ...@@ -34,8 +34,7 @@ import org.springframework.http.ResponseEntity;
import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import static org.junit.Assert.assertEquals; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertTrue;
/** /**
* Basic integration tests for Velocity application. * Basic integration tests for Velocity application.
...@@ -56,9 +55,8 @@ public class SampleWebVelocityApplicationTests { ...@@ -56,9 +55,8 @@ public class SampleWebVelocityApplicationTests {
public void testVelocityTemplate() throws Exception { public void testVelocityTemplate() throws Exception {
ResponseEntity<String> entity = new TestRestTemplate() ResponseEntity<String> entity = new TestRestTemplate()
.getForEntity("http://localhost:" + this.port, String.class); .getForEntity("http://localhost:" + this.port, String.class);
assertEquals(HttpStatus.OK, entity.getStatusCode()); assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertTrue("Wrong body:\n" + entity.getBody(), assertThat(entity.getBody()).contains("Hello, Andy");
entity.getBody().contains("Hello, Andy"));
} }
@Test @Test
...@@ -71,9 +69,9 @@ public class SampleWebVelocityApplicationTests { ...@@ -71,9 +69,9 @@ public class SampleWebVelocityApplicationTests {
"http://localhost:" + this.port + "/does-not-exist", HttpMethod.GET, "http://localhost:" + this.port + "/does-not-exist", HttpMethod.GET,
requestEntity, String.class); requestEntity, String.class);
assertEquals(HttpStatus.NOT_FOUND, responseEntity.getStatusCode()); assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND);
assertTrue("Wrong body:\n" + responseEntity.getBody(), assertThat(responseEntity.getBody())
responseEntity.getBody().contains("Something went wrong: 404 Not Found")); .contains("Something went wrong: 404 Not Found");
} }
} }
...@@ -24,7 +24,6 @@ import org.apache.commons.logging.Log; ...@@ -24,7 +24,6 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.boot.test.WebIntegrationTest;
import samples.websocket.jetty.client.GreetingService; import samples.websocket.jetty.client.GreetingService;
import samples.websocket.jetty.client.SimpleClientWebSocketHandler; import samples.websocket.jetty.client.SimpleClientWebSocketHandler;
import samples.websocket.jetty.client.SimpleGreetingService; import samples.websocket.jetty.client.SimpleGreetingService;
...@@ -34,6 +33,7 @@ import org.springframework.boot.CommandLineRunner; ...@@ -34,6 +33,7 @@ import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.boot.test.WebIntegrationTest;
import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
...@@ -42,7 +42,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; ...@@ -42,7 +42,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.web.socket.client.WebSocketConnectionManager; import org.springframework.web.socket.client.WebSocketConnectionManager;
import org.springframework.web.socket.client.standard.StandardWebSocketClient; import org.springframework.web.socket.client.standard.StandardWebSocketClient;
import static org.junit.Assert.assertEquals; import static org.assertj.core.api.Assertions.assertThat;
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(SampleJettyWebSocketsApplication.class) @SpringApplicationConfiguration(SampleJettyWebSocketsApplication.class)
...@@ -66,8 +66,9 @@ public class SampleWebSocketsApplicationTests { ...@@ -66,8 +66,9 @@ public class SampleWebSocketsApplicationTests {
AtomicReference<String> messagePayloadReference = context AtomicReference<String> messagePayloadReference = context
.getBean(ClientConfiguration.class).messagePayload; .getBean(ClientConfiguration.class).messagePayload;
context.close(); context.close();
assertEquals(0, count); assertThat(count).isEqualTo(0);
assertEquals("Did you say \"Hello world!\"?", messagePayloadReference.get()); assertThat(messagePayloadReference.get())
.isEqualTo("Did you say \"Hello world!\"?");
} }
@Test @Test
...@@ -81,8 +82,8 @@ public class SampleWebSocketsApplicationTests { ...@@ -81,8 +82,8 @@ public class SampleWebSocketsApplicationTests {
AtomicReference<String> messagePayloadReference = context AtomicReference<String> messagePayloadReference = context
.getBean(ClientConfiguration.class).messagePayload; .getBean(ClientConfiguration.class).messagePayload;
context.close(); context.close();
assertEquals(0, count); assertThat(count).isEqualTo(0);
assertEquals("Reversed: !dlrow olleH", messagePayloadReference.get()); assertThat(messagePayloadReference.get()).isEqualTo("Reversed: !dlrow olleH");
} }
@Configuration @Configuration
......
...@@ -24,7 +24,6 @@ import org.apache.commons.logging.Log; ...@@ -24,7 +24,6 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.boot.test.WebIntegrationTest;
import samples.websocket.jetty.SampleJettyWebSocketsApplication; import samples.websocket.jetty.SampleJettyWebSocketsApplication;
import samples.websocket.jetty.client.GreetingService; import samples.websocket.jetty.client.GreetingService;
import samples.websocket.jetty.client.SimpleClientWebSocketHandler; import samples.websocket.jetty.client.SimpleClientWebSocketHandler;
...@@ -38,6 +37,7 @@ import org.springframework.boot.builder.SpringApplicationBuilder; ...@@ -38,6 +37,7 @@ import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory; import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory;
import org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainerFactory; import org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainerFactory;
import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.boot.test.WebIntegrationTest;
import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
...@@ -47,7 +47,7 @@ import org.springframework.util.SocketUtils; ...@@ -47,7 +47,7 @@ import org.springframework.util.SocketUtils;
import org.springframework.web.socket.client.WebSocketConnectionManager; import org.springframework.web.socket.client.WebSocketConnectionManager;
import org.springframework.web.socket.client.standard.StandardWebSocketClient; import org.springframework.web.socket.client.standard.StandardWebSocketClient;
import static org.junit.Assert.assertEquals; import static org.assertj.core.api.Assertions.assertThat;
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration({ SampleJettyWebSocketsApplication.class, @SpringApplicationConfiguration({ SampleJettyWebSocketsApplication.class,
...@@ -72,8 +72,9 @@ public class CustomContainerWebSocketsApplicationTests { ...@@ -72,8 +72,9 @@ public class CustomContainerWebSocketsApplicationTests {
AtomicReference<String> messagePayloadReference = context AtomicReference<String> messagePayloadReference = context
.getBean(ClientConfiguration.class).messagePayload; .getBean(ClientConfiguration.class).messagePayload;
context.close(); context.close();
assertEquals(0, count); assertThat(count).isEqualTo(0);
assertEquals("Did you say \"Hello world!\"?", messagePayloadReference.get()); assertThat(messagePayloadReference.get())
.isEqualTo("Did you say \"Hello world!\"?");
} }
@Test @Test
...@@ -87,8 +88,8 @@ public class CustomContainerWebSocketsApplicationTests { ...@@ -87,8 +88,8 @@ public class CustomContainerWebSocketsApplicationTests {
AtomicReference<String> messagePayloadReference = context AtomicReference<String> messagePayloadReference = context
.getBean(ClientConfiguration.class).messagePayload; .getBean(ClientConfiguration.class).messagePayload;
context.close(); context.close();
assertEquals(0, count); assertThat(count).isEqualTo(0);
assertEquals("Reversed: !dlrow olleH", messagePayloadReference.get()); assertThat(messagePayloadReference.get()).isEqualTo("Reversed: !dlrow olleH");
} }
@Configuration @Configuration
......
...@@ -20,8 +20,7 @@ import java.io.IOException; ...@@ -20,8 +20,7 @@ import java.io.IOException;
import org.junit.Test; import org.junit.Test;
import static org.hamcrest.CoreMatchers.is; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertThat;
import static org.mockito.BDDMockito.willThrow; import static org.mockito.BDDMockito.willThrow;
import static org.mockito.Matchers.anyString; import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
...@@ -35,7 +34,7 @@ public class SnakeTimerTests { ...@@ -35,7 +34,7 @@ public class SnakeTimerTests {
SnakeTimer.addSnake(snake); SnakeTimer.addSnake(snake);
SnakeTimer.broadcast(""); SnakeTimer.broadcast("");
assertThat(SnakeTimer.getSnakes().size(), is(0)); assertThat(SnakeTimer.getSnakes()).hasSize(0);
} }
} }
...@@ -24,7 +24,6 @@ import org.apache.commons.logging.Log; ...@@ -24,7 +24,6 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.boot.test.WebIntegrationTest;
import samples.websocket.tomcat.client.GreetingService; import samples.websocket.tomcat.client.GreetingService;
import samples.websocket.tomcat.client.SimpleClientWebSocketHandler; import samples.websocket.tomcat.client.SimpleClientWebSocketHandler;
import samples.websocket.tomcat.client.SimpleGreetingService; import samples.websocket.tomcat.client.SimpleGreetingService;
...@@ -34,6 +33,7 @@ import org.springframework.boot.CommandLineRunner; ...@@ -34,6 +33,7 @@ import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.boot.test.WebIntegrationTest;
import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
...@@ -42,7 +42,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; ...@@ -42,7 +42,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.web.socket.client.WebSocketConnectionManager; import org.springframework.web.socket.client.WebSocketConnectionManager;
import org.springframework.web.socket.client.standard.StandardWebSocketClient; import org.springframework.web.socket.client.standard.StandardWebSocketClient;
import static org.junit.Assert.assertEquals; import static org.assertj.core.api.Assertions.assertThat;
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(SampleTomcatWebSocketApplication.class) @SpringApplicationConfiguration(SampleTomcatWebSocketApplication.class)
...@@ -66,8 +66,9 @@ public class SampleWebSocketsApplicationTests { ...@@ -66,8 +66,9 @@ public class SampleWebSocketsApplicationTests {
AtomicReference<String> messagePayloadReference = context AtomicReference<String> messagePayloadReference = context
.getBean(ClientConfiguration.class).messagePayload; .getBean(ClientConfiguration.class).messagePayload;
context.close(); context.close();
assertEquals(0, count); assertThat(count).isEqualTo(0);
assertEquals("Did you say \"Hello world!\"?", messagePayloadReference.get()); assertThat(messagePayloadReference.get())
.isEqualTo("Did you say \"Hello world!\"?");
} }
@Test @Test
...@@ -81,8 +82,8 @@ public class SampleWebSocketsApplicationTests { ...@@ -81,8 +82,8 @@ public class SampleWebSocketsApplicationTests {
AtomicReference<String> messagePayloadReference = context AtomicReference<String> messagePayloadReference = context
.getBean(ClientConfiguration.class).messagePayload; .getBean(ClientConfiguration.class).messagePayload;
context.close(); context.close();
assertEquals(0, count); assertThat(count).isEqualTo(0);
assertEquals("Reversed: !dlrow olleH", messagePayloadReference.get()); assertThat(messagePayloadReference.get()).isEqualTo("Reversed: !dlrow olleH");
} }
@Configuration @Configuration
......
...@@ -24,7 +24,6 @@ import org.apache.commons.logging.Log; ...@@ -24,7 +24,6 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.boot.test.WebIntegrationTest;
import samples.websocket.tomcat.SampleTomcatWebSocketApplication; import samples.websocket.tomcat.SampleTomcatWebSocketApplication;
import samples.websocket.tomcat.client.GreetingService; import samples.websocket.tomcat.client.GreetingService;
import samples.websocket.tomcat.client.SimpleClientWebSocketHandler; import samples.websocket.tomcat.client.SimpleClientWebSocketHandler;
...@@ -38,6 +37,7 @@ import org.springframework.boot.builder.SpringApplicationBuilder; ...@@ -38,6 +37,7 @@ import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory; import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory;
import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory; import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory;
import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.boot.test.WebIntegrationTest;
import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
...@@ -47,7 +47,7 @@ import org.springframework.util.SocketUtils; ...@@ -47,7 +47,7 @@ import org.springframework.util.SocketUtils;
import org.springframework.web.socket.client.WebSocketConnectionManager; import org.springframework.web.socket.client.WebSocketConnectionManager;
import org.springframework.web.socket.client.standard.StandardWebSocketClient; import org.springframework.web.socket.client.standard.StandardWebSocketClient;
import static org.junit.Assert.assertEquals; import static org.assertj.core.api.Assertions.assertThat;
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration({ SampleTomcatWebSocketApplication.class, @SpringApplicationConfiguration({ SampleTomcatWebSocketApplication.class,
...@@ -72,8 +72,9 @@ public class CustomContainerWebSocketsApplicationTests { ...@@ -72,8 +72,9 @@ public class CustomContainerWebSocketsApplicationTests {
AtomicReference<String> messagePayloadReference = context AtomicReference<String> messagePayloadReference = context
.getBean(ClientConfiguration.class).messagePayload; .getBean(ClientConfiguration.class).messagePayload;
context.close(); context.close();
assertEquals(0, count); assertThat(count).isEqualTo(0);
assertEquals("Did you say \"Hello world!\"?", messagePayloadReference.get()); assertThat(messagePayloadReference.get())
.isEqualTo("Did you say \"Hello world!\"?");
} }
@Test @Test
...@@ -87,8 +88,8 @@ public class CustomContainerWebSocketsApplicationTests { ...@@ -87,8 +88,8 @@ public class CustomContainerWebSocketsApplicationTests {
AtomicReference<String> messagePayloadReference = context AtomicReference<String> messagePayloadReference = context
.getBean(ClientConfiguration.class).messagePayload; .getBean(ClientConfiguration.class).messagePayload;
context.close(); context.close();
assertEquals(0, count); assertThat(count).isEqualTo(0);
assertEquals("Reversed: !dlrow olleH", messagePayloadReference.get()); assertThat(messagePayloadReference.get()).isEqualTo("Reversed: !dlrow olleH");
} }
@Configuration @Configuration
......
...@@ -20,8 +20,7 @@ import java.io.IOException; ...@@ -20,8 +20,7 @@ import java.io.IOException;
import org.junit.Test; import org.junit.Test;
import static org.hamcrest.CoreMatchers.is; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertThat;
import static org.mockito.BDDMockito.willThrow; import static org.mockito.BDDMockito.willThrow;
import static org.mockito.Matchers.anyString; import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
...@@ -35,6 +34,6 @@ public class SnakeTimerTests { ...@@ -35,6 +34,6 @@ public class SnakeTimerTests {
SnakeTimer.addSnake(snake); SnakeTimer.addSnake(snake);
SnakeTimer.broadcast(""); SnakeTimer.broadcast("");
assertThat(SnakeTimer.getSnakes().size(), is(0)); assertThat(SnakeTimer.getSnakes()).hasSize(0);
} }
} }
...@@ -24,7 +24,6 @@ import org.apache.commons.logging.Log; ...@@ -24,7 +24,6 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.boot.test.WebIntegrationTest;
import samples.websocket.undertow.client.GreetingService; import samples.websocket.undertow.client.GreetingService;
import samples.websocket.undertow.client.SimpleClientWebSocketHandler; import samples.websocket.undertow.client.SimpleClientWebSocketHandler;
import samples.websocket.undertow.client.SimpleGreetingService; import samples.websocket.undertow.client.SimpleGreetingService;
...@@ -34,6 +33,7 @@ import org.springframework.boot.CommandLineRunner; ...@@ -34,6 +33,7 @@ import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration;
import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.boot.test.WebIntegrationTest;
import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
...@@ -42,7 +42,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; ...@@ -42,7 +42,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.web.socket.client.WebSocketConnectionManager; import org.springframework.web.socket.client.WebSocketConnectionManager;
import org.springframework.web.socket.client.standard.StandardWebSocketClient; import org.springframework.web.socket.client.standard.StandardWebSocketClient;
import static org.junit.Assert.assertEquals; import static org.assertj.core.api.Assertions.assertThat;
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(SampleUndertowWebSocketsApplication.class) @SpringApplicationConfiguration(SampleUndertowWebSocketsApplication.class)
...@@ -66,8 +66,9 @@ public class SampleWebSocketsApplicationTests { ...@@ -66,8 +66,9 @@ public class SampleWebSocketsApplicationTests {
AtomicReference<String> messagePayloadReference = context AtomicReference<String> messagePayloadReference = context
.getBean(ClientConfiguration.class).messagePayload; .getBean(ClientConfiguration.class).messagePayload;
context.close(); context.close();
assertEquals(0, count); assertThat(count).isEqualTo(0);
assertEquals("Did you say \"Hello world!\"?", messagePayloadReference.get()); assertThat(messagePayloadReference.get())
.isEqualTo("Did you say \"Hello world!\"?");
} }
@Test @Test
...@@ -81,8 +82,8 @@ public class SampleWebSocketsApplicationTests { ...@@ -81,8 +82,8 @@ public class SampleWebSocketsApplicationTests {
AtomicReference<String> messagePayloadReference = context AtomicReference<String> messagePayloadReference = context
.getBean(ClientConfiguration.class).messagePayload; .getBean(ClientConfiguration.class).messagePayload;
context.close(); context.close();
assertEquals(0, count); assertThat(count).isEqualTo(0);
assertEquals("Reversed: !dlrow olleH", messagePayloadReference.get()); assertThat(messagePayloadReference.get()).isEqualTo("Reversed: !dlrow olleH");
} }
@Configuration @Configuration
......
...@@ -24,7 +24,6 @@ import org.apache.commons.logging.Log; ...@@ -24,7 +24,6 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.boot.test.WebIntegrationTest;
import samples.websocket.undertow.SampleUndertowWebSocketsApplication; import samples.websocket.undertow.SampleUndertowWebSocketsApplication;
import samples.websocket.undertow.client.GreetingService; import samples.websocket.undertow.client.GreetingService;
import samples.websocket.undertow.client.SimpleClientWebSocketHandler; import samples.websocket.undertow.client.SimpleClientWebSocketHandler;
...@@ -38,6 +37,7 @@ import org.springframework.boot.builder.SpringApplicationBuilder; ...@@ -38,6 +37,7 @@ import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory; import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory;
import org.springframework.boot.context.embedded.undertow.UndertowEmbeddedServletContainerFactory; import org.springframework.boot.context.embedded.undertow.UndertowEmbeddedServletContainerFactory;
import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.boot.test.WebIntegrationTest;
import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
...@@ -47,7 +47,7 @@ import org.springframework.util.SocketUtils; ...@@ -47,7 +47,7 @@ import org.springframework.util.SocketUtils;
import org.springframework.web.socket.client.WebSocketConnectionManager; import org.springframework.web.socket.client.WebSocketConnectionManager;
import org.springframework.web.socket.client.standard.StandardWebSocketClient; import org.springframework.web.socket.client.standard.StandardWebSocketClient;
import static org.junit.Assert.assertEquals; import static org.assertj.core.api.Assertions.assertThat;
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration({ SampleUndertowWebSocketsApplication.class, @SpringApplicationConfiguration({ SampleUndertowWebSocketsApplication.class,
...@@ -72,8 +72,9 @@ public class CustomContainerWebSocketsApplicationTests { ...@@ -72,8 +72,9 @@ public class CustomContainerWebSocketsApplicationTests {
AtomicReference<String> messagePayloadReference = context AtomicReference<String> messagePayloadReference = context
.getBean(ClientConfiguration.class).messagePayload; .getBean(ClientConfiguration.class).messagePayload;
context.close(); context.close();
assertEquals(0, count); assertThat(count).isEqualTo(0);
assertEquals("Did you say \"Hello world!\"?", messagePayloadReference.get()); assertThat(messagePayloadReference.get())
.isEqualTo("Did you say \"Hello world!\"?");
} }
@Test @Test
...@@ -87,8 +88,8 @@ public class CustomContainerWebSocketsApplicationTests { ...@@ -87,8 +88,8 @@ public class CustomContainerWebSocketsApplicationTests {
AtomicReference<String> messagePayloadReference = context AtomicReference<String> messagePayloadReference = context
.getBean(ClientConfiguration.class).messagePayload; .getBean(ClientConfiguration.class).messagePayload;
context.close(); context.close();
assertEquals(0, count); assertThat(count).isEqualTo(0);
assertEquals("Reversed: !dlrow olleH", messagePayloadReference.get()); assertThat(messagePayloadReference.get()).isEqualTo("Reversed: !dlrow olleH");
} }
@Configuration @Configuration
......
...@@ -20,8 +20,7 @@ import java.io.IOException; ...@@ -20,8 +20,7 @@ import java.io.IOException;
import org.junit.Test; import org.junit.Test;
import static org.hamcrest.CoreMatchers.is; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertThat;
import static org.mockito.BDDMockito.willThrow; import static org.mockito.BDDMockito.willThrow;
import static org.mockito.Matchers.anyString; import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
...@@ -35,6 +34,6 @@ public class SnakeTimerTests { ...@@ -35,6 +34,6 @@ public class SnakeTimerTests {
SnakeTimer.addSnake(snake); SnakeTimer.addSnake(snake);
SnakeTimer.broadcast(""); SnakeTimer.broadcast("");
assertThat(SnakeTimer.getSnakes().size(), is(0)); assertThat(SnakeTimer.getSnakes()).hasSize(0);
} }
} }
...@@ -32,8 +32,7 @@ import org.springframework.boot.test.WebIntegrationTest; ...@@ -32,8 +32,7 @@ import org.springframework.boot.test.WebIntegrationTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.ws.client.core.WebServiceTemplate; import org.springframework.ws.client.core.WebServiceTemplate;
import static org.hamcrest.Matchers.containsString; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertThat;
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(SampleWsApplication.class) @SpringApplicationConfiguration(SampleWsApplication.class)
...@@ -68,7 +67,7 @@ public class SampleWsApplicationTests { ...@@ -68,7 +67,7 @@ public class SampleWsApplicationTests {
StreamResult result = new StreamResult(System.out); StreamResult result = new StreamResult(System.out);
this.webServiceTemplate.sendSourceAndReceiveToResult(source, result); this.webServiceTemplate.sendSourceAndReceiveToResult(source, result);
assertThat(this.output.toString(), containsString("Booking holiday for")); assertThat(this.output.toString()).contains("Booking holiday for");
} }
} }
...@@ -21,7 +21,7 @@ import org.junit.Test; ...@@ -21,7 +21,7 @@ import org.junit.Test;
import org.springframework.boot.test.OutputCapture; import org.springframework.boot.test.OutputCapture;
import static org.junit.Assert.assertTrue; import static org.assertj.core.api.Assertions.assertThat;
public class SampleSpringXmlApplicationTests { public class SampleSpringXmlApplicationTests {
...@@ -32,7 +32,7 @@ public class SampleSpringXmlApplicationTests { ...@@ -32,7 +32,7 @@ public class SampleSpringXmlApplicationTests {
public void testDefaultSettings() throws Exception { public void testDefaultSettings() throws Exception {
SampleSpringXmlApplication.main(new String[0]); SampleSpringXmlApplication.main(new String[0]);
String output = this.outputCapture.toString(); String output = this.outputCapture.toString();
assertTrue("Wrong output: " + output, output.contains("Hello World")); assertThat(output).contains("Hello World");
} }
} }
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