diff --git a/spring-boot-samples/spring-boot-sample-activemq/src/test/java/sample/activemq/SampleActiveMqTests.java b/spring-boot-samples/spring-boot-sample-activemq/src/test/java/sample/activemq/SampleActiveMqTests.java index b96cfe6115..a89ac1aaaa 100644 --- a/spring-boot-samples/spring-boot-sample-activemq/src/test/java/sample/activemq/SampleActiveMqTests.java +++ b/spring-boot-samples/spring-boot-sample-activemq/src/test/java/sample/activemq/SampleActiveMqTests.java @@ -27,7 +27,7 @@ import org.springframework.boot.test.OutputCapture; import org.springframework.boot.test.SpringApplicationConfiguration; 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. @@ -48,7 +48,7 @@ public class SampleActiveMqTests { public void sendSimpleMessage() throws InterruptedException, JMSException { this.producer.send("Test message"); Thread.sleep(1000L); - assertTrue(this.outputCapture.toString().contains("Test message")); + assertThat(this.outputCapture.toString().contains("Test message")).isTrue(); } } diff --git a/spring-boot-samples/spring-boot-sample-actuator-log4j2/src/test/java/sample/actuator/log4j2/SampleActuatorApplicationTests.java b/spring-boot-samples/spring-boot-sample-actuator-log4j2/src/test/java/sample/actuator/log4j2/SampleActuatorApplicationTests.java index d7c71bdeb6..a6e4381951 100644 --- a/spring-boot-samples/spring-boot-sample-actuator-log4j2/src/test/java/sample/actuator/log4j2/SampleActuatorApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-actuator-log4j2/src/test/java/sample/actuator/log4j2/SampleActuatorApplicationTests.java @@ -30,7 +30,7 @@ import org.springframework.http.ResponseEntity; import org.springframework.test.annotation.DirtiesContext; 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. @@ -51,10 +51,10 @@ public class SampleActuatorApplicationTests { @SuppressWarnings("rawtypes") ResponseEntity entity = new TestRestTemplate() .getForEntity("http://localhost:" + port, Map.class); - assertEquals(HttpStatus.OK, entity.getStatusCode()); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); @SuppressWarnings("unchecked") Map body = entity.getBody(); - assertEquals("Hello Daniel", body.get("message")); + assertThat(body.get("message")).isEqualTo("Hello Daniel"); } } diff --git a/spring-boot-samples/spring-boot-sample-actuator-noweb/src/test/java/sample/actuator/noweb/SampleActuatorNoWebApplicationTests.java b/spring-boot-samples/spring-boot-sample-actuator-noweb/src/test/java/sample/actuator/noweb/SampleActuatorNoWebApplicationTests.java index 9b47c1ace0..4bffcc648f 100644 --- a/spring-boot-samples/spring-boot-sample-actuator-noweb/src/test/java/sample/actuator/noweb/SampleActuatorNoWebApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-actuator-noweb/src/test/java/sample/actuator/noweb/SampleActuatorNoWebApplicationTests.java @@ -25,7 +25,7 @@ import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.test.annotation.DirtiesContext; 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. @@ -42,7 +42,7 @@ public class SampleActuatorNoWebApplicationTests { @Test public void endpointsExist() throws Exception { - assertNotNull(this.endpoint); + assertThat(this.endpoint).isNotNull(); } } diff --git a/spring-boot-samples/spring-boot-sample-actuator-ui/src/test/java/sample/actuator/ui/SampleActuatorUiApplicationPortTests.java b/spring-boot-samples/spring-boot-sample-actuator-ui/src/test/java/sample/actuator/ui/SampleActuatorUiApplicationPortTests.java index b930a18d1c..0f2460b846 100644 --- a/spring-boot-samples/spring-boot-sample-actuator-ui/src/test/java/sample/actuator/ui/SampleActuatorUiApplicationPortTests.java +++ b/spring-boot-samples/spring-boot-sample-actuator-ui/src/test/java/sample/actuator/ui/SampleActuatorUiApplicationPortTests.java @@ -30,7 +30,7 @@ import org.springframework.http.ResponseEntity; import org.springframework.test.annotation.DirtiesContext; 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. @@ -53,7 +53,7 @@ public class SampleActuatorUiApplicationPortTests { public void testHome() throws Exception { ResponseEntity entity = new TestRestTemplate() .getForEntity("http://localhost:" + this.port, String.class); - assertEquals(HttpStatus.OK, entity.getStatusCode()); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); } @Test @@ -61,15 +61,15 @@ public class SampleActuatorUiApplicationPortTests { @SuppressWarnings("rawtypes") ResponseEntity entity = new TestRestTemplate().getForEntity( "http://localhost:" + this.managementPort + "/metrics", Map.class); - assertEquals(HttpStatus.UNAUTHORIZED, entity.getStatusCode()); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); } @Test public void testHealth() throws Exception { ResponseEntity entity = new TestRestTemplate().getForEntity( "http://localhost:" + this.managementPort + "/health", String.class); - assertEquals(HttpStatus.OK, entity.getStatusCode()); - assertEquals("{\"status\":\"UP\"}", entity.getBody()); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(entity.getBody()).isEqualTo("{\"status\":\"UP\"}"); } } diff --git a/spring-boot-samples/spring-boot-sample-actuator-ui/src/test/java/sample/actuator/ui/SampleActuatorUiApplicationTests.java b/spring-boot-samples/spring-boot-sample-actuator-ui/src/test/java/sample/actuator/ui/SampleActuatorUiApplicationTests.java index bdb76e65c2..9ee10c24f8 100644 --- a/spring-boot-samples/spring-boot-sample-actuator-ui/src/test/java/sample/actuator/ui/SampleActuatorUiApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-actuator-ui/src/test/java/sample/actuator/ui/SampleActuatorUiApplicationTests.java @@ -35,8 +35,7 @@ import org.springframework.http.ResponseEntity; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * Basic integration tests for demo application. @@ -59,17 +58,16 @@ public class SampleActuatorUiApplicationTests { ResponseEntity entity = new TestRestTemplate().exchange( "http://localhost:" + this.port, HttpMethod.GET, new HttpEntity(headers), String.class); - assertEquals(HttpStatus.OK, entity.getStatusCode()); - assertTrue("Wrong body (title doesn't match):\n" + entity.getBody(), - entity.getBody().contains("Hello")); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(entity.getBody()).contains("<title>Hello"); } @Test public void testCss() throws Exception { ResponseEntity<String> entity = new TestRestTemplate().getForEntity( "http://localhost:" + this.port + "/css/bootstrap.min.css", String.class); - assertEquals(HttpStatus.OK, entity.getStatusCode()); - assertTrue("Wrong body:\n" + entity.getBody(), entity.getBody().contains("body")); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(entity.getBody()).contains("body"); } @Test @@ -77,7 +75,7 @@ public class SampleActuatorUiApplicationTests { @SuppressWarnings("rawtypes") ResponseEntity<Map> entity = new TestRestTemplate() .getForEntity("http://localhost:" + this.port + "/metrics", Map.class); - assertEquals(HttpStatus.UNAUTHORIZED, entity.getStatusCode()); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); } @Test @@ -87,13 +85,9 @@ public class SampleActuatorUiApplicationTests { ResponseEntity<String> entity = new TestRestTemplate().exchange( "http://localhost:" + this.port + "/error", HttpMethod.GET, new HttpEntity<Void>(headers), String.class); - assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, entity.getStatusCode()); - assertTrue("Wrong body:\n" + entity.getBody(), - entity.getBody().contains("<html>")); - 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")); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR); + assertThat(entity.getBody()).contains("<html>").contains("<body>") + .contains("Please contact the operator with the above information"); } } diff --git a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/EndpointsPropertiesSampleActuatorApplicationTests.java b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/EndpointsPropertiesSampleActuatorApplicationTests.java index d6a6c56c45..95e95c787e 100644 --- a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/EndpointsPropertiesSampleActuatorApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/EndpointsPropertiesSampleActuatorApplicationTests.java @@ -33,8 +33,7 @@ import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * Integration tests for endpoints configuration. @@ -59,11 +58,11 @@ public class EndpointsPropertiesSampleActuatorApplicationTests { @SuppressWarnings("rawtypes") ResponseEntity<Map> entity = new TestRestTemplate("user", getPassword()) .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") Map<String, Object> body = entity.getBody(); - assertEquals("None", body.get("error")); - assertEquals(999, body.get("status")); + assertThat(body.get("error")).isEqualTo("None"); + assertThat(body.get("status")).isEqualTo(999); } @Test @@ -71,12 +70,9 @@ public class EndpointsPropertiesSampleActuatorApplicationTests { ResponseEntity<String> entity = new TestRestTemplate("user", getPassword()) .getForEntity("http://localhost:" + this.port + "/admin/health", String.class); - assertEquals(HttpStatus.OK, entity.getStatusCode()); - assertTrue("Wrong body: " + entity.getBody(), - entity.getBody().contains("\"status\":\"UP\"")); - System.err.println(entity.getBody()); - assertTrue("Wrong body: " + entity.getBody(), - entity.getBody().contains("\"hello\":\"world\"")); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(entity.getBody()).contains("\"status\":\"UP\""); + assertThat(entity.getBody()).contains("\"hello\":\"world\""); } private String getPassword() { diff --git a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/InsecureManagementPortAndPathSampleActuatorApplicationTests.java b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/InsecureManagementPortAndPathSampleActuatorApplicationTests.java index 97d9574ad9..a8741fff73 100644 --- a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/InsecureManagementPortAndPathSampleActuatorApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/InsecureManagementPortAndPathSampleActuatorApplicationTests.java @@ -32,8 +32,7 @@ import org.springframework.http.ResponseEntity; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * Integration tests for separate management and main service ports. @@ -61,10 +60,10 @@ public class InsecureManagementPortAndPathSampleActuatorApplicationTests { @SuppressWarnings("rawtypes") ResponseEntity<Map> entity = new TestRestTemplate("user", getPassword()) .getForEntity("http://localhost:" + this.port, Map.class); - assertEquals(HttpStatus.OK, entity.getStatusCode()); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); @SuppressWarnings("unchecked") Map<String, Object> body = entity.getBody(); - assertEquals("Hello Phil", body.get("message")); + assertThat(body.get("message")).isEqualTo("Hello Phil"); } @Test @@ -73,7 +72,7 @@ public class InsecureManagementPortAndPathSampleActuatorApplicationTests { @SuppressWarnings("rawtypes") ResponseEntity<Map> entity = new TestRestTemplate().getForEntity( "http://localhost:" + this.managementPort + "/admin/metrics", Map.class); - assertEquals(HttpStatus.OK, entity.getStatusCode()); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); } @Test @@ -81,9 +80,8 @@ public class InsecureManagementPortAndPathSampleActuatorApplicationTests { ResponseEntity<String> entity = new TestRestTemplate().getForEntity( "http://localhost:" + this.managementPort + "/admin/health", String.class); - assertEquals(HttpStatus.OK, entity.getStatusCode()); - assertTrue("Wrong body: " + entity.getBody(), - entity.getBody().contains("\"status\":\"UP\"")); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(entity.getBody()).contains("\"status\":\"UP\""); } @Test @@ -91,9 +89,8 @@ public class InsecureManagementPortAndPathSampleActuatorApplicationTests { ResponseEntity<String> entity = new TestRestTemplate().getForEntity( "http://localhost:" + this.managementPort + "/admin/missing", String.class); - assertEquals(HttpStatus.NOT_FOUND, entity.getStatusCode()); - assertTrue("Wrong body: " + entity.getBody(), - entity.getBody().contains("\"status\":404")); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND); + assertThat(entity.getBody()).contains("\"status\":404"); } private String getPassword() { diff --git a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/InsecureManagementSampleActuatorApplicationTests.java b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/InsecureManagementSampleActuatorApplicationTests.java index 57bca76db6..89d86992ef 100644 --- a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/InsecureManagementSampleActuatorApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/InsecureManagementSampleActuatorApplicationTests.java @@ -31,9 +31,7 @@ import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * Integration tests for insecured service endpoints (even with Spring Security on @@ -56,12 +54,11 @@ public class InsecureManagementSampleActuatorApplicationTests { @SuppressWarnings("rawtypes") ResponseEntity<Map> entity = new TestRestTemplate() .getForEntity("http://localhost:" + this.port, Map.class); - assertEquals(HttpStatus.UNAUTHORIZED, entity.getStatusCode()); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); @SuppressWarnings("unchecked") Map<String, Object> body = entity.getBody(); - assertEquals("Wrong body: " + body, "Unauthorized", body.get("error")); - assertFalse("Wrong headers: " + entity.getHeaders(), - entity.getHeaders().containsKey("Set-Cookie")); + assertThat(body.get("error")).isEqualTo("Unauthorized"); + assertThat(entity.getHeaders()).doesNotContainKey("Set-Cookie"); } @Test @@ -75,11 +72,10 @@ public class InsecureManagementSampleActuatorApplicationTests { @SuppressWarnings("rawtypes") ResponseEntity<Map> entity = new TestRestTemplate() .getForEntity("http://localhost:" + this.port + "/metrics", Map.class); - assertEquals(HttpStatus.OK, entity.getStatusCode()); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); @SuppressWarnings("unchecked") Map<String, Object> body = entity.getBody(); - assertTrue("Wrong body: " + body, - body.containsKey("counter.status.401.unmapped")); + assertThat(body).containsKey("counter.status.401.unmapped"); } } diff --git a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/InsecureSampleActuatorApplicationTests.java b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/InsecureSampleActuatorApplicationTests.java index 914e3ec20d..e3d4d6107b 100644 --- a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/InsecureSampleActuatorApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/InsecureSampleActuatorApplicationTests.java @@ -30,8 +30,7 @@ import org.springframework.http.ResponseEntity; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; +import static org.assertj.core.api.Assertions.assertThat; /** * Integration tests for insecured service endpoints (even with Spring Security on @@ -53,12 +52,11 @@ public class InsecureSampleActuatorApplicationTests { @SuppressWarnings("rawtypes") ResponseEntity<Map> entity = new TestRestTemplate() .getForEntity("http://localhost:" + this.port, Map.class); - assertEquals(HttpStatus.OK, entity.getStatusCode()); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); @SuppressWarnings("unchecked") Map<String, Object> body = entity.getBody(); - assertEquals("Hello Phil", body.get("message")); - assertFalse("Wrong headers: " + entity.getHeaders(), - entity.getHeaders().containsKey("Set-Cookie")); + assertThat(body.get("message")).isEqualTo("Hello Phil"); + assertThat(entity.getHeaders()).doesNotContainKey("Set-Cookie"); } } diff --git a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementAddressActuatorApplicationTests.java b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementAddressActuatorApplicationTests.java index df075314d3..fa8f2cd394 100644 --- a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementAddressActuatorApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementAddressActuatorApplicationTests.java @@ -30,8 +30,7 @@ import org.springframework.http.ResponseEntity; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * Integration tests for separate management and main service ports. @@ -56,7 +55,7 @@ public class ManagementAddressActuatorApplicationTests { @SuppressWarnings("rawtypes") ResponseEntity<Map> entity = new TestRestTemplate() .getForEntity("http://localhost:" + this.port, Map.class); - assertEquals(HttpStatus.UNAUTHORIZED, entity.getStatusCode()); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); } @Test @@ -64,9 +63,8 @@ public class ManagementAddressActuatorApplicationTests { ResponseEntity<String> entity = new TestRestTemplate().getForEntity( "http://localhost:" + this.managementPort + "/admin/health", String.class); - assertEquals(HttpStatus.OK, entity.getStatusCode()); - assertTrue("Wrong body: " + entity.getBody(), - entity.getBody().contains("\"status\":\"UP\"")); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(entity.getBody()).contains("\"status\":\"UP\""); } } diff --git a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementPathSampleActuatorApplicationTests.java b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementPathSampleActuatorApplicationTests.java index 75711361fe..3d823ad69e 100644 --- a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementPathSampleActuatorApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementPathSampleActuatorApplicationTests.java @@ -30,9 +30,7 @@ import org.springframework.http.ResponseEntity; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * Integration tests for endpoints configuration. @@ -52,9 +50,8 @@ public class ManagementPathSampleActuatorApplicationTests { public void testHealth() throws Exception { ResponseEntity<String> entity = new TestRestTemplate().getForEntity( "http://localhost:" + this.port + "/admin/health", String.class); - assertEquals(HttpStatus.OK, entity.getStatusCode()); - assertTrue("Wrong body: " + entity.getBody(), - entity.getBody().contains("\"status\":\"UP\"")); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(entity.getBody()).contains("\"status\":\"UP\""); } @Test @@ -62,12 +59,11 @@ public class ManagementPathSampleActuatorApplicationTests { @SuppressWarnings("rawtypes") ResponseEntity<Map> entity = new TestRestTemplate() .getForEntity("http://localhost:" + this.port, Map.class); - assertEquals(HttpStatus.UNAUTHORIZED, entity.getStatusCode()); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); @SuppressWarnings("unchecked") Map<String, Object> body = entity.getBody(); - assertEquals("Wrong body: " + body, "Unauthorized", body.get("error")); - assertFalse("Wrong headers: " + entity.getHeaders(), - entity.getHeaders().containsKey("Set-Cookie")); + assertThat(body.get("error")).isEqualTo("Unauthorized"); + assertThat(entity.getHeaders()).doesNotContainKey("Set-Cookie"); } } diff --git a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementPortAndPathSampleActuatorApplicationTests.java b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementPortAndPathSampleActuatorApplicationTests.java index 1446de329a..bc4441aaa3 100644 --- a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementPortAndPathSampleActuatorApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementPortAndPathSampleActuatorApplicationTests.java @@ -32,8 +32,7 @@ import org.springframework.http.ResponseEntity; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * Integration tests for separate management and main service ports. @@ -61,10 +60,10 @@ public class ManagementPortAndPathSampleActuatorApplicationTests { @SuppressWarnings("rawtypes") ResponseEntity<Map> entity = new TestRestTemplate("user", getPassword()) .getForEntity("http://localhost:" + this.port, Map.class); - assertEquals(HttpStatus.OK, entity.getStatusCode()); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); @SuppressWarnings("unchecked") Map<String, Object> body = entity.getBody(); - assertEquals("Hello Phil", body.get("message")); + assertThat(body.get("message")).isEqualTo("Hello Phil"); } @Test @@ -73,7 +72,7 @@ public class ManagementPortAndPathSampleActuatorApplicationTests { @SuppressWarnings("rawtypes") ResponseEntity<Map> entity = new TestRestTemplate().getForEntity( "http://localhost:" + this.managementPort + "/admin/metrics", Map.class); - assertEquals(HttpStatus.UNAUTHORIZED, entity.getStatusCode()); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); } @Test @@ -81,9 +80,8 @@ public class ManagementPortAndPathSampleActuatorApplicationTests { ResponseEntity<String> entity = new TestRestTemplate().getForEntity( "http://localhost:" + this.managementPort + "/admin/health", String.class); - assertEquals(HttpStatus.OK, entity.getStatusCode()); - assertTrue("Wrong body: " + entity.getBody(), - entity.getBody().contains("\"status\":\"UP\"")); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(entity.getBody()).contains("\"status\":\"UP\""); } @Test @@ -92,9 +90,8 @@ public class ManagementPortAndPathSampleActuatorApplicationTests { .getForEntity( "http://localhost:" + this.managementPort + "/admin/missing", String.class); - assertEquals(HttpStatus.NOT_FOUND, entity.getStatusCode()); - assertTrue("Wrong body: " + entity.getBody(), - entity.getBody().contains("\"status\":404")); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND); + assertThat(entity.getBody()).contains("\"status\":404"); } @Test @@ -102,10 +99,10 @@ public class ManagementPortAndPathSampleActuatorApplicationTests { @SuppressWarnings("rawtypes") ResponseEntity<Map> entity = new TestRestTemplate() .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") Map<String, Object> body = entity.getBody(); - assertEquals(999, body.get("status")); + assertThat(body.get("status")).isEqualTo(999); } @Test @@ -113,11 +110,10 @@ public class ManagementPortAndPathSampleActuatorApplicationTests { @SuppressWarnings("rawtypes") ResponseEntity<Map> entity = new TestRestTemplate().getForEntity( "http://localhost:" + this.managementPort + "/error", Map.class); - // TODO: should be 500? - assertEquals(HttpStatus.OK, entity.getStatusCode()); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); @SuppressWarnings("unchecked") Map<String, Object> body = entity.getBody(); - assertEquals(999, body.get("status")); + assertThat(body.get("status")).isEqualTo(999); } private String getPassword() { diff --git a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementPortSampleActuatorApplicationTests.java b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementPortSampleActuatorApplicationTests.java index fc9c21ab9e..24dd9042b9 100644 --- a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementPortSampleActuatorApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ManagementPortSampleActuatorApplicationTests.java @@ -32,8 +32,7 @@ import org.springframework.http.ResponseEntity; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * Integration tests for separate management and main service ports. @@ -60,10 +59,10 @@ public class ManagementPortSampleActuatorApplicationTests { @SuppressWarnings("rawtypes") ResponseEntity<Map> entity = new TestRestTemplate("user", getPassword()) .getForEntity("http://localhost:" + this.port, Map.class); - assertEquals(HttpStatus.OK, entity.getStatusCode()); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); @SuppressWarnings("unchecked") Map<String, Object> body = entity.getBody(); - assertEquals("Hello Phil", body.get("message")); + assertThat(body.get("message")).isEqualTo("Hello Phil"); } @Test @@ -72,16 +71,15 @@ public class ManagementPortSampleActuatorApplicationTests { @SuppressWarnings("rawtypes") ResponseEntity<Map> entity = new TestRestTemplate().getForEntity( "http://localhost:" + this.managementPort + "/metrics", Map.class); - assertEquals(HttpStatus.UNAUTHORIZED, entity.getStatusCode()); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); } @Test public void testHealth() throws Exception { ResponseEntity<String> entity = new TestRestTemplate().getForEntity( "http://localhost:" + this.managementPort + "/health", String.class); - assertEquals(HttpStatus.OK, entity.getStatusCode()); - assertTrue("Wrong body: " + entity.getBody(), - entity.getBody().contains("\"status\":\"UP\"")); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(entity.getBody()).contains("\"status\":\"UP\""); } @Test @@ -89,10 +87,10 @@ public class ManagementPortSampleActuatorApplicationTests { @SuppressWarnings("rawtypes") ResponseEntity<Map> entity = new TestRestTemplate().getForEntity( "http://localhost:" + this.managementPort + "/error", Map.class); - assertEquals(HttpStatus.OK, entity.getStatusCode()); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); @SuppressWarnings("unchecked") Map<String, Object> body = entity.getBody(); - assertEquals(999, body.get("status")); + assertThat(body.get("status")).isEqualTo(999); } private String getPassword() { diff --git a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/NoManagementSampleActuatorApplicationTests.java b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/NoManagementSampleActuatorApplicationTests.java index ff0d2aca92..e0523de21c 100644 --- a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/NoManagementSampleActuatorApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/NoManagementSampleActuatorApplicationTests.java @@ -32,7 +32,7 @@ import org.springframework.http.ResponseEntity; import org.springframework.test.annotation.DirtiesContext; 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. @@ -56,10 +56,10 @@ public class NoManagementSampleActuatorApplicationTests { @SuppressWarnings("rawtypes") ResponseEntity<Map> entity = new TestRestTemplate("user", getPassword()) .getForEntity("http://localhost:" + this.port, Map.class); - assertEquals(HttpStatus.OK, entity.getStatusCode()); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); @SuppressWarnings("unchecked") Map<String, Object> body = entity.getBody(); - assertEquals("Hello Phil", body.get("message")); + assertThat(body.get("message")).isEqualTo("Hello Phil"); } @Test @@ -68,7 +68,7 @@ public class NoManagementSampleActuatorApplicationTests { @SuppressWarnings("rawtypes") ResponseEntity<Map> entity = new TestRestTemplate("user", getPassword()) .getForEntity("http://localhost:" + this.port + "/metrics", Map.class); - assertEquals(HttpStatus.NOT_FOUND, entity.getStatusCode()); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND); } private String getPassword() { diff --git a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/NonSensitiveHealthTests.java b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/NonSensitiveHealthTests.java index a55be0c4a8..1debd23883 100644 --- a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/NonSensitiveHealthTests.java +++ b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/NonSensitiveHealthTests.java @@ -28,8 +28,7 @@ import org.springframework.http.ResponseEntity; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests for /health with {@code endpoints.health.sensitive=false}. @@ -49,9 +48,8 @@ public class NonSensitiveHealthTests { public void testSecureHealth() throws Exception { ResponseEntity<String> entity = new TestRestTemplate() .getForEntity("http://localhost:" + this.port + "/health", String.class); - assertEquals(HttpStatus.OK, entity.getStatusCode()); - assertFalse("Wrong body: " + entity.getBody(), - entity.getBody().contains("\"hello\":1")); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(entity.getBody()).doesNotContain("\"hello\":1"); } } diff --git a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/SampleActuatorApplicationTests.java b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/SampleActuatorApplicationTests.java index f2d7797e07..cbfc1be396 100644 --- a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/SampleActuatorApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/SampleActuatorApplicationTests.java @@ -38,10 +38,7 @@ import org.springframework.http.ResponseEntity; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * Basic integration tests for service demo application. @@ -65,12 +62,11 @@ public class SampleActuatorApplicationTests { @SuppressWarnings("rawtypes") ResponseEntity<Map> entity = new TestRestTemplate() .getForEntity("http://localhost:" + this.port, Map.class); - assertEquals(HttpStatus.UNAUTHORIZED, entity.getStatusCode()); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); @SuppressWarnings("unchecked") Map<String, Object> body = entity.getBody(); - assertEquals("Wrong body: " + body, "Unauthorized", body.get("error")); - assertFalse("Wrong headers: " + entity.getHeaders(), - entity.getHeaders().containsKey("Set-Cookie")); + assertThat(body.get("error")).isEqualTo("Unauthorized"); + assertThat(entity.getHeaders()).doesNotContainKey("Set-Cookie"); } @Test @@ -78,16 +74,16 @@ public class SampleActuatorApplicationTests { @SuppressWarnings("rawtypes") ResponseEntity<Map> entity = new TestRestTemplate() .getForEntity("http://localhost:" + this.port + "/metrics", Map.class); - assertEquals(HttpStatus.UNAUTHORIZED, entity.getStatusCode()); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); entity = new TestRestTemplate() .getForEntity("http://localhost:" + this.port + "/metrics/", Map.class); - assertEquals(HttpStatus.UNAUTHORIZED, entity.getStatusCode()); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); entity = new TestRestTemplate().getForEntity( "http://localhost:" + this.port + "/metrics/foo", Map.class); - assertEquals(HttpStatus.UNAUTHORIZED, entity.getStatusCode()); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); entity = new TestRestTemplate().getForEntity( "http://localhost:" + this.port + "/metrics.json", Map.class); - assertEquals(HttpStatus.UNAUTHORIZED, entity.getStatusCode()); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); } @Test @@ -95,10 +91,10 @@ public class SampleActuatorApplicationTests { @SuppressWarnings("rawtypes") ResponseEntity<Map> entity = new TestRestTemplate("user", getPassword()) .getForEntity("http://localhost:" + this.port, Map.class); - assertEquals(HttpStatus.OK, entity.getStatusCode()); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); @SuppressWarnings("unchecked") Map<String, Object> body = entity.getBody(); - assertEquals("Hello Phil", body.get("message")); + assertThat(body.get("message")).isEqualTo("Hello Phil"); } @Test @@ -107,10 +103,10 @@ public class SampleActuatorApplicationTests { @SuppressWarnings("rawtypes") ResponseEntity<Map> entity = new TestRestTemplate("user", getPassword()) .getForEntity("http://localhost:" + this.port + "/metrics", Map.class); - assertEquals(HttpStatus.OK, entity.getStatusCode()); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); @SuppressWarnings("unchecked") Map<String, Object> body = entity.getBody(); - assertTrue("Wrong body: " + body, body.containsKey("counter.status.200.root")); + assertThat(body).containsKey("counter.status.200.root"); } @Test @@ -118,49 +114,45 @@ public class SampleActuatorApplicationTests { @SuppressWarnings("rawtypes") ResponseEntity<Map> entity = new TestRestTemplate("user", getPassword()) .getForEntity("http://localhost:" + this.port + "/env", Map.class); - assertEquals(HttpStatus.OK, entity.getStatusCode()); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); @SuppressWarnings("unchecked") Map<String, Object> body = entity.getBody(); - assertTrue("Wrong body: " + body, body.containsKey("systemProperties")); + assertThat(body).containsKey("systemProperties"); } @Test public void testHealth() throws Exception { ResponseEntity<String> entity = new TestRestTemplate() .getForEntity("http://localhost:" + this.port + "/health", String.class); - assertEquals(HttpStatus.OK, entity.getStatusCode()); - assertTrue("Wrong body: " + entity.getBody(), - entity.getBody().contains("\"status\":\"UP\"")); - assertFalse("Wrong body: " + entity.getBody(), - entity.getBody().contains("\"hello\":\"1\"")); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(entity.getBody()).contains("\"status\":\"UP\""); + assertThat(entity.getBody()).doesNotContain("\"hello\":\"1\""); } @Test public void testSecureHealth() throws Exception { ResponseEntity<String> entity = new TestRestTemplate("user", getPassword()) .getForEntity("http://localhost:" + this.port + "/health", String.class); - assertEquals(HttpStatus.OK, entity.getStatusCode()); - assertTrue("Wrong body: " + entity.getBody(), - entity.getBody().contains("\"hello\":1")); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(entity.getBody()).contains("\"hello\":1"); } @Test public void testInfo() throws Exception { ResponseEntity<String> entity = new TestRestTemplate() .getForEntity("http://localhost:" + this.port + "/info", String.class); - assertEquals(HttpStatus.OK, entity.getStatusCode()); - assertTrue("Wrong body: " + entity.getBody(), entity.getBody() - .contains("\"artifact\":\"spring-boot-sample-actuator\"")); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(entity.getBody()) + .contains("\"artifact\":\"spring-boot-sample-actuator\""); } @Test public void testErrorPage() throws Exception { ResponseEntity<String> entity = new TestRestTemplate("user", getPassword()) .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(); - assertNotNull(body); - assertTrue("Wrong body: " + body, body.contains("\"error\":")); + assertThat(body).contains("\"error\":"); } @Test @@ -171,11 +163,10 @@ public class SampleActuatorApplicationTests { ResponseEntity<String> entity = new TestRestTemplate("user", getPassword()) .exchange("http://localhost:" + this.port + "/foo", HttpMethod.GET, request, String.class); - assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, entity.getStatusCode()); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR); String body = entity.getBody(); - assertNotNull("Body was null", body); - assertTrue("Wrong body: " + body, - body.contains("This application has no explicit mapping for /error")); + assertThat(body).as("Body was null").isNotNull(); + assertThat(body).contains("This application has no explicit mapping for /error"); } @Test @@ -185,14 +176,14 @@ public class SampleActuatorApplicationTests { @SuppressWarnings("rawtypes") ResponseEntity<List> entity = new TestRestTemplate("user", getPassword()) .getForEntity("http://localhost:" + this.port + "/trace", List.class); - assertEquals(HttpStatus.OK, entity.getStatusCode()); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); @SuppressWarnings("unchecked") List<Map<String, Object>> list = entity.getBody(); Map<String, Object> trace = list.get(list.size() - 1); @SuppressWarnings("unchecked") Map<String, Object> map = (Map<String, Object>) ((Map<String, Object>) ((Map<String, Object>) trace .get("info")).get("headers")).get("response"); - assertEquals("200", map.get("status")); + assertThat(map.get("status")).isEqualTo("200"); } @Test @@ -200,24 +191,23 @@ public class SampleActuatorApplicationTests { @SuppressWarnings("rawtypes") ResponseEntity<Map> entity = new TestRestTemplate() .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") Map<String, Object> body = entity.getBody(); - assertEquals("None", body.get("error")); - assertEquals(999, body.get("status")); + assertThat(body.get("error")).isEqualTo("None"); + assertThat(body.get("status")).isEqualTo(999); } @Test + @SuppressWarnings("unchecked") public void testBeans() throws Exception { @SuppressWarnings("rawtypes") ResponseEntity<List> entity = new TestRestTemplate("user", getPassword()) .getForEntity("http://localhost:" + this.port + "/beans", List.class); - assertEquals(HttpStatus.OK, entity.getStatusCode()); - assertEquals(1, entity.getBody().size()); - @SuppressWarnings("unchecked") + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(entity.getBody()).hasSize(1); Map<String, Object> body = (Map<String, Object>) entity.getBody().get(0); - assertTrue("Wrong body: " + body, - ((String) body.get("context")).startsWith("application")); + assertThat(((String) body.get("context"))).startsWith("application"); } @Test @@ -226,11 +216,10 @@ public class SampleActuatorApplicationTests { ResponseEntity<Map> entity = new TestRestTemplate("user", getPassword()) .getForEntity("http://localhost:" + this.port + "/configprops", Map.class); - assertEquals(HttpStatus.OK, entity.getStatusCode()); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); @SuppressWarnings("unchecked") Map<String, Object> body = entity.getBody(); - assertTrue("Wrong body: " + body, - body.containsKey("spring.datasource.CONFIGURATION_PROPERTIES")); + assertThat(body).containsKey("spring.datasource.CONFIGURATION_PROPERTIES"); } private String getPassword() { diff --git a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ServletPathInsecureSampleActuatorApplicationTests.java b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ServletPathInsecureSampleActuatorApplicationTests.java index c5b9b30a8e..5f344e8bbc 100644 --- a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ServletPathInsecureSampleActuatorApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ServletPathInsecureSampleActuatorApplicationTests.java @@ -30,8 +30,7 @@ import org.springframework.http.ResponseEntity; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; +import static org.assertj.core.api.Assertions.assertThat; /** * Integration tests for insecured service endpoints (even with Spring Security on @@ -54,12 +53,11 @@ public class ServletPathInsecureSampleActuatorApplicationTests { @SuppressWarnings("rawtypes") ResponseEntity<Map> entity = new TestRestTemplate() .getForEntity("http://localhost:" + this.port + "/spring/", Map.class); - assertEquals(HttpStatus.OK, entity.getStatusCode()); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); @SuppressWarnings("unchecked") Map<String, Object> body = entity.getBody(); - assertEquals("Hello Phil", body.get("message")); - assertFalse("Wrong headers: " + entity.getHeaders(), - entity.getHeaders().containsKey("Set-Cookie")); + assertThat(body.get("message")).isEqualTo("Hello Phil"); + assertThat(entity.getHeaders()).doesNotContainKey("Set-Cookie"); } @Test @@ -67,7 +65,7 @@ public class ServletPathInsecureSampleActuatorApplicationTests { @SuppressWarnings("rawtypes") ResponseEntity<Map> entity = new TestRestTemplate().getForEntity( "http://localhost:" + this.port + "/spring/metrics", Map.class); - assertEquals(HttpStatus.UNAUTHORIZED, entity.getStatusCode()); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); } } diff --git a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ServletPathSampleActuatorApplicationTests.java b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ServletPathSampleActuatorApplicationTests.java index a1e760910d..deb970a12c 100644 --- a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ServletPathSampleActuatorApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ServletPathSampleActuatorApplicationTests.java @@ -30,9 +30,7 @@ import org.springframework.http.ResponseEntity; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * Integration tests for endpoints configuration. @@ -54,20 +52,19 @@ public class ServletPathSampleActuatorApplicationTests { ResponseEntity<Map> entity = new TestRestTemplate("user", "password") .getForEntity("http://localhost:" + this.port + "/spring/error", Map.class); - assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, entity.getStatusCode()); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR); @SuppressWarnings("unchecked") Map<String, Object> body = entity.getBody(); - assertEquals("None", body.get("error")); - assertEquals(999, body.get("status")); + assertThat(body.get("error")).isEqualTo("None"); + assertThat(body.get("status")).isEqualTo(999); } @Test public void testHealth() throws Exception { ResponseEntity<String> entity = new TestRestTemplate().getForEntity( "http://localhost:" + this.port + "/spring/health", String.class); - assertEquals(HttpStatus.OK, entity.getStatusCode()); - assertTrue("Wrong body: " + entity.getBody(), - entity.getBody().contains("\"status\":\"UP\"")); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(entity.getBody()).contains("\"status\":\"UP\""); } @Test @@ -75,12 +72,11 @@ public class ServletPathSampleActuatorApplicationTests { @SuppressWarnings("rawtypes") ResponseEntity<Map> entity = new TestRestTemplate() .getForEntity("http://localhost:" + this.port + "/spring/", Map.class); - assertEquals(HttpStatus.UNAUTHORIZED, entity.getStatusCode()); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); @SuppressWarnings("unchecked") Map<String, Object> body = entity.getBody(); - assertEquals("Wrong body: " + body, "Unauthorized", body.get("error")); - assertFalse("Wrong headers: " + entity.getHeaders(), - entity.getHeaders().containsKey("Set-Cookie")); + assertThat(body.get("error")).isEqualTo("Unauthorized"); + assertThat(entity.getHeaders()).doesNotContainKey("Set-Cookie"); } } diff --git a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ShutdownSampleActuatorApplicationTests.java b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ShutdownSampleActuatorApplicationTests.java index a822d130ea..09c567f884 100644 --- a/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ShutdownSampleActuatorApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-actuator/src/test/java/sample/actuator/ShutdownSampleActuatorApplicationTests.java @@ -32,8 +32,7 @@ import org.springframework.http.ResponseEntity; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * Integration tests for separate management and main service ports. @@ -57,10 +56,10 @@ public class ShutdownSampleActuatorApplicationTests { @SuppressWarnings("rawtypes") ResponseEntity<Map> entity = new TestRestTemplate("user", getPassword()) .getForEntity("http://localhost:" + this.port, Map.class); - assertEquals(HttpStatus.OK, entity.getStatusCode()); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); @SuppressWarnings("unchecked") Map<String, Object> body = entity.getBody(); - assertEquals("Hello Phil", body.get("message")); + assertThat(body.get("message")).isEqualTo("Hello Phil"); } @Test @@ -69,11 +68,10 @@ public class ShutdownSampleActuatorApplicationTests { ResponseEntity<Map> entity = new TestRestTemplate("user", getPassword()) .postForEntity("http://localhost:" + this.port + "/shutdown", null, Map.class); - assertEquals(HttpStatus.OK, entity.getStatusCode()); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); @SuppressWarnings("unchecked") Map<String, Object> body = entity.getBody(); - assertTrue("Wrong body: " + body, - ((String) body.get("message")).contains("Shutting down")); + assertThat(((String) body.get("message"))).contains("Shutting down"); } private String getPassword() { diff --git a/spring-boot-samples/spring-boot-sample-ant/src/test/java/sample/ant/SampleAntApplicationIT.java b/spring-boot-samples/spring-boot-sample-ant/src/test/java/sample/ant/SampleAntApplicationIT.java index 7050787e79..617e12273b 100644 --- a/spring-boot-samples/spring-boot-sample-ant/src/test/java/sample/ant/SampleAntApplicationIT.java +++ b/spring-boot-samples/spring-boot-sample-ant/src/test/java/sample/ant/SampleAntApplicationIT.java @@ -16,9 +16,7 @@ package sample.ant; -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.equalTo; -import static org.junit.Assert.assertThat; +import static org.assertj.core.api.Assertions.assertThat; import java.io.File; import java.io.FileFilter; @@ -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.waitFor(5, TimeUnit.MINUTES); - assertThat(process.exitValue(), equalTo(0)); + assertThat(process.exitValue()).isEqualTo(0); String output = FileCopyUtils.copyToString(new InputStreamReader(process.getInputStream())); - assertThat(output, containsString("Spring Boot Ant Example")); + assertThat(output).contains("Spring Boot Ant Example"); } } diff --git a/spring-boot-samples/spring-boot-sample-aop/src/test/java/sample/aop/SampleAopApplicationTests.java b/spring-boot-samples/spring-boot-sample-aop/src/test/java/sample/aop/SampleAopApplicationTests.java index 326ac90b39..18e03b2f5f 100644 --- a/spring-boot-samples/spring-boot-sample-aop/src/test/java/sample/aop/SampleAopApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-aop/src/test/java/sample/aop/SampleAopApplicationTests.java @@ -23,7 +23,7 @@ import org.junit.Test; import org.springframework.boot.test.OutputCapture; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests for {@link SampleAopApplication}. @@ -57,14 +57,14 @@ public class SampleAopApplicationTests { public void testDefaultSettings() throws Exception { SampleAopApplication.main(new String[0]); String output = this.outputCapture.toString(); - assertTrue("Wrong output: " + output, output.contains("Hello Phil")); + assertThat(output).contains("Hello Phil"); } @Test public void testCommandLineOverrides() throws Exception { SampleAopApplication.main(new String[] { "--name=Gordon" }); String output = this.outputCapture.toString(); - assertTrue("Wrong output: " + output, output.contains("Hello Gordon")); + assertThat(output).contains("Hello Gordon"); } } diff --git a/spring-boot-samples/spring-boot-sample-atmosphere/src/test/java/sample/atmosphere/SampleAtmosphereApplicationTests.java b/spring-boot-samples/spring-boot-sample-atmosphere/src/test/java/sample/atmosphere/SampleAtmosphereApplicationTests.java index beb0c0d186..d58676e7ad 100644 --- a/spring-boot-samples/spring-boot-sample-atmosphere/src/test/java/sample/atmosphere/SampleAtmosphereApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-atmosphere/src/test/java/sample/atmosphere/SampleAtmosphereApplicationTests.java @@ -42,9 +42,7 @@ import org.springframework.web.socket.client.WebSocketConnectionManager; import org.springframework.web.socket.client.standard.StandardWebSocketClient; import org.springframework.web.socket.handler.TextWebSocketHandler; -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.equalTo; -import static org.junit.Assert.assertThat; +import static org.assertj.core.api.Assertions.assertThat; @RunWith(SpringJUnit4ClassRunner.class) @SpringApplicationConfiguration(SampleAtmosphereApplication.class) @@ -68,9 +66,9 @@ public class SampleAtmosphereApplicationTests { AtomicReference<String> messagePayloadReference = context .getBean(ClientConfiguration.class).messagePayload; context.close(); - assertThat(count, equalTo(0L)); - assertThat(messagePayloadReference.get(), - containsString("{\"message\":\"test\",\"author\":\"test\",\"time\":")); + assertThat(count).isEqualTo(0L); + assertThat(messagePayloadReference.get()) + .contains("{\"message\":\"test\",\"author\":\"test\",\"time\":"); } @Configuration diff --git a/spring-boot-samples/spring-boot-sample-batch/src/test/java/sample/batch/SampleBatchApplicationTests.java b/spring-boot-samples/spring-boot-sample-batch/src/test/java/sample/batch/SampleBatchApplicationTests.java index 52f983b941..141ad2334f 100644 --- a/spring-boot-samples/spring-boot-sample-batch/src/test/java/sample/batch/SampleBatchApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-batch/src/test/java/sample/batch/SampleBatchApplicationTests.java @@ -22,8 +22,7 @@ import org.junit.Test; import org.springframework.boot.SpringApplication; import org.springframework.boot.test.OutputCapture; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; public class SampleBatchApplicationTests { @@ -32,11 +31,10 @@ public class SampleBatchApplicationTests { @Test public void testDefaultSettings() throws Exception { - assertEquals(0, SpringApplication - .exit(SpringApplication.run(SampleBatchApplication.class))); + assertThat(SpringApplication + .exit(SpringApplication.run(SampleBatchApplication.class))).isEqualTo(0); String output = this.outputCapture.toString(); - assertTrue("Wrong output: " + output, - output.contains("completed with the following parameters")); + assertThat(output).contains("completed with the following parameters"); } } diff --git a/spring-boot-samples/spring-boot-sample-cache/src/test/java/sample/cache/SampleCacheApplicationTests.java b/spring-boot-samples/spring-boot-sample-cache/src/test/java/sample/cache/SampleCacheApplicationTests.java index df5c5c6e1c..2d3a17f317 100644 --- a/spring-boot-samples/spring-boot-sample-cache/src/test/java/sample/cache/SampleCacheApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-cache/src/test/java/sample/cache/SampleCacheApplicationTests.java @@ -25,10 +25,7 @@ import org.springframework.cache.Cache; import org.springframework.cache.CacheManager; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import static org.hamcrest.CoreMatchers.nullValue; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.core.IsNull.notNullValue; +import static org.assertj.core.api.Assertions.assertThat; @RunWith(SpringJUnit4ClassRunner.class) @SpringApplicationConfiguration(SampleCacheApplication.class) @@ -43,11 +40,11 @@ public class SampleCacheApplicationTests { @Test public void validateCache() { Cache countries = this.cacheManager.getCache("countries"); - assertThat(countries, is(notNullValue())); + assertThat(countries).isNotNull(); 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"); - assertThat((Country) countries.get("BE").get(), is(be)); + assertThat((Country) countries.get("BE").get()).isEqualTo(be); } } diff --git a/spring-boot-samples/spring-boot-sample-data-cassandra/src/test/java/sample/data/cassandra/SampleCassandraApplicationTests.java b/spring-boot-samples/spring-boot-sample-data-cassandra/src/test/java/sample/data/cassandra/SampleCassandraApplicationTests.java index 10c0a83b12..f50659242a 100644 --- a/spring-boot-samples/spring-boot-sample-data-cassandra/src/test/java/sample/data/cassandra/SampleCassandraApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-data-cassandra/src/test/java/sample/data/cassandra/SampleCassandraApplicationTests.java @@ -30,7 +30,7 @@ import org.springframework.test.context.TestExecutionListeners; import org.springframework.test.context.TestExecutionListeners.MergeMode; 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}. @@ -51,8 +51,7 @@ public class SampleCassandraApplicationTests { @Test public void testDefaultSettings() throws Exception { String output = SampleCassandraApplicationTests.outputCapture.toString(); - assertTrue("Wrong output: " + output, - output.contains("firstName='Alice', lastName='Smith'")); + assertThat(output).contains("firstName='Alice', lastName='Smith'"); } } diff --git a/spring-boot-samples/spring-boot-sample-data-elasticsearch/src/test/java/sample/data/elasticsearch/SampleElasticsearchApplicationTests.java b/spring-boot-samples/spring-boot-sample-data-elasticsearch/src/test/java/sample/data/elasticsearch/SampleElasticsearchApplicationTests.java index 87d9db45e5..2cfceb60a9 100644 --- a/spring-boot-samples/spring-boot-sample-data-elasticsearch/src/test/java/sample/data/elasticsearch/SampleElasticsearchApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-data-elasticsearch/src/test/java/sample/data/elasticsearch/SampleElasticsearchApplicationTests.java @@ -25,7 +25,7 @@ import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.test.OutputCapture; import org.springframework.core.NestedCheckedException; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests for {@link SampleElasticsearchApplication}. @@ -53,8 +53,7 @@ public class SampleElasticsearchApplicationTests { } } String output = this.outputCapture.toString(); - assertTrue("Wrong output: " + output, - output.contains("firstName='Alice', lastName='Smith'")); + assertThat(output).contains("firstName='Alice', lastName='Smith'"); } private boolean serverNotRunning(IllegalStateException ex) { diff --git a/spring-boot-samples/spring-boot-sample-data-gemfire/src/test/java/sample/data/gemfire/SampleDataGemFireApplicationTests.java b/spring-boot-samples/spring-boot-sample-data-gemfire/src/test/java/sample/data/gemfire/SampleDataGemFireApplicationTests.java index 0fce4acdd1..13f90ac861 100644 --- a/spring-boot-samples/spring-boot-sample-data-gemfire/src/test/java/sample/data/gemfire/SampleDataGemFireApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-data-gemfire/src/test/java/sample/data/gemfire/SampleDataGemFireApplicationTests.java @@ -16,8 +16,6 @@ package sample.data.gemfire; -import java.util.ArrayList; -import java.util.List; import java.util.concurrent.atomic.AtomicLong; import org.junit.Before; @@ -31,9 +29,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * The SampleDataGemFireApplicationTests class is a test suite with test cases testing the @@ -50,70 +46,38 @@ public class SampleDataGemFireApplicationTests { 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 public void setup() { - assertNotNull("A reference to the GemstoneService was not properly configured!", - this.gemstoneService); + assertThat(this.gemstoneService).isNotNull(); } @Test public void testGemstonesApp() { - assertEquals(0, this.gemstoneService.count()); - assertTrue(asList(this.gemstoneService.list()).isEmpty()); + assertThat(this.gemstoneService.count()).isEqualTo(0); + assertThat(this.gemstoneService.list()).isEmpty(); this.gemstoneService.save(createGemstone("Diamond")); this.gemstoneService.save(createGemstone("Ruby")); - assertEquals(2, this.gemstoneService.count()); - assertTrue(asList(this.gemstoneService.list()) - .containsAll(getGemstones("Diamond", "Ruby"))); + assertThat(this.gemstoneService.count()).isEqualTo(2); + assertThat(this.gemstoneService.list()).contains(getGemstones("Diamond", "Ruby")); try { this.gemstoneService.save(createGemstone("Coal")); } - catch (IllegalGemstoneException expected) { + catch (IllegalGemstoneException ex) { + // Expected } - assertEquals(2, this.gemstoneService.count()); - assertTrue(asList(this.gemstoneService.list()) - .containsAll(getGemstones("Diamond", "Ruby"))); + assertThat(this.gemstoneService.count()).isEqualTo(2); + assertThat(this.gemstoneService.list()).contains(getGemstones("Diamond", "Ruby")); this.gemstoneService.save(createGemstone("Pearl")); this.gemstoneService.save(createGemstone("Sapphire")); - assertEquals(4, this.gemstoneService.count()); - assertTrue(asList(this.gemstoneService.list()) - .containsAll(getGemstones("Diamond", "Ruby", "Pearl", "Sapphire"))); + assertThat(this.gemstoneService.count()).isEqualTo(4); + assertThat(this.gemstoneService.list()) + .contains(getGemstones("Diamond", "Ruby", "Pearl", "Sapphire")); try { this.gemstoneService.save(createGemstone("Quartz")); @@ -121,11 +85,28 @@ public class SampleDataGemFireApplicationTests { catch (IllegalGemstoneException expected) { } - assertEquals(4, this.gemstoneService.count()); - assertTrue(asList(this.gemstoneService.list()) - .containsAll(getGemstones("Diamond", "Ruby", "Pearl", "Sapphire"))); - assertEquals(createGemstone("Diamond"), this.gemstoneService.get("Diamond")); - assertEquals(createGemstone("Pearl"), this.gemstoneService.get("Pearl")); + assertThat(this.gemstoneService.count()).isEqualTo(4); + assertThat(this.gemstoneService.list()) + .contains(getGemstones("Diamond", "Ruby", "Pearl", "Sapphire")); + assertThat(this.gemstoneService.get("Diamond")) + .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); } } diff --git a/spring-boot-samples/spring-boot-sample-data-jpa/src/test/java/sample/data/jpa/SampleDataJpaApplicationTests.java b/spring-boot-samples/spring-boot-sample-data-jpa/src/test/java/sample/data/jpa/SampleDataJpaApplicationTests.java index ef1e073f3a..371ca52577 100644 --- a/spring-boot-samples/spring-boot-sample-data-jpa/src/test/java/sample/data/jpa/SampleDataJpaApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-data-jpa/src/test/java/sample/data/jpa/SampleDataJpaApplicationTests.java @@ -34,7 +34,7 @@ import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.setup.MockMvcBuilders; 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.result.MockMvcResultMatchers.content; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @@ -74,9 +74,9 @@ public class SampleDataJpaApplicationTests { @Test public void testJmx() throws Exception { - assertEquals(1, ManagementFactory.getPlatformMBeanServer() - .queryMBeans(new ObjectName("jpa.sample:type=ConnectionPool,*"), null) - .size()); + assertThat(ManagementFactory.getPlatformMBeanServer() + .queryMBeans(new ObjectName("jpa.sample:type=ConnectionPool,*"), null)) + .hasSize(1); } } diff --git a/spring-boot-samples/spring-boot-sample-data-jpa/src/test/java/sample/data/jpa/service/CityRepositoryIntegrationTests.java b/spring-boot-samples/spring-boot-sample-data-jpa/src/test/java/sample/data/jpa/service/CityRepositoryIntegrationTests.java index 2e591a964d..58d1afd914 100644 --- a/spring-boot-samples/spring-boot-sample-data-jpa/src/test/java/sample/data/jpa/service/CityRepositoryIntegrationTests.java +++ b/spring-boot-samples/spring-boot-sample-data-jpa/src/test/java/sample/data/jpa/service/CityRepositoryIntegrationTests.java @@ -26,9 +26,7 @@ import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import static org.hamcrest.Matchers.greaterThan; -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThat; +import static org.assertj.core.api.Assertions.assertThat; /** * Integration tests for {@link CityRepository}. @@ -46,6 +44,6 @@ public class CityRepositoryIntegrationTests { public void findsFirstPageOfCities() { Page<City> cities = this.repository.findAll(new PageRequest(0, 10)); - assertThat(cities.getTotalElements(), is(greaterThan(20L))); + assertThat(cities.getTotalElements()).isGreaterThan(20L); } } diff --git a/spring-boot-samples/spring-boot-sample-data-jpa/src/test/java/sample/data/jpa/service/HotelRepositoryIntegrationTests.java b/spring-boot-samples/spring-boot-sample-data-jpa/src/test/java/sample/data/jpa/service/HotelRepositoryIntegrationTests.java index 4a540b7c22..9b8c2d9cf5 100644 --- a/spring-boot-samples/spring-boot-sample-data-jpa/src/test/java/sample/data/jpa/service/HotelRepositoryIntegrationTests.java +++ b/spring-boot-samples/spring-boot-sample-data-jpa/src/test/java/sample/data/jpa/service/HotelRepositoryIntegrationTests.java @@ -33,10 +33,7 @@ import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Sort.Direction; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import static org.hamcrest.Matchers.greaterThan; -import static org.hamcrest.Matchers.hasSize; -import static org.hamcrest.Matchers.is; -import static org.junit.Assert.assertThat; +import static org.assertj.core.api.Assertions.assertThat; /** * Integration tests for {@link HotelRepository}. @@ -57,17 +54,17 @@ public class HotelRepositoryIntegrationTests { City city = this.cityRepository .findAll(new PageRequest(0, 1, Direction.ASC, "name")).getContent() .get(0); - assertThat(city.getName(), is("Atlanta")); + assertThat(city.getName()).isEqualTo("Atlanta"); Page<HotelSummary> hotels = this.repository.findByCity(city, new PageRequest(0, 10, Direction.ASC, "name")); Hotel hotel = this.repository.findByCityAndName(city, hotels.getContent().get(0).getName()); - assertThat(hotel.getName(), is("Doubletree")); + assertThat(hotel.getName()).isEqualTo("Doubletree"); List<RatingCount> counts = this.repository.findRatingCounts(hotel); - assertThat(counts, hasSize(1)); - assertThat(counts.get(0).getRating(), is(Rating.AVERAGE)); - assertThat(counts.get(0).getCount(), is(greaterThan(1L))); + assertThat(counts).hasSize(1); + assertThat(counts.get(0).getRating()).isEqualTo(Rating.AVERAGE); + assertThat(counts.get(0).getCount()).isGreaterThan(1L); } } diff --git a/spring-boot-samples/spring-boot-sample-data-mongodb/src/test/java/sample/data/mongo/SampleMongoApplicationTests.java b/spring-boot-samples/spring-boot-sample-data-mongodb/src/test/java/sample/data/mongo/SampleMongoApplicationTests.java index 53eb843be2..befd77b18d 100644 --- a/spring-boot-samples/spring-boot-sample-data-mongodb/src/test/java/sample/data/mongo/SampleMongoApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-data-mongodb/src/test/java/sample/data/mongo/SampleMongoApplicationTests.java @@ -25,7 +25,7 @@ import org.springframework.boot.test.OutputCapture; import org.springframework.boot.test.SpringApplicationConfiguration; 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}. @@ -44,8 +44,7 @@ public class SampleMongoApplicationTests { @Test public void testDefaultSettings() throws Exception { String output = SampleMongoApplicationTests.outputCapture.toString(); - assertTrue("Wrong output: " + output, - output.contains("firstName='Alice', lastName='Smith'")); + assertThat(output).contains("firstName='Alice', lastName='Smith'"); } } diff --git a/spring-boot-samples/spring-boot-sample-data-redis/src/test/java/sample/data/redis/SampleRedisApplicationTests.java b/spring-boot-samples/spring-boot-sample-data-redis/src/test/java/sample/data/redis/SampleRedisApplicationTests.java index d3329a7c25..91b7832a4f 100644 --- a/spring-boot-samples/spring-boot-sample-data-redis/src/test/java/sample/data/redis/SampleRedisApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-data-redis/src/test/java/sample/data/redis/SampleRedisApplicationTests.java @@ -22,7 +22,7 @@ import org.junit.Test; import org.springframework.boot.test.OutputCapture; import org.springframework.data.redis.RedisConnectionFailureException; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests for {@link SampleRedisApplication}. @@ -45,8 +45,7 @@ public class SampleRedisApplicationTests { } } String output = this.outputCapture.toString(); - assertTrue("Wrong output: " + output, - output.contains("Found key spring.boot.redis.test")); + assertThat(output).contains("Found key spring.boot.redis.test"); } private boolean redisServerRunning(Throwable ex) { diff --git a/spring-boot-samples/spring-boot-sample-data-rest/src/test/java/sample/data/rest/service/CityRepositoryIntegrationTests.java b/spring-boot-samples/spring-boot-sample-data-rest/src/test/java/sample/data/rest/service/CityRepositoryIntegrationTests.java index 9a2c1392b6..a3549ba0ff 100644 --- a/spring-boot-samples/spring-boot-sample-data-rest/src/test/java/sample/data/rest/service/CityRepositoryIntegrationTests.java +++ b/spring-boot-samples/spring-boot-sample-data-rest/src/test/java/sample/data/rest/service/CityRepositoryIntegrationTests.java @@ -27,11 +27,7 @@ import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.greaterThan; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.notNullValue; -import static org.junit.Assert.assertThat; +import static org.assertj.core.api.Assertions.assertThat; /** * Integration tests for {@link CityRepository}. @@ -50,15 +46,15 @@ public class CityRepositoryIntegrationTests { public void findsFirstPageOfCities() { Page<City> cities = this.repository.findAll(new PageRequest(0, 10)); - assertThat(cities.getTotalElements(), is(greaterThan(20L))); + assertThat(cities.getTotalElements()).isGreaterThan(20L); } @Test public void findByNameAndCountry() { City city = this.repository.findByNameAndCountryAllIgnoringCase("Melbourne", "Australia"); - assertThat(city, notNullValue()); - assertThat(city.getName(), is(equalTo("Melbourne"))); + assertThat(city).isNotNull(); + assertThat(city.getName()).isEqualTo("Melbourne"); } @Test @@ -66,6 +62,6 @@ public class CityRepositoryIntegrationTests { Page<City> cities = this.repository .findByNameContainingAndCountryContainingAllIgnoringCase("", "UK", new PageRequest(0, 10)); - assertThat(cities.getTotalElements(), is(equalTo(3L))); + assertThat(cities.getTotalElements()).isEqualTo(3L); } } diff --git a/spring-boot-samples/spring-boot-sample-data-solr/src/test/java/sample/data/solr/SampleSolrApplicationTests.java b/spring-boot-samples/spring-boot-sample-data-solr/src/test/java/sample/data/solr/SampleSolrApplicationTests.java index 9a527cb329..a63e9e816b 100644 --- a/spring-boot-samples/spring-boot-sample-data-solr/src/test/java/sample/data/solr/SampleSolrApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-data-solr/src/test/java/sample/data/solr/SampleSolrApplicationTests.java @@ -22,7 +22,7 @@ import org.junit.Test; import org.springframework.boot.test.OutputCapture; import org.springframework.core.NestedCheckedException; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; public class SampleSolrApplicationTests { @@ -41,7 +41,7 @@ public class SampleSolrApplicationTests { } } 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) { diff --git a/spring-boot-samples/spring-boot-sample-flyway/src/test/java/sample/flyway/SampleFlywayApplicationTests.java b/spring-boot-samples/spring-boot-sample-flyway/src/test/java/sample/flyway/SampleFlywayApplicationTests.java index 1382f213a0..f3e325a324 100644 --- a/spring-boot-samples/spring-boot-sample-flyway/src/test/java/sample/flyway/SampleFlywayApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-flyway/src/test/java/sample/flyway/SampleFlywayApplicationTests.java @@ -24,7 +24,7 @@ import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import static org.junit.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; @RunWith(SpringJUnit4ClassRunner.class) @SpringApplicationConfiguration(SampleFlywayApplication.class) @@ -35,8 +35,8 @@ public class SampleFlywayApplicationTests { @Test public void testDefaultSettings() throws Exception { - assertEquals(new Integer(1), this.template - .queryForObject("SELECT COUNT(*) from PERSON", Integer.class)); + assertThat(this.template.queryForObject("SELECT COUNT(*) from PERSON", + Integer.class)).isEqualTo(1); } } diff --git a/spring-boot-samples/spring-boot-sample-hateoas/src/test/java/sample/hateoas/SampleHateoasApplicationTests.java b/spring-boot-samples/spring-boot-sample-hateoas/src/test/java/sample/hateoas/SampleHateoasApplicationTests.java index 511024cfa4..d7fc1fd82e 100644 --- a/spring-boot-samples/spring-boot-sample-hateoas/src/test/java/sample/hateoas/SampleHateoasApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-hateoas/src/test/java/sample/hateoas/SampleHateoasApplicationTests.java @@ -33,10 +33,7 @@ import org.springframework.http.RequestEntity; import org.springframework.http.ResponseEntity; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.startsWith; -import static org.junit.Assert.assertThat; +import static org.assertj.core.api.Assertions.assertThat; @RunWith(SpringJUnit4ClassRunner.class) @SpringApplicationConfiguration(SampleHateoasApplication.class) @@ -50,10 +47,10 @@ public class SampleHateoasApplicationTests { public void hasHalLinks() throws Exception { ResponseEntity<String> entity = new TestRestTemplate().getForEntity( "http://localhost:" + this.port + "/customers/1", String.class); - assertThat(entity.getStatusCode(), equalTo(HttpStatus.OK)); - assertThat(entity.getBody(), startsWith( - "{\"id\":1,\"firstName\":\"Oliver\"" + ",\"lastName\":\"Gierke\"")); - assertThat(entity.getBody(), containsString("_links\":{\"self\":{\"href\"")); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(entity.getBody()).startsWith( + "{\"id\":1,\"firstName\":\"Oliver\"" + ",\"lastName\":\"Gierke\""); + assertThat(entity.getBody()).contains("_links\":{\"self\":{\"href\""); } @Test @@ -64,9 +61,9 @@ public class SampleHateoasApplicationTests { URI.create("http://localhost:" + this.port + "/customers/1")); ResponseEntity<String> response = new TestRestTemplate().exchange(request, String.class); - assertThat(response.getStatusCode(), equalTo(HttpStatus.OK)); - assertThat(response.getHeaders().getContentType(), - equalTo(MediaType.parseMediaType("application/json;charset=UTF-8"))); + assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(response.getHeaders().getContentType()) + .isEqualTo(MediaType.parseMediaType("application/json;charset=UTF-8")); } } diff --git a/spring-boot-samples/spring-boot-sample-hypermedia-jpa/src/test/java/sample/hypermedia/jpa/SampleHypermediaJpaApplicationIntegrationTests.java b/spring-boot-samples/spring-boot-sample-hypermedia-jpa/src/test/java/sample/hypermedia/jpa/SampleHypermediaJpaApplicationIntegrationTests.java index 67896386b7..f279a28fb2 100644 --- a/spring-boot-samples/spring-boot-sample-hypermedia-jpa/src/test/java/sample/hypermedia/jpa/SampleHypermediaJpaApplicationIntegrationTests.java +++ b/spring-boot-samples/spring-boot-sample-hypermedia-jpa/src/test/java/sample/hypermedia/jpa/SampleHypermediaJpaApplicationIntegrationTests.java @@ -31,7 +31,7 @@ import org.springframework.test.web.servlet.MvcResult; import org.springframework.test.web.servlet.setup.MockMvcBuilders; 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.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @@ -83,8 +83,8 @@ public class SampleHypermediaJpaApplicationIntegrationTests { public void browser() throws Exception { MvcResult response = this.mockMvc.perform(get("/").accept(MediaType.TEXT_HTML)) .andExpect(status().isFound()).andReturn(); - assertEquals("/browser/index.html#", - response.getResponse().getHeaders("location").get(0)); + assertThat(response.getResponse().getHeaders("location").get(0)) + .isEqualTo("/browser/index.html#"); } } diff --git a/spring-boot-samples/spring-boot-sample-hypermedia-ui/src/test/java/sample/hypermedia/ui/SampleHypermediaUiApplicationTests.java b/spring-boot-samples/spring-boot-sample-hypermedia-ui/src/test/java/sample/hypermedia/ui/SampleHypermediaUiApplicationTests.java index 342fde1a53..da90ecbd8c 100644 --- a/spring-boot-samples/spring-boot-sample-hypermedia-ui/src/test/java/sample/hypermedia/ui/SampleHypermediaUiApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-hypermedia-ui/src/test/java/sample/hypermedia/ui/SampleHypermediaUiApplicationTests.java @@ -33,7 +33,7 @@ import org.springframework.http.RequestEntity; import org.springframework.http.ResponseEntity; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; @RunWith(SpringJUnit4ClassRunner.class) @SpringApplicationConfiguration(SampleHypermediaUiApplication.class) @@ -47,14 +47,14 @@ public class SampleHypermediaUiApplicationTests { public void home() { String response = new TestRestTemplate() .getForObject("http://localhost:" + this.port, String.class); - assertTrue("Wrong body: " + response, response.contains("Hello World")); + assertThat(response).contains("Hello World"); } @Test public void links() { String response = new TestRestTemplate().getForObject( "http://localhost:" + this.port + "/actuator", String.class); - assertTrue("Wrong body: " + response, response.contains("\"_links\":")); + assertThat(response).contains("\"_links\":"); } @Test @@ -65,7 +65,7 @@ public class SampleHypermediaUiApplicationTests { new RequestEntity<Void>(headers, HttpMethod.GET, new URI("http://localhost:" + this.port + "/actuator")), String.class); - assertTrue("Wrong body: " + response, response.getBody().contains("\"_links\":")); + assertThat(response.getBody()).contains("\"_links\":"); } @Test @@ -75,7 +75,7 @@ public class SampleHypermediaUiApplicationTests { ResponseEntity<String> response = new TestRestTemplate() .exchange(new RequestEntity<Void>(headers, HttpMethod.GET, new URI("http://localhost:" + this.port)), String.class); - assertTrue("Wrong body: " + response, response.getBody().contains("Hello World")); + assertThat(response.getBody()).contains("Hello World"); } } diff --git a/spring-boot-samples/spring-boot-sample-hypermedia/src/test/java/sample/hypermedia/SampleHypermediaApplicationHomePageTests.java b/spring-boot-samples/spring-boot-sample-hypermedia/src/test/java/sample/hypermedia/SampleHypermediaApplicationHomePageTests.java index d5a4f936ac..0bd29ab243 100644 --- a/spring-boot-samples/spring-boot-sample-hypermedia/src/test/java/sample/hypermedia/SampleHypermediaApplicationHomePageTests.java +++ b/spring-boot-samples/spring-boot-sample-hypermedia/src/test/java/sample/hypermedia/SampleHypermediaApplicationHomePageTests.java @@ -33,7 +33,7 @@ import org.springframework.http.RequestEntity; import org.springframework.http.ResponseEntity; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; @RunWith(SpringJUnit4ClassRunner.class) @SpringApplicationConfiguration(SampleHypermediaApplication.class) @@ -47,7 +47,7 @@ public class SampleHypermediaApplicationHomePageTests { public void home() { String response = new TestRestTemplate() .getForObject("http://localhost:" + this.port, String.class); - assertTrue("Wrong body: " + response, response.contains("404")); + assertThat(response).contains("404"); } @Test @@ -58,7 +58,7 @@ public class SampleHypermediaApplicationHomePageTests { new RequestEntity<Void>(headers, HttpMethod.GET, new URI("http://localhost:" + this.port + "/actuator")), String.class); - assertTrue("Wrong body: " + response, response.getBody().contains("\"_links\":")); + assertThat(response.getBody()).contains("\"_links\":"); } @Test @@ -69,7 +69,7 @@ public class SampleHypermediaApplicationHomePageTests { new RequestEntity<Void>(headers, HttpMethod.GET, new URI("http://localhost:" + this.port + "/actuator/")), String.class); - assertTrue("Wrong body: " + response, response.getBody().contains("HAL Browser")); + assertThat(response.getBody()).contains("HAL Browser"); } } diff --git a/spring-boot-samples/spring-boot-sample-integration/src/test/java/sample/integration/consumer/SampleIntegrationApplicationTests.java b/spring-boot-samples/spring-boot-sample-integration/src/test/java/sample/integration/consumer/SampleIntegrationApplicationTests.java index a81df0a3fa..2ba25ca58f 100644 --- a/spring-boot-samples/spring-boot-sample-integration/src/test/java/sample/integration/consumer/SampleIntegrationApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-integration/src/test/java/sample/integration/consumer/SampleIntegrationApplicationTests.java @@ -38,7 +38,7 @@ import org.springframework.core.io.support.ResourcePatternUtils; import org.springframework.util.FileSystemUtils; 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. @@ -71,7 +71,7 @@ public class SampleIntegrationApplicationTests { public void testVanillaExchange() throws Exception { SpringApplication.run(ProducerApplication.class, "World"); String output = getOutput(); - assertTrue("Wrong output: " + output, output.contains("Hello World")); + assertThat(output).contains("Hello World"); } private String getOutput() throws Exception { diff --git a/spring-boot-samples/spring-boot-sample-jersey/src/test/java/sample/jersey/SampleJerseyApplicationTests.java b/spring-boot-samples/spring-boot-sample-jersey/src/test/java/sample/jersey/SampleJerseyApplicationTests.java index 16d47f6208..e6c3e47235 100644 --- a/spring-boot-samples/spring-boot-sample-jersey/src/test/java/sample/jersey/SampleJerseyApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-jersey/src/test/java/sample/jersey/SampleJerseyApplicationTests.java @@ -28,7 +28,7 @@ import org.springframework.http.ResponseEntity; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.web.client.RestTemplate; -import static org.junit.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; @RunWith(SpringJUnit4ClassRunner.class) @SpringApplicationConfiguration(SampleJerseyApplication.class) @@ -44,22 +44,22 @@ public class SampleJerseyApplicationTests { public void contextLoads() { ResponseEntity<String> entity = this.restTemplate .getForEntity("http://localhost:" + this.port + "/hello", String.class); - assertEquals(HttpStatus.OK, entity.getStatusCode()); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); } @Test public void reverse() { ResponseEntity<String> entity = this.restTemplate.getForEntity( "http://localhost:" + this.port + "/reverse?input=olleh", String.class); - assertEquals(HttpStatus.OK, entity.getStatusCode()); - assertEquals("hello", entity.getBody()); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(entity.getBody()).isEqualTo("hello"); } @Test public void validation() { ResponseEntity<String> entity = this.restTemplate .getForEntity("http://localhost:" + this.port + "/reverse", String.class); - assertEquals(HttpStatus.BAD_REQUEST, entity.getStatusCode()); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.BAD_REQUEST); } } diff --git a/spring-boot-samples/spring-boot-sample-jersey1/src/test/java/sample/jersey1/SampleJersey1ApplicationTests.java b/spring-boot-samples/spring-boot-sample-jersey1/src/test/java/sample/jersey1/SampleJersey1ApplicationTests.java index 4f7a5e8815..4e1825f083 100644 --- a/spring-boot-samples/spring-boot-sample-jersey1/src/test/java/sample/jersey1/SampleJersey1ApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-jersey1/src/test/java/sample/jersey1/SampleJersey1ApplicationTests.java @@ -25,7 +25,7 @@ import org.springframework.boot.test.TestRestTemplate; import org.springframework.boot.test.WebIntegrationTest; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import static org.junit.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; @RunWith(SpringJUnit4ClassRunner.class) @SpringApplicationConfiguration(SampleJersey1Application.class) @@ -37,8 +37,9 @@ public class SampleJersey1ApplicationTests { @Test public void contextLoads() { - assertEquals("Hello World", new TestRestTemplate() - .getForObject("http://localhost:" + this.port + "/", String.class)); + assertThat(new TestRestTemplate() + .getForObject("http://localhost:" + this.port + "/", String.class)) + .isEqualTo("Hello World"); } } diff --git a/spring-boot-samples/spring-boot-sample-jetty-ssl/src/test/java/sample/jetty/ssl/SampleJettySslApplicationTests.java b/spring-boot-samples/spring-boot-sample-jetty-ssl/src/test/java/sample/jetty/ssl/SampleJettySslApplicationTests.java index 2c522463f9..d3910b8b31 100644 --- a/spring-boot-samples/spring-boot-sample-jetty-ssl/src/test/java/sample/jetty/ssl/SampleJettySslApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-jetty-ssl/src/test/java/sample/jetty/ssl/SampleJettySslApplicationTests.java @@ -34,7 +34,7 @@ import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; import org.springframework.test.annotation.DirtiesContext; 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. @@ -64,8 +64,8 @@ public class SampleJettySslApplicationTests { .setHttpClient(httpClient); ResponseEntity<String> entity = testRestTemplate .getForEntity("https://localhost:" + this.port, String.class); - assertEquals(HttpStatus.OK, entity.getStatusCode()); - assertEquals("Hello World", entity.getBody()); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(entity.getBody()).isEqualTo("Hello World"); } } diff --git a/spring-boot-samples/spring-boot-sample-jetty/src/test/java/sample/jetty/SampleJettyApplicationTests.java b/spring-boot-samples/spring-boot-sample-jetty/src/test/java/sample/jetty/SampleJettyApplicationTests.java index 75dcb45166..7401038e57 100644 --- a/spring-boot-samples/spring-boot-sample-jetty/src/test/java/sample/jetty/SampleJettyApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-jetty/src/test/java/sample/jetty/SampleJettyApplicationTests.java @@ -37,7 +37,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.util.StreamUtils; 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. @@ -58,8 +58,8 @@ public class SampleJettyApplicationTests { public void testHome() throws Exception { ResponseEntity<String> entity = new TestRestTemplate() .getForEntity("http://localhost:" + this.port, String.class); - assertEquals(HttpStatus.OK, entity.getStatusCode()); - assertEquals("Hello World", entity.getBody()); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(entity.getBody()).isEqualTo("Hello World"); } @Test @@ -74,13 +74,13 @@ public class SampleJettyApplicationTests { "http://localhost:" + this.port, HttpMethod.GET, requestEntity, byte[].class); - assertEquals(HttpStatus.OK, entity.getStatusCode()); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); GZIPInputStream inflater = new GZIPInputStream( new ByteArrayInputStream(entity.getBody())); try { - assertEquals("Hello World", - StreamUtils.copyToString(inflater, Charset.forName("UTF-8"))); + assertThat(StreamUtils.copyToString(inflater, Charset.forName("UTF-8"))) + .isEqualTo("Hello World"); } finally { inflater.close(); diff --git a/spring-boot-samples/spring-boot-sample-jetty8-ssl/src/test/java/sample/jetty8/ssl/SampleJetty8SslApplicationTests.java b/spring-boot-samples/spring-boot-sample-jetty8-ssl/src/test/java/sample/jetty8/ssl/SampleJetty8SslApplicationTests.java index 7d0cfa474d..c70b9898e7 100644 --- a/spring-boot-samples/spring-boot-sample-jetty8-ssl/src/test/java/sample/jetty8/ssl/SampleJetty8SslApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-jetty8-ssl/src/test/java/sample/jetty8/ssl/SampleJetty8SslApplicationTests.java @@ -34,7 +34,7 @@ import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; import org.springframework.test.annotation.DirtiesContext; 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. @@ -64,8 +64,8 @@ public class SampleJetty8SslApplicationTests { .setHttpClient(httpClient); ResponseEntity<String> entity = testRestTemplate .getForEntity("https://localhost:" + this.port, String.class); - assertEquals(HttpStatus.OK, entity.getStatusCode()); - assertEquals("Hello World", entity.getBody()); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(entity.getBody()).isEqualTo("Hello World"); } } diff --git a/spring-boot-samples/spring-boot-sample-jetty8/src/test/java/sample/jetty8/SampleJetty8ApplicationTests.java b/spring-boot-samples/spring-boot-sample-jetty8/src/test/java/sample/jetty8/SampleJetty8ApplicationTests.java index 60f77b7b04..3b9b676565 100644 --- a/spring-boot-samples/spring-boot-sample-jetty8/src/test/java/sample/jetty8/SampleJetty8ApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-jetty8/src/test/java/sample/jetty8/SampleJetty8ApplicationTests.java @@ -37,7 +37,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.util.StreamUtils; 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. @@ -58,8 +58,8 @@ public class SampleJetty8ApplicationTests { public void testHome() throws Exception { ResponseEntity<String> entity = new TestRestTemplate() .getForEntity("http://localhost:" + this.port, String.class); - assertEquals(HttpStatus.OK, entity.getStatusCode()); - assertEquals("Hello World", entity.getBody()); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(entity.getBody()).isEqualTo("Hello World"); } @Test @@ -71,12 +71,12 @@ public class SampleJetty8ApplicationTests { ResponseEntity<byte[]> entity = restTemplate.exchange( "http://localhost:" + this.port, HttpMethod.GET, requestEntity, byte[].class); - assertEquals(HttpStatus.OK, entity.getStatusCode()); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); GZIPInputStream inflater = new GZIPInputStream( new ByteArrayInputStream(entity.getBody())); try { - assertEquals("Hello World", - StreamUtils.copyToString(inflater, Charset.forName("UTF-8"))); + assertThat(StreamUtils.copyToString(inflater, Charset.forName("UTF-8"))) + .isEqualTo("Hello World"); } finally { inflater.close(); diff --git a/spring-boot-samples/spring-boot-sample-jetty93/src/test/java/sample/jetty93/SampleJetty93ApplicationTests.java b/spring-boot-samples/spring-boot-sample-jetty93/src/test/java/sample/jetty93/SampleJetty93ApplicationTests.java index 0112a97616..8e135eb6a4 100644 --- a/spring-boot-samples/spring-boot-sample-jetty93/src/test/java/sample/jetty93/SampleJetty93ApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-jetty93/src/test/java/sample/jetty93/SampleJetty93ApplicationTests.java @@ -37,7 +37,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.util.StreamUtils; 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. @@ -58,8 +58,8 @@ public class SampleJetty93ApplicationTests { public void testHome() throws Exception { ResponseEntity<String> entity = new TestRestTemplate() .getForEntity("http://localhost:" + this.port, String.class); - assertEquals(HttpStatus.OK, entity.getStatusCode()); - assertEquals("Hello World", entity.getBody()); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(entity.getBody()).isEqualTo("Hello World"); } @Test @@ -71,12 +71,12 @@ public class SampleJetty93ApplicationTests { ResponseEntity<byte[]> entity = restTemplate.exchange( "http://localhost:" + this.port, HttpMethod.GET, requestEntity, byte[].class); - assertEquals(HttpStatus.OK, entity.getStatusCode()); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); GZIPInputStream inflater = new GZIPInputStream( new ByteArrayInputStream(entity.getBody())); try { - assertEquals("Hello World", - StreamUtils.copyToString(inflater, Charset.forName("UTF-8"))); + assertThat(StreamUtils.copyToString(inflater, Charset.forName("UTF-8"))) + .isEqualTo("Hello World"); } finally { inflater.close(); diff --git a/spring-boot-samples/spring-boot-sample-jooq/src/test/java/sample/jooq/SampleJooqApplicationTests.java b/spring-boot-samples/spring-boot-sample-jooq/src/test/java/sample/jooq/SampleJooqApplicationTests.java index d6c222fe24..178192fadd 100644 --- a/spring-boot-samples/spring-boot-sample-jooq/src/test/java/sample/jooq/SampleJooqApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-jooq/src/test/java/sample/jooq/SampleJooqApplicationTests.java @@ -21,8 +21,7 @@ import org.junit.Test; import org.springframework.boot.test.OutputCapture; -import static org.hamcrest.Matchers.containsString; -import static org.junit.Assert.assertThat; +import static org.assertj.core.api.Assertions.assertThat; /** * Integration tests for {@link SampleJooqApplication}. @@ -37,11 +36,11 @@ public class SampleJooqApplicationTests { @Test public void outputResults() throws Exception { SampleJooqApplication.main(NO_ARGS); - assertThat(this.out.toString(), containsString("jOOQ Fetch 1 Greg Turnquest")); - assertThat(this.out.toString(), containsString("jOOQ Fetch 2 Craig Walls")); - assertThat(this.out.toString(), - containsString("jOOQ SQL " + "[Learning Spring Boot : Greg Turnquest, " - + "Spring Boot in Action : Craig Walls]")); + assertThat(this.out.toString()).contains("jOOQ Fetch 1 Greg Turnquest"); + assertThat(this.out.toString()).contains("jOOQ Fetch 2 Craig Walls"); + assertThat(this.out.toString()) + .contains("jOOQ SQL " + "[Learning Spring Boot : Greg Turnquest, " + + "Spring Boot in Action : Craig Walls]"); } } diff --git a/spring-boot-samples/spring-boot-sample-jpa/src/test/java/sample/jpa/repository/JpaNoteRepositoryIntegrationTests.java b/spring-boot-samples/spring-boot-sample-jpa/src/test/java/sample/jpa/repository/JpaNoteRepositoryIntegrationTests.java index 28044e811c..b4c2dd8432 100644 --- a/spring-boot-samples/spring-boot-sample-jpa/src/test/java/sample/jpa/repository/JpaNoteRepositoryIntegrationTests.java +++ b/spring-boot-samples/spring-boot-sample-jpa/src/test/java/sample/jpa/repository/JpaNoteRepositoryIntegrationTests.java @@ -26,7 +26,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.SpringApplicationConfiguration; 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}. @@ -43,7 +43,7 @@ public class JpaNoteRepositoryIntegrationTests { @Test public void findsAllNotes() { List<Note> notes = this.repository.findAll(); - assertEquals(4, notes.size()); + assertThat(notes).hasSize(4); } } diff --git a/spring-boot-samples/spring-boot-sample-jpa/src/test/java/sample/jpa/repository/JpaTagRepositoryIntegrationTests.java b/spring-boot-samples/spring-boot-sample-jpa/src/test/java/sample/jpa/repository/JpaTagRepositoryIntegrationTests.java index 404fd7bc66..83d59c96cc 100644 --- a/spring-boot-samples/spring-boot-sample-jpa/src/test/java/sample/jpa/repository/JpaTagRepositoryIntegrationTests.java +++ b/spring-boot-samples/spring-boot-sample-jpa/src/test/java/sample/jpa/repository/JpaTagRepositoryIntegrationTests.java @@ -26,7 +26,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.SpringApplicationConfiguration; 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}. @@ -43,7 +43,7 @@ public class JpaTagRepositoryIntegrationTests { @Test public void findsAllTags() { List<Tag> tags = this.repository.findAll(); - assertEquals(3, tags.size()); + assertThat(tags).hasSize(3); } } diff --git a/spring-boot-samples/spring-boot-sample-jta-atomikos/src/test/java/sample/atomikos/SampleAtomikosApplicationTests.java b/spring-boot-samples/spring-boot-sample-jta-atomikos/src/test/java/sample/atomikos/SampleAtomikosApplicationTests.java index 38d688d1c8..519e6c413a 100644 --- a/spring-boot-samples/spring-boot-sample-jta-atomikos/src/test/java/sample/atomikos/SampleAtomikosApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-jta-atomikos/src/test/java/sample/atomikos/SampleAtomikosApplicationTests.java @@ -16,14 +16,13 @@ package sample.atomikos; -import org.hamcrest.Matcher; -import org.hamcrest.core.SubstringMatcher; +import org.assertj.core.api.Condition; import org.junit.Rule; import org.junit.Test; 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. @@ -39,25 +38,22 @@ public class SampleAtomikosApplicationTests { public void testTransactionRollback() throws Exception { SampleAtomikosApplication.main(new String[] {}); String output = this.outputCapture.toString(); - assertThat(output, containsString(1, "---->")); - assertThat(output, containsString(1, "----> josh")); - assertThat(output, containsString(2, "Count is 1")); - assertThat(output, containsString(1, "Simulated error")); + assertThat(output).has(substring(1, "---->")); + assertThat(output).has(substring(1, "----> josh")); + assertThat(output).has(substring(2, "Count is 1")); + assertThat(output).has(substring(1, "Simulated error")); } - private Matcher<? super String> containsString(final int times, String s) { - return new SubstringMatcher(s) { + private Condition<String> substring(final int times, final String substring) { + return new Condition<String>( + "containing '" + substring + "' " + times + " times") { @Override - protected String relationship() { - return "containing " + times + " times"; - } - - @Override - protected boolean evalSubstringOf(String s) { + public boolean matches(String value) { int i = 0; - while (s.contains(this.substring)) { - s = s.substring(s.indexOf(this.substring) + this.substring.length()); + while (value.contains(substring)) { + int beginIndex = value.indexOf(substring) + substring.length(); + value = value.substring(beginIndex); i++; } return i == times; diff --git a/spring-boot-samples/spring-boot-sample-jta-bitronix/src/test/java/sample/bitronix/SampleBitronixApplicationTests.java b/spring-boot-samples/spring-boot-sample-jta-bitronix/src/test/java/sample/bitronix/SampleBitronixApplicationTests.java index 140df19905..b56bd98c62 100644 --- a/spring-boot-samples/spring-boot-sample-jta-bitronix/src/test/java/sample/bitronix/SampleBitronixApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-jta-bitronix/src/test/java/sample/bitronix/SampleBitronixApplicationTests.java @@ -17,8 +17,7 @@ package sample.bitronix; import bitronix.tm.resource.jms.PoolingConnectionFactory; -import org.hamcrest.Matcher; -import org.hamcrest.core.SubstringMatcher; +import org.assertj.core.api.Condition; import org.junit.Rule; import org.junit.Test; @@ -26,10 +25,7 @@ import org.springframework.boot.SpringApplication; import org.springframework.boot.test.OutputCapture; import org.springframework.context.ApplicationContext; -import static org.hamcrest.Matchers.instanceOf; -import static org.hamcrest.Matchers.not; -import static org.hamcrest.Matchers.sameInstance; -import static org.junit.Assert.assertThat; +import static org.assertj.core.api.Assertions.assertThat; /** * Basic integration tests for demo application. @@ -45,10 +41,10 @@ public class SampleBitronixApplicationTests { public void testTransactionRollback() throws Exception { SampleBitronixApplication.main(new String[] {}); String output = this.outputCapture.toString(); - assertThat(output, containsString(1, "---->")); - assertThat(output, containsString(1, "----> josh")); - assertThat(output, containsString(2, "Count is 1")); - assertThat(output, containsString(1, "Simulated error")); + assertThat(output).has(substring(1, "---->")); + assertThat(output).has(substring(1, "----> josh")); + assertThat(output).has(substring(2, "Count is 1")); + assertThat(output).has(substring(1, "Simulated error")); } @Test @@ -58,25 +54,22 @@ public class SampleBitronixApplicationTests { Object jmsConnectionFactory = context.getBean("jmsConnectionFactory"); Object xaJmsConnectionFactory = context.getBean("xaJmsConnectionFactory"); Object nonXaJmsConnectionFactory = context.getBean("nonXaJmsConnectionFactory"); - assertThat(jmsConnectionFactory, sameInstance(xaJmsConnectionFactory)); - assertThat(jmsConnectionFactory, instanceOf(PoolingConnectionFactory.class)); - assertThat(nonXaJmsConnectionFactory, - not(instanceOf(PoolingConnectionFactory.class))); + assertThat(jmsConnectionFactory).isSameAs(xaJmsConnectionFactory); + assertThat(jmsConnectionFactory).isInstanceOf(PoolingConnectionFactory.class); + assertThat(nonXaJmsConnectionFactory) + .isNotInstanceOf(PoolingConnectionFactory.class); } - private Matcher<? super String> containsString(final int times, String s) { - return new SubstringMatcher(s) { + private Condition<String> substring(final int times, final String substring) { + return new Condition<String>( + "containing '" + substring + "' " + times + " times") { @Override - protected String relationship() { - return "containing " + times + " times"; - } - - @Override - protected boolean evalSubstringOf(String s) { + public boolean matches(String value) { int i = 0; - while (s.contains(this.substring)) { - s = s.substring(s.indexOf(this.substring) + this.substring.length()); + while (value.contains(substring)) { + int beginIndex = value.indexOf(substring) + substring.length(); + value = value.substring(beginIndex); i++; } return i == times; diff --git a/spring-boot-samples/spring-boot-sample-liquibase/src/test/java/sample/liquibase/SampleLiquibaseApplicationTests.java b/spring-boot-samples/spring-boot-sample-liquibase/src/test/java/sample/liquibase/SampleLiquibaseApplicationTests.java index e33231cf73..331eb65dd6 100644 --- a/spring-boot-samples/spring-boot-sample-liquibase/src/test/java/sample/liquibase/SampleLiquibaseApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-liquibase/src/test/java/sample/liquibase/SampleLiquibaseApplicationTests.java @@ -24,7 +24,7 @@ import org.junit.Test; import org.springframework.boot.test.OutputCapture; import org.springframework.core.NestedCheckedException; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; public class SampleLiquibaseApplicationTests { @@ -42,23 +42,22 @@ public class SampleLiquibaseApplicationTests { } } String output = this.outputCapture.toString(); - assertTrue("Wrong output: " + output, - output.contains("Successfully acquired change log lock") - && output.contains("Creating database history " - + "table with name: PUBLIC.DATABASECHANGELOG") - && output.contains("Table person created") - && output.contains("ChangeSet classpath:/db/" + assertThat(output).contains("Successfully acquired change log lock") + .contains("Creating database history " + + "table with name: PUBLIC.DATABASECHANGELOG") + .contains("Table person created") + .contains("ChangeSet classpath:/db/" + "changelog/db.changelog-master.yaml::1::" + "marceloverdijk ran successfully") - && output.contains("New row inserted into person") - && output.contains("ChangeSet classpath:/db/changelog/" + .contains("New row inserted into person") + .contains("ChangeSet classpath:/db/changelog/" + "db.changelog-master.yaml::2::" + "marceloverdijk ran successfully") - && output.contains("Successfully released change log lock")); + .contains("Successfully released change log lock"); } + @SuppressWarnings("serial") private boolean serverNotRunning(IllegalStateException ex) { - @SuppressWarnings("serial") NestedCheckedException nested = new NestedCheckedException("failed", ex) { }; if (nested.contains(ConnectException.class)) { diff --git a/spring-boot-samples/spring-boot-sample-metrics-dropwizard/src/test/java/sample/metrics/dropwizard/SampleDropwizardMetricsApplicationTests.java b/spring-boot-samples/spring-boot-sample-metrics-dropwizard/src/test/java/sample/metrics/dropwizard/SampleDropwizardMetricsApplicationTests.java index 8ec62f11e4..9ec6b54af5 100644 --- a/spring-boot-samples/spring-boot-sample-metrics-dropwizard/src/test/java/sample/metrics/dropwizard/SampleDropwizardMetricsApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-metrics-dropwizard/src/test/java/sample/metrics/dropwizard/SampleDropwizardMetricsApplicationTests.java @@ -27,7 +27,7 @@ import org.springframework.boot.test.WebIntegrationTest; import org.springframework.test.annotation.DirtiesContext; 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}. @@ -49,7 +49,7 @@ public class SampleDropwizardMetricsApplicationTests { @Test public void timerCreated() { 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); } } diff --git a/spring-boot-samples/spring-boot-sample-profile/src/test/java/sample/profile/SampleProfileApplicationTests.java b/spring-boot-samples/spring-boot-sample-profile/src/test/java/sample/profile/SampleProfileApplicationTests.java index a252afa4c6..0548159001 100644 --- a/spring-boot-samples/spring-boot-sample-profile/src/test/java/sample/profile/SampleProfileApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-profile/src/test/java/sample/profile/SampleProfileApplicationTests.java @@ -23,7 +23,7 @@ import org.junit.Test; import org.springframework.boot.test.OutputCapture; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; public class SampleProfileApplicationTests { @@ -51,7 +51,7 @@ public class SampleProfileApplicationTests { public void testDefaultProfile() throws Exception { SampleProfileApplication.main(new String[0]); String output = this.outputCapture.toString(); - assertTrue("Wrong output: " + output, output.contains("Hello Phil")); + assertThat(output).contains("Hello Phil"); } @Test @@ -59,7 +59,7 @@ public class SampleProfileApplicationTests { System.setProperty("spring.profiles.active", "goodbye"); SampleProfileApplication.main(new String[0]); String output = this.outputCapture.toString(); - assertTrue("Wrong output: " + output, output.contains("Goodbye Everyone")); + assertThat(output).contains("Goodbye Everyone"); } @Test @@ -73,7 +73,7 @@ public class SampleProfileApplicationTests { System.setProperty("spring.profiles.active", "generic"); SampleProfileApplication.main(new String[0]); String output = this.outputCapture.toString(); - assertTrue("Wrong output: " + output, output.contains("Bonjour Phil")); + assertThat(output).contains("Bonjour Phil"); } @Test @@ -81,7 +81,7 @@ public class SampleProfileApplicationTests { SampleProfileApplication .main(new String[] { "--spring.profiles.active=goodbye" }); String output = this.outputCapture.toString(); - assertTrue("Wrong output: " + output, output.contains("Goodbye Everyone")); + assertThat(output).contains("Goodbye Everyone"); } } diff --git a/spring-boot-samples/spring-boot-sample-property-validation/src/test/java/sample/propertyvalidation/SamplePropertyValidationApplicationTests.java b/spring-boot-samples/spring-boot-sample-property-validation/src/test/java/sample/propertyvalidation/SamplePropertyValidationApplicationTests.java index 0f8defc904..885463e3ce 100644 --- a/spring-boot-samples/spring-boot-sample-property-validation/src/test/java/sample/propertyvalidation/SamplePropertyValidationApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-property-validation/src/test/java/sample/propertyvalidation/SamplePropertyValidationApplicationTests.java @@ -26,7 +26,7 @@ import org.springframework.boot.autoconfigure.web.ServerProperties; import org.springframework.boot.test.EnvironmentTestUtils; import org.springframework.context.annotation.AnnotationConfigApplicationContext; -import static org.junit.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests for {@link SamplePropertyValidationApplication}. @@ -53,8 +53,8 @@ public class SamplePropertyValidationApplicationTests { "sample.port:9090"); this.context.refresh(); SampleProperties properties = this.context.getBean(SampleProperties.class); - assertEquals("192.168.0.1", properties.getHost()); - assertEquals(Integer.valueOf(9090), properties.getPort()); + assertThat(properties.getHost()).isEqualTo("192.168.0.1"); + assertThat(properties.getPort()).isEqualTo(Integer.valueOf(9090)); } @Test @@ -84,8 +84,8 @@ public class SamplePropertyValidationApplicationTests { "sample.port:9090"); this.context.refresh(); SampleProperties properties = this.context.getBean(SampleProperties.class); - assertEquals("192.168.0.1", properties.getHost()); - assertEquals(Integer.valueOf(9090), properties.getPort()); + assertThat(properties.getHost()).isEqualTo("192.168.0.1"); + assertThat(properties.getPort()).isEqualTo(Integer.valueOf(9090)); } } diff --git a/spring-boot-samples/spring-boot-sample-secure-oauth2/src/test/java/sample/secure/oauth2/SampleSecureOAuth2ApplicationTests.java b/spring-boot-samples/spring-boot-sample-secure-oauth2/src/test/java/sample/secure/oauth2/SampleSecureOAuth2ApplicationTests.java index 49c2f3d297..92a5c352f3 100644 --- a/spring-boot-samples/spring-boot-sample-secure-oauth2/src/test/java/sample/secure/oauth2/SampleSecureOAuth2ApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-secure-oauth2/src/test/java/sample/secure/oauth2/SampleSecureOAuth2ApplicationTests.java @@ -20,8 +20,7 @@ import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MvcResult; import org.springframework.web.context.WebApplicationContext; -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.MatcherAssert.assertThat; +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.post; import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; @@ -100,11 +99,11 @@ public class SampleSecureOAuth2ApplicationTests { Flight flight = this.objectMapper.readValue( flightsAction.getResponse().getContentAsString(), Flight.class); - assertThat(flight.getOrigin(), is("Nashville")); - assertThat(flight.getDestination(), is("Dallas")); - assertThat(flight.getAirline(), is("Spring Ways")); - assertThat(flight.getFlightNumber(), is("OAUTH2")); - assertThat(flight.getTraveler(), is("Greg Turnquist")); + assertThat(flight.getOrigin()).isEqualTo("Nashville"); + assertThat(flight.getDestination()).isEqualTo("Dallas"); + assertThat(flight.getAirline()).isEqualTo("Spring Ways"); + assertThat(flight.getFlightNumber()).isEqualTo("OAUTH2"); + assertThat(flight.getTraveler()).isEqualTo("Greg Turnquist"); } } diff --git a/spring-boot-samples/spring-boot-sample-secure/src/test/java/sample/secure/SampleSecureApplicationTests.java b/spring-boot-samples/spring-boot-sample-secure/src/test/java/sample/secure/SampleSecureApplicationTests.java index 689da7112f..6eed7b6d12 100644 --- a/spring-boot-samples/spring-boot-sample-secure/src/test/java/sample/secure/SampleSecureApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-secure/src/test/java/sample/secure/SampleSecureApplicationTests.java @@ -35,7 +35,7 @@ import org.springframework.security.core.AuthenticationException; import org.springframework.security.core.context.SecurityContextHolder; 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. @@ -70,25 +70,25 @@ public class SampleSecureApplicationTests { @Test(expected = AuthenticationException.class) public void secure() throws Exception { - assertEquals(this.service.secure(), "Hello Security"); + assertThat("Hello Security").isEqualTo(this.service.secure()); } @Test public void authenticated() throws Exception { SecurityContextHolder.getContext().setAuthentication(this.authentication); - assertEquals(this.service.secure(), "Hello Security"); + assertThat("Hello Security").isEqualTo(this.service.secure()); } @Test public void preauth() throws Exception { SecurityContextHolder.getContext().setAuthentication(this.authentication); - assertEquals(this.service.authorized(), "Hello World"); + assertThat("Hello World").isEqualTo(this.service.authorized()); } @Test(expected = AccessDeniedException.class) public void denied() throws Exception { SecurityContextHolder.getContext().setAuthentication(this.authentication); - assertEquals(this.service.denied(), "Goodbye World"); + assertThat("Goodbye World").isEqualTo(this.service.denied()); } @PropertySource("classpath:test.properties") diff --git a/spring-boot-samples/spring-boot-sample-servlet/src/test/java/sample/servlet/SampleServletApplicationTests.java b/spring-boot-samples/spring-boot-sample-servlet/src/test/java/sample/servlet/SampleServletApplicationTests.java index 2b727d7b95..b206aac81c 100644 --- a/spring-boot-samples/spring-boot-sample-servlet/src/test/java/sample/servlet/SampleServletApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-servlet/src/test/java/sample/servlet/SampleServletApplicationTests.java @@ -30,7 +30,7 @@ import org.springframework.http.ResponseEntity; import org.springframework.test.annotation.DirtiesContext; 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. @@ -53,15 +53,15 @@ public class SampleServletApplicationTests { public void testHomeIsSecure() throws Exception { ResponseEntity<String> entity = new TestRestTemplate() .getForEntity("http://localhost:" + this.port, String.class); - assertEquals(HttpStatus.UNAUTHORIZED, entity.getStatusCode()); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); } @Test public void testHome() throws Exception { ResponseEntity<String> entity = new TestRestTemplate("user", getPassword()) .getForEntity("http://localhost:" + this.port, String.class); - assertEquals(HttpStatus.OK, entity.getStatusCode()); - assertEquals("Hello World", entity.getBody()); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(entity.getBody()).isEqualTo("Hello World"); } private String getPassword() { diff --git a/spring-boot-samples/spring-boot-sample-session-redis/src/test/java/sample/session/redis/SampleSessionRedisApplicationTests.java b/spring-boot-samples/spring-boot-sample-session-redis/src/test/java/sample/session/redis/SampleSessionRedisApplicationTests.java index 3b20c126fa..3a58faeb71 100644 --- a/spring-boot-samples/spring-boot-sample-session-redis/src/test/java/sample/session/redis/SampleSessionRedisApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-session-redis/src/test/java/sample/session/redis/SampleSessionRedisApplicationTests.java @@ -30,10 +30,7 @@ import org.springframework.http.RequestEntity; import org.springframework.http.ResponseEntity; import org.springframework.web.client.RestTemplate; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.not; -import static org.junit.Assert.assertThat; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests for {@link SampleSessionRedisApplication}. @@ -73,12 +70,12 @@ public class SampleSessionRedisApplicationTests { HttpMethod.GET, uri); String uuid2 = restTemplate.exchange(request, String.class).getBody(); - assertThat(uuid1, is(equalTo(uuid2))); + assertThat(uuid1).isEqualTo(uuid2); Thread.sleep(5000); String uuid3 = restTemplate.exchange(request, String.class).getBody(); - assertThat(uuid2, is(not(equalTo(uuid3)))); + assertThat(uuid2).isNotEqualTo(uuid3); } private boolean redisServerRunning(Throwable ex) { diff --git a/spring-boot-samples/spring-boot-sample-simple/src/test/java/sample/simple/SampleSimpleApplicationTests.java b/spring-boot-samples/spring-boot-sample-simple/src/test/java/sample/simple/SampleSimpleApplicationTests.java index e885d91be1..33e47903b2 100644 --- a/spring-boot-samples/spring-boot-sample-simple/src/test/java/sample/simple/SampleSimpleApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-simple/src/test/java/sample/simple/SampleSimpleApplicationTests.java @@ -23,7 +23,7 @@ import org.junit.Test; import org.springframework.boot.test.OutputCapture; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests for {@link SampleSimpleApplication}. @@ -57,14 +57,14 @@ public class SampleSimpleApplicationTests { public void testDefaultSettings() throws Exception { SampleSimpleApplication.main(new String[0]); String output = this.outputCapture.toString(); - assertTrue("Wrong output: " + output, output.contains("Hello Phil")); + assertThat(output).contains("Hello Phil"); } @Test public void testCommandLineOverrides() throws Exception { SampleSimpleApplication.main(new String[] { "--name=Gordon" }); String output = this.outputCapture.toString(); - assertTrue("Wrong output: " + output, output.contains("Hello Gordon")); + assertThat(output).contains("Hello Gordon"); } } diff --git a/spring-boot-samples/spring-boot-sample-simple/src/test/java/sample/simple/SpringTestSampleSimpleApplicationTests.java b/spring-boot-samples/spring-boot-sample-simple/src/test/java/sample/simple/SpringTestSampleSimpleApplicationTests.java index 8a21ea0c39..22988c18a4 100644 --- a/spring-boot-samples/spring-boot-sample-simple/src/test/java/sample/simple/SpringTestSampleSimpleApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-simple/src/test/java/sample/simple/SpringTestSampleSimpleApplicationTests.java @@ -24,8 +24,7 @@ import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.context.ApplicationContext; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * Tests for {@link SampleSimpleApplication}. @@ -41,9 +40,9 @@ public class SpringTestSampleSimpleApplicationTests { @Test public void testContextLoads() throws Exception { - assertNotNull(this.ctx); - assertTrue(this.ctx.containsBean("helloWorldService")); - assertTrue(this.ctx.containsBean("sampleSimpleApplication")); + assertThat(this.ctx).isNotNull(); + assertThat(this.ctx.containsBean("helloWorldService")).isTrue(); + assertThat(this.ctx.containsBean("sampleSimpleApplication")).isTrue(); } } diff --git a/spring-boot-samples/spring-boot-sample-testng/pom.xml b/spring-boot-samples/spring-boot-sample-testng/pom.xml index 85aa584291..5a19a3def2 100644 --- a/spring-boot-samples/spring-boot-sample-testng/pom.xml +++ b/spring-boot-samples/spring-boot-sample-testng/pom.xml @@ -40,6 +40,10 @@ <artifactId>testng</artifactId> <version>6.8.13</version> </dependency> + <dependency> + <groupId>org.assertj</groupId> + <artifactId>assertj-core</artifactId> + </dependency> </dependencies> <build> <plugins> diff --git a/spring-boot-samples/spring-boot-sample-testng/src/test/java/sample/testng/SampleTestNGApplicationTests.java b/spring-boot-samples/spring-boot-sample-testng/src/test/java/sample/testng/SampleTestNGApplicationTests.java index 54f0911c7c..d4c002f479 100644 --- a/spring-boot-samples/spring-boot-sample-testng/src/test/java/sample/testng/SampleTestNGApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-testng/src/test/java/sample/testng/SampleTestNGApplicationTests.java @@ -27,7 +27,7 @@ import org.springframework.http.ResponseEntity; import org.springframework.test.annotation.DirtiesContext; 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. @@ -46,8 +46,8 @@ public class SampleTestNGApplicationTests extends AbstractTestNGSpringContextTes public void testHome() throws Exception { ResponseEntity<String> entity = new TestRestTemplate() .getForEntity("http://localhost:" + this.port, String.class); - assertEquals(HttpStatus.OK, entity.getStatusCode()); - assertEquals("Hello World", entity.getBody()); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(entity.getBody()).isEqualTo("Hello World"); } } diff --git a/spring-boot-samples/spring-boot-sample-tomcat-jsp/src/test/java/sample/tomcat/jsp/SampleWebJspApplicationTests.java b/spring-boot-samples/spring-boot-sample-tomcat-jsp/src/test/java/sample/tomcat/jsp/SampleWebJspApplicationTests.java index 9095087685..18d3df15fd 100644 --- a/spring-boot-samples/spring-boot-sample-tomcat-jsp/src/test/java/sample/tomcat/jsp/SampleWebJspApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-tomcat-jsp/src/test/java/sample/tomcat/jsp/SampleWebJspApplicationTests.java @@ -28,8 +28,7 @@ import org.springframework.http.ResponseEntity; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * Basic integration tests for JSP application. @@ -49,9 +48,8 @@ public class SampleWebJspApplicationTests { public void testJspWithEl() throws Exception { ResponseEntity<String> entity = new TestRestTemplate() .getForEntity("http://localhost:" + this.port, String.class); - assertEquals(HttpStatus.OK, entity.getStatusCode()); - assertTrue("Wrong body:\n" + entity.getBody(), - entity.getBody().contains("/resources/text.txt")); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(entity.getBody()).contains("/resources/text.txt"); } } diff --git a/spring-boot-samples/spring-boot-sample-tomcat-multi-connectors/src/test/java/sample/tomcat/multiconnector/SampleTomcatTwoConnectorsApplicationTests.java b/spring-boot-samples/spring-boot-sample-tomcat-multi-connectors/src/test/java/sample/tomcat/multiconnector/SampleTomcatTwoConnectorsApplicationTests.java index 1199493f2c..84cabbf921 100644 --- a/spring-boot-samples/spring-boot-sample-tomcat-multi-connectors/src/test/java/sample/tomcat/multiconnector/SampleTomcatTwoConnectorsApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-tomcat-multi-connectors/src/test/java/sample/tomcat/multiconnector/SampleTomcatTwoConnectorsApplicationTests.java @@ -42,7 +42,7 @@ import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; 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}. @@ -111,13 +111,13 @@ public class SampleTomcatTwoConnectorsApplicationTests { ResponseEntity<String> entity = template.getForEntity( "http://localhost:" + this.context.getBean("port") + "/hello", String.class); - assertEquals(HttpStatus.OK, entity.getStatusCode()); - assertEquals("hello", entity.getBody()); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(entity.getBody()).isEqualTo("hello"); ResponseEntity<String> httpsEntity = template .getForEntity("https://localhost:" + this.port + "/hello", String.class); - assertEquals(HttpStatus.OK, httpsEntity.getStatusCode()); - assertEquals("hello", httpsEntity.getBody()); + assertThat(httpsEntity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(httpsEntity.getBody()).isEqualTo("hello"); } diff --git a/spring-boot-samples/spring-boot-sample-tomcat-ssl/src/test/java/sample/tomcat/SampleTomcatSslApplicationTests.java b/spring-boot-samples/spring-boot-sample-tomcat-ssl/src/test/java/sample/tomcat/SampleTomcatSslApplicationTests.java index e158130a49..4b353b472b 100644 --- a/spring-boot-samples/spring-boot-sample-tomcat-ssl/src/test/java/sample/tomcat/SampleTomcatSslApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-tomcat-ssl/src/test/java/sample/tomcat/SampleTomcatSslApplicationTests.java @@ -23,19 +23,19 @@ import org.apache.http.impl.client.HttpClients; import org.apache.http.ssl.SSLContextBuilder; import org.junit.Test; import org.junit.runner.RunWith; -import org.springframework.boot.test.WebIntegrationTest; import sample.tomcat.ssl.SampleTomcatSslApplication; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.TestRestTemplate; +import org.springframework.boot.test.WebIntegrationTest; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import static org.junit.Assert.assertEquals; +import static org.assertj.core.api.Assertions.assertThat; @RunWith(SpringJUnit4ClassRunner.class) @SpringApplicationConfiguration(SampleTomcatSslApplication.class) @@ -60,8 +60,8 @@ public class SampleTomcatSslApplicationTests { .setHttpClient(httpClient); ResponseEntity<String> entity = testRestTemplate .getForEntity("https://localhost:" + this.port, String.class); - assertEquals(HttpStatus.OK, entity.getStatusCode()); - assertEquals("Hello, world", entity.getBody()); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(entity.getBody()).isEqualTo("Hello, world"); } } diff --git a/spring-boot-samples/spring-boot-sample-tomcat/src/test/java/sample/tomcat/NonAutoConfigurationSampleTomcatApplicationTests.java b/spring-boot-samples/spring-boot-sample-tomcat/src/test/java/sample/tomcat/NonAutoConfigurationSampleTomcatApplicationTests.java index bf706d8bcb..5aba54cf4a 100644 --- a/spring-boot-samples/spring-boot-sample-tomcat/src/test/java/sample/tomcat/NonAutoConfigurationSampleTomcatApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-tomcat/src/test/java/sample/tomcat/NonAutoConfigurationSampleTomcatApplicationTests.java @@ -18,7 +18,6 @@ package sample.tomcat; import org.junit.Test; import org.junit.runner.RunWith; -import org.springframework.boot.test.WebIntegrationTest; import sample.tomcat.NonAutoConfigurationSampleTomcatApplicationTests.NonAutoConfigurationSampleTomcatApplication; import sample.tomcat.service.HelloWorldService; import sample.tomcat.web.SampleController; @@ -33,6 +32,7 @@ import org.springframework.boot.autoconfigure.web.ServerPropertiesAutoConfigurat import org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration; import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.TestRestTemplate; +import org.springframework.boot.test.WebIntegrationTest; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; @@ -41,7 +41,7 @@ import org.springframework.http.ResponseEntity; import org.springframework.test.annotation.DirtiesContext; 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. @@ -77,8 +77,8 @@ public class NonAutoConfigurationSampleTomcatApplicationTests { public void testHome() throws Exception { ResponseEntity<String> entity = new TestRestTemplate() .getForEntity("http://localhost:" + this.port, String.class); - assertEquals(HttpStatus.OK, entity.getStatusCode()); - assertEquals("Hello World", entity.getBody()); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(entity.getBody()).isEqualTo("Hello World"); } } diff --git a/spring-boot-samples/spring-boot-sample-tomcat/src/test/java/sample/tomcat/SampleTomcatApplicationTests.java b/spring-boot-samples/spring-boot-sample-tomcat/src/test/java/sample/tomcat/SampleTomcatApplicationTests.java index 944ca61f80..88ed4cc4e9 100644 --- a/spring-boot-samples/spring-boot-sample-tomcat/src/test/java/sample/tomcat/SampleTomcatApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-tomcat/src/test/java/sample/tomcat/SampleTomcatApplicationTests.java @@ -37,7 +37,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.util.StreamUtils; 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. @@ -58,8 +58,8 @@ public class SampleTomcatApplicationTests { public void testHome() throws Exception { ResponseEntity<String> entity = new TestRestTemplate() .getForEntity("http://localhost:" + this.port, String.class); - assertEquals(HttpStatus.OK, entity.getStatusCode()); - assertEquals("Hello World", entity.getBody()); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(entity.getBody()).isEqualTo("Hello World"); } @Test @@ -71,12 +71,12 @@ public class SampleTomcatApplicationTests { ResponseEntity<byte[]> entity = restTemplate.exchange( "http://localhost:" + this.port, HttpMethod.GET, requestEntity, byte[].class); - assertEquals(HttpStatus.OK, entity.getStatusCode()); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); GZIPInputStream inflater = new GZIPInputStream( new ByteArrayInputStream(entity.getBody())); try { - assertEquals("Hello World", - StreamUtils.copyToString(inflater, Charset.forName("UTF-8"))); + assertThat(StreamUtils.copyToString(inflater, Charset.forName("UTF-8"))) + .isEqualTo("Hello World"); } finally { inflater.close(); diff --git a/spring-boot-samples/spring-boot-sample-tomcat7-jsp/src/test/java/sample/tomcat7/jsp/SampleWebJspApplicationTests.java b/spring-boot-samples/spring-boot-sample-tomcat7-jsp/src/test/java/sample/tomcat7/jsp/SampleWebJspApplicationTests.java index d55e19afa1..26877e8bbd 100644 --- a/spring-boot-samples/spring-boot-sample-tomcat7-jsp/src/test/java/sample/tomcat7/jsp/SampleWebJspApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-tomcat7-jsp/src/test/java/sample/tomcat7/jsp/SampleWebJspApplicationTests.java @@ -28,8 +28,7 @@ import org.springframework.http.ResponseEntity; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * Basic integration tests for JSP application. @@ -49,9 +48,8 @@ public class SampleWebJspApplicationTests { public void testJspWithEl() throws Exception { ResponseEntity<String> entity = new TestRestTemplate() .getForEntity("http://localhost:" + this.port, String.class); - assertEquals(HttpStatus.OK, entity.getStatusCode()); - assertTrue("Wrong body:\n" + entity.getBody(), - entity.getBody().contains("/resources/text.txt")); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(entity.getBody()).contains("/resources/text.txt"); } } diff --git a/spring-boot-samples/spring-boot-sample-traditional/src/test/java/sample/traditional/SampleTraditionalApplicationTests.java b/spring-boot-samples/spring-boot-sample-traditional/src/test/java/sample/traditional/SampleTraditionalApplicationTests.java index 8a84bffa77..0ae8fef537 100644 --- a/spring-boot-samples/spring-boot-sample-traditional/src/test/java/sample/traditional/SampleTraditionalApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-traditional/src/test/java/sample/traditional/SampleTraditionalApplicationTests.java @@ -28,8 +28,7 @@ import org.springframework.http.ResponseEntity; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * Basic integration tests for demo application. @@ -49,20 +48,18 @@ public class SampleTraditionalApplicationTests { public void testHomeJsp() throws Exception { ResponseEntity<String> entity = new TestRestTemplate() .getForEntity("http://localhost:" + this.port, String.class); - assertEquals(HttpStatus.OK, entity.getStatusCode()); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); String body = entity.getBody(); - assertTrue("Wrong body:\n" + body, body.contains("<html>")); - assertTrue("Wrong body:\n" + body, body.contains("<h1>Home</h1>")); + assertThat(body).contains("<html>").contains("<h1>Home</h1>"); } @Test public void testStaticPage() throws Exception { ResponseEntity<String> entity = new TestRestTemplate().getForEntity( "http://localhost:" + this.port + "/index.html", String.class); - assertEquals(HttpStatus.OK, entity.getStatusCode()); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); String body = entity.getBody(); - assertTrue("Wrong body:\n" + body, body.contains("<html>")); - assertTrue("Wrong body:\n" + body, body.contains("<h1>Hello</h1>")); + assertThat(body).contains("<html>").contains("<h1>Hello</h1>"); } } diff --git a/spring-boot-samples/spring-boot-sample-undertow-ssl/src/test/java/sample/undertow/ssl/SampleUndertowSslApplicationTests.java b/spring-boot-samples/spring-boot-sample-undertow-ssl/src/test/java/sample/undertow/ssl/SampleUndertowSslApplicationTests.java index 63f0ecf3a5..892efc110e 100644 --- a/spring-boot-samples/spring-boot-sample-undertow-ssl/src/test/java/sample/undertow/ssl/SampleUndertowSslApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-undertow-ssl/src/test/java/sample/undertow/ssl/SampleUndertowSslApplicationTests.java @@ -34,7 +34,7 @@ import org.springframework.http.client.HttpComponentsClientHttpRequestFactory; import org.springframework.test.annotation.DirtiesContext; 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. @@ -64,8 +64,8 @@ public class SampleUndertowSslApplicationTests { .setHttpClient(httpClient); ResponseEntity<String> entity = testRestTemplate .getForEntity("https://localhost:" + this.port, String.class); - assertEquals(HttpStatus.OK, entity.getStatusCode()); - assertEquals("Hello World", entity.getBody()); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(entity.getBody()).isEqualTo("Hello World"); } } diff --git a/spring-boot-samples/spring-boot-sample-undertow/src/test/java/sample/undertow/SampleUndertowApplicationTests.java b/spring-boot-samples/spring-boot-sample-undertow/src/test/java/sample/undertow/SampleUndertowApplicationTests.java index cba1eff262..a57ad05271 100644 --- a/spring-boot-samples/spring-boot-sample-undertow/src/test/java/sample/undertow/SampleUndertowApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-undertow/src/test/java/sample/undertow/SampleUndertowApplicationTests.java @@ -37,7 +37,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.util.StreamUtils; 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. @@ -73,12 +73,12 @@ public class SampleUndertowApplicationTests { ResponseEntity<byte[]> entity = restTemplate.exchange( "http://localhost:" + this.port, HttpMethod.GET, requestEntity, byte[].class); - assertEquals(HttpStatus.OK, entity.getStatusCode()); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); GZIPInputStream inflater = new GZIPInputStream( new ByteArrayInputStream(entity.getBody())); try { - assertEquals("Hello World", - StreamUtils.copyToString(inflater, Charset.forName("UTF-8"))); + assertThat(StreamUtils.copyToString(inflater, Charset.forName("UTF-8"))) + .isEqualTo("Hello World"); } finally { inflater.close(); @@ -88,8 +88,8 @@ public class SampleUndertowApplicationTests { private void assertOkResponse(String path, String body) { ResponseEntity<String> entity = new TestRestTemplate() .getForEntity("http://localhost:" + this.port + path, String.class); - assertEquals(HttpStatus.OK, entity.getStatusCode()); - assertEquals(body, entity.getBody()); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(entity.getBody()).isEqualTo(body); } } diff --git a/spring-boot-samples/spring-boot-sample-velocity/src/test/java/sample/velocity/SampleVelocityApplicationTests.java b/spring-boot-samples/spring-boot-sample-velocity/src/test/java/sample/velocity/SampleVelocityApplicationTests.java index 94dcbac26a..f1cb56bbbb 100644 --- a/spring-boot-samples/spring-boot-sample-velocity/src/test/java/sample/velocity/SampleVelocityApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-velocity/src/test/java/sample/velocity/SampleVelocityApplicationTests.java @@ -24,7 +24,7 @@ import org.springframework.boot.test.OutputCapture; import org.springframework.boot.test.SpringApplicationConfiguration; 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. @@ -41,7 +41,7 @@ public class SampleVelocityApplicationTests { @Test public void testVelocityTemplate() throws Exception { String result = SampleVelocityApplicationTests.output.toString(); - assertTrue("Wrong output: " + result, result.contains("Hello, Andy")); + assertThat(result).contains("Hello, Andy"); } } diff --git a/spring-boot-samples/spring-boot-sample-web-freemarker/src/test/java/sample/freemarker/SampleWebFreeMarkerApplicationTests.java b/spring-boot-samples/spring-boot-sample-web-freemarker/src/test/java/sample/freemarker/SampleWebFreeMarkerApplicationTests.java index 3cdca9c8d4..85c6b6ef09 100644 --- a/spring-boot-samples/spring-boot-sample-web-freemarker/src/test/java/sample/freemarker/SampleWebFreeMarkerApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-web-freemarker/src/test/java/sample/freemarker/SampleWebFreeMarkerApplicationTests.java @@ -34,8 +34,7 @@ import org.springframework.http.ResponseEntity; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * Basic integration tests for FreeMarker application. @@ -55,10 +54,9 @@ public class SampleWebFreeMarkerApplicationTests { @Test public void testFreeMarkerTemplate() throws Exception { ResponseEntity<String> entity = new TestRestTemplate() - .getForEntity("http://localhost:" + port, String.class); - assertEquals(HttpStatus.OK, entity.getStatusCode()); - assertTrue("Wrong body:\n" + entity.getBody(), - entity.getBody().contains("Hello, Andy")); + .getForEntity("http://localhost:" + this.port, String.class); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(entity.getBody()).contains("Hello, Andy"); } @Test @@ -68,12 +66,12 @@ public class SampleWebFreeMarkerApplicationTests { HttpEntity<String> requestEntity = new HttpEntity<String>(headers); 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); - assertEquals(HttpStatus.NOT_FOUND, responseEntity.getStatusCode()); - assertTrue("Wrong body:\n" + responseEntity.getBody(), - responseEntity.getBody().contains("Something went wrong: 404 Not Found")); + assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND); + assertThat(responseEntity.getBody()) + .contains("Something went wrong: 404 Not Found"); } } diff --git a/spring-boot-samples/spring-boot-sample-web-groovy-templates/src/test/java/sample/groovytemplates/SampleGroovyTemplateApplicationTests.java b/spring-boot-samples/spring-boot-sample-web-groovy-templates/src/test/java/sample/groovytemplates/SampleGroovyTemplateApplicationTests.java index 19cec7ce8d..c4f16b87d2 100644 --- a/spring-boot-samples/spring-boot-sample-web-groovy-templates/src/test/java/sample/groovytemplates/SampleGroovyTemplateApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-web-groovy-templates/src/test/java/sample/groovytemplates/SampleGroovyTemplateApplicationTests.java @@ -32,9 +32,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * Basic integration tests for demo application. @@ -54,11 +52,9 @@ public class SampleGroovyTemplateApplicationTests { public void testHome() throws Exception { ResponseEntity<String> entity = new TestRestTemplate() .getForEntity("http://localhost:" + this.port, String.class); - assertEquals(HttpStatus.OK, entity.getStatusCode()); - assertTrue("Wrong body (title doesn't match):\n" + entity.getBody(), - entity.getBody().contains("<title>Messages")); - assertFalse("Wrong body (found layout:fragment):\n" + entity.getBody(), - entity.getBody().contains("layout:fragment")); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(entity.getBody()).contains("<title>Messages"); + assertThat(entity.getBody()).doesNotContain("layout:fragment"); } @Test @@ -68,16 +64,15 @@ public class SampleGroovyTemplateApplicationTests { map.set("summary", "FOO"); URI location = new TestRestTemplate() .postForLocation("http://localhost:" + this.port, map); - assertTrue("Wrong location:\n" + location, - location.toString().contains("localhost:" + this.port)); + assertThat(location.toString()).contains("localhost:" + this.port); } @Test public void testCss() throws Exception { ResponseEntity<String> entity = new TestRestTemplate().getForEntity( "http://localhost:" + this.port + "/css/bootstrap.min.css", String.class); - assertEquals(HttpStatus.OK, entity.getStatusCode()); - assertTrue("Wrong body:\n" + entity.getBody(), entity.getBody().contains("body")); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(entity.getBody()).contains("body"); } } diff --git a/spring-boot-samples/spring-boot-sample-web-jsp/src/test/java/sample/jsp/SampleWebJspApplicationTests.java b/spring-boot-samples/spring-boot-sample-web-jsp/src/test/java/sample/jsp/SampleWebJspApplicationTests.java index 37a0cbbd0e..2b16f8fe12 100644 --- a/spring-boot-samples/spring-boot-sample-web-jsp/src/test/java/sample/jsp/SampleWebJspApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-web-jsp/src/test/java/sample/jsp/SampleWebJspApplicationTests.java @@ -28,8 +28,7 @@ import org.springframework.http.ResponseEntity; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * Basic integration tests for JSP application. @@ -49,9 +48,8 @@ public class SampleWebJspApplicationTests { public void testJspWithEl() throws Exception { ResponseEntity<String> entity = new TestRestTemplate() .getForEntity("http://localhost:" + this.port, String.class); - assertEquals(HttpStatus.OK, entity.getStatusCode()); - assertTrue("Wrong body:\n" + entity.getBody(), - entity.getBody().contains("/resources/text.txt")); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(entity.getBody()).contains("/resources/text.txt"); } } diff --git a/spring-boot-samples/spring-boot-sample-web-method-security/src/test/java/sample/security/method/SampleMethodSecurityApplicationTests.java b/spring-boot-samples/spring-boot-sample-web-method-security/src/test/java/sample/security/method/SampleMethodSecurityApplicationTests.java index 022a2e6803..7687e3a157 100644 --- a/spring-boot-samples/spring-boot-sample-web-method-security/src/test/java/sample/security/method/SampleMethodSecurityApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-web-method-security/src/test/java/sample/security/method/SampleMethodSecurityApplicationTests.java @@ -38,8 +38,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * Basic integration tests for demo application. @@ -62,9 +61,8 @@ public class SampleMethodSecurityApplicationTests { ResponseEntity<String> entity = new TestRestTemplate().exchange( "http://localhost:" + this.port, HttpMethod.GET, new HttpEntity<Void>(headers), String.class); - assertEquals(HttpStatus.OK, entity.getStatusCode()); - assertTrue("Wrong body (title doesn't match):\n" + entity.getBody(), - entity.getBody().contains("<title>Login")); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(entity.getBody()).contains("<title>Login"); } @Test @@ -79,9 +77,9 @@ public class SampleMethodSecurityApplicationTests { "http://localhost:" + this.port + "/login", HttpMethod.POST, new HttpEntity<MultiValueMap<String, String>>(form, headers), String.class); - assertEquals(HttpStatus.FOUND, entity.getStatusCode()); - assertEquals("http://localhost:" + this.port + "/", - entity.getHeaders().getLocation().toString()); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.FOUND); + assertThat(entity.getHeaders().getLocation().toString()) + .isEqualTo("http://localhost:" + this.port + "/"); } @Test @@ -96,36 +94,35 @@ public class SampleMethodSecurityApplicationTests { "http://localhost:" + this.port + "/login", HttpMethod.POST, new HttpEntity<MultiValueMap<String, String>>(form, headers), String.class); - assertEquals(HttpStatus.FOUND, entity.getStatusCode()); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.FOUND); String cookie = entity.getHeaders().getFirst("Set-Cookie"); headers.set("Cookie", cookie); ResponseEntity<String> page = new TestRestTemplate().exchange( entity.getHeaders().getLocation(), HttpMethod.GET, new HttpEntity<Void>(headers), String.class); - assertEquals(HttpStatus.FORBIDDEN, page.getStatusCode()); - assertTrue("Wrong body (message doesn't match):\n" + entity.getBody(), - page.getBody().contains("Access denied")); + assertThat(page.getStatusCode()).isEqualTo(HttpStatus.FORBIDDEN); + assertThat(page.getBody()).contains("Access denied"); } @Test public void testManagementProtected() throws Exception { ResponseEntity<String> entity = new TestRestTemplate() .getForEntity("http://localhost:" + this.port + "/beans", String.class); - assertEquals(HttpStatus.UNAUTHORIZED, entity.getStatusCode()); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.UNAUTHORIZED); } @Test public void testManagementAuthorizedAccess() throws Exception { ResponseEntity<String> entity = new TestRestTemplate("admin", "admin") .getForEntity("http://localhost:" + this.port + "/beans", String.class); - assertEquals(HttpStatus.OK, entity.getStatusCode()); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); } @Test public void testManagementUnauthorizedAccess() throws Exception { ResponseEntity<String> entity = new TestRestTemplate("user", "user") .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) { diff --git a/spring-boot-samples/spring-boot-sample-web-mustache/src/test/java/sample/mustache/SampleWebMustacheApplicationTests.java b/spring-boot-samples/spring-boot-sample-web-mustache/src/test/java/sample/mustache/SampleWebMustacheApplicationTests.java index f7c6f0b162..7dfeb7b977 100644 --- a/spring-boot-samples/spring-boot-sample-web-mustache/src/test/java/sample/mustache/SampleWebMustacheApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-web-mustache/src/test/java/sample/mustache/SampleWebMustacheApplicationTests.java @@ -34,8 +34,7 @@ import org.springframework.http.ResponseEntity; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * Basic integration tests for Mustache application. @@ -56,9 +55,8 @@ public class SampleWebMustacheApplicationTests { public void testMustacheTemplate() throws Exception { ResponseEntity<String> entity = new TestRestTemplate() .getForEntity("http://localhost:" + this.port, String.class); - assertEquals(HttpStatus.OK, entity.getStatusCode()); - assertTrue("Wrong body:\n" + entity.getBody(), - entity.getBody().contains("Hello, Andy")); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(entity.getBody()).contains("Hello, Andy"); } @Test @@ -71,9 +69,9 @@ public class SampleWebMustacheApplicationTests { "http://localhost:" + this.port + "/does-not-exist", HttpMethod.GET, requestEntity, String.class); - assertEquals(HttpStatus.NOT_FOUND, responseEntity.getStatusCode()); - assertTrue("Wrong body:\n" + responseEntity.getBody(), - responseEntity.getBody().contains("Something went wrong: 404 Not Found")); + assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND); + assertThat(responseEntity.getBody()) + .contains("Something went wrong: 404 Not Found"); } } diff --git a/spring-boot-samples/spring-boot-sample-web-secure-custom/src/test/java/sample/ui/secure/SampleWebSecureCustomApplicationTests.java b/spring-boot-samples/spring-boot-sample-web-secure-custom/src/test/java/sample/ui/secure/SampleWebSecureCustomApplicationTests.java index 7e87264c4c..263169a389 100644 --- a/spring-boot-samples/spring-boot-sample-web-secure-custom/src/test/java/sample/ui/secure/SampleWebSecureCustomApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-web-secure-custom/src/test/java/sample/ui/secure/SampleWebSecureCustomApplicationTests.java @@ -22,12 +22,12 @@ import java.util.regex.Pattern; import org.junit.Test; import org.junit.runner.RunWith; -import org.springframework.boot.test.WebIntegrationTest; import sample.web.secure.custom.SampleWebSecureCustomApplication; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.TestRestTemplate; +import org.springframework.boot.test.WebIntegrationTest; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; @@ -39,9 +39,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * Basic integration tests for demo application. @@ -64,9 +62,9 @@ public class SampleWebSecureCustomApplicationTests { ResponseEntity<String> entity = new TestRestTemplate().exchange( "http://localhost:" + this.port, HttpMethod.GET, new HttpEntity<Void>(headers), String.class); - assertEquals(HttpStatus.FOUND, entity.getStatusCode()); - assertTrue("Wrong location:\n" + entity.getHeaders(), - entity.getHeaders().getLocation().toString().endsWith(port + "/login")); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.FOUND); + assertThat(entity.getHeaders().getLocation().toString()) + .endsWith(this.port + "/login"); } @Test @@ -76,9 +74,8 @@ public class SampleWebSecureCustomApplicationTests { ResponseEntity<String> entity = new TestRestTemplate().exchange( "http://localhost:" + this.port + "/login", HttpMethod.GET, new HttpEntity<Void>(headers), String.class); - assertEquals(HttpStatus.OK, entity.getStatusCode()); - assertTrue("Wrong content:\n" + entity.getBody(), - entity.getBody().contains("_csrf")); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(entity.getBody()).contains("_csrf"); } @Test @@ -93,23 +90,22 @@ public class SampleWebSecureCustomApplicationTests { "http://localhost:" + this.port + "/login", HttpMethod.POST, new HttpEntity<MultiValueMap<String, String>>(form, headers), String.class); - assertEquals(HttpStatus.FOUND, entity.getStatusCode()); - assertTrue("Wrong location:\n" + entity.getHeaders(), - entity.getHeaders().getLocation().toString().endsWith(port + "/")); - assertNotNull("Missing cookie:\n" + entity.getHeaders(), - entity.getHeaders().get("Set-Cookie")); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.FOUND); + assertThat(entity.getHeaders().getLocation().toString()) + .endsWith(this.port + "/"); + assertThat(entity.getHeaders().get("Set-Cookie")).isNotNull(); } private HttpHeaders getHeaders() { HttpHeaders headers = new HttpHeaders(); ResponseEntity<String> page = new TestRestTemplate() .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"); headers.set("Cookie", cookie); - Matcher matcher = Pattern.compile("(?s).*name=\"_csrf\".*?value=\"([^\"]+).*") - .matcher(page.getBody()); - assertTrue("No csrf token: " + page.getBody(), matcher.matches()); + Pattern pattern = Pattern.compile("(?s).*name=\"_csrf\".*?value=\"([^\"]+).*"); + Matcher matcher = pattern.matcher(page.getBody()); + assertThat(matcher.matches()).as(page.getBody()).isTrue(); headers.set("X-CSRF-TOKEN", matcher.group(1)); return headers; } @@ -118,8 +114,8 @@ public class SampleWebSecureCustomApplicationTests { public void testCss() throws Exception { ResponseEntity<String> entity = new TestRestTemplate().getForEntity( "http://localhost:" + this.port + "/css/bootstrap.min.css", String.class); - assertEquals(HttpStatus.OK, entity.getStatusCode()); - assertTrue("Wrong body:\n" + entity.getBody(), entity.getBody().contains("body")); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(entity.getBody()).contains("body"); } } diff --git a/spring-boot-samples/spring-boot-sample-web-secure-github/src/test/java/sample/web/secure/github/SampleGithubApplicationTests.java b/spring-boot-samples/spring-boot-sample-web-secure-github/src/test/java/sample/web/secure/github/SampleGithubApplicationTests.java index 8964d41044..d206331121 100644 --- a/spring-boot-samples/spring-boot-sample-web-secure-github/src/test/java/sample/web/secure/github/SampleGithubApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-web-secure-github/src/test/java/sample/web/secure/github/SampleGithubApplicationTests.java @@ -30,10 +30,7 @@ import org.springframework.http.ResponseEntity; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.startsWith; -import static org.junit.Assert.assertThat; +import static org.assertj.core.api.Assertions.assertThat; /** * Basic integration tests for GitHub SSO application. @@ -55,9 +52,9 @@ public class SampleGithubApplicationTests { TestRestTemplate restTemplate = new TestRestTemplate(); ResponseEntity<Void> entity = restTemplate .getForEntity("http://localhost:" + this.port, Void.class); - assertThat(entity.getStatusCode(), is(HttpStatus.FOUND)); - assertThat(entity.getHeaders().getLocation(), - is(equalTo(URI.create("http://localhost:" + this.port + "/login")))); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.FOUND); + assertThat(entity.getHeaders().getLocation()) + .isEqualTo(URI.create("http://localhost:" + this.port + "/login")); } @Test @@ -65,9 +62,9 @@ public class SampleGithubApplicationTests { TestRestTemplate restTemplate = new TestRestTemplate(); ResponseEntity<Void> entity = restTemplate .getForEntity("http://localhost:" + this.port + "/login", Void.class); - assertThat(entity.getStatusCode(), is(HttpStatus.FOUND)); - assertThat(entity.getHeaders().getLocation().toString(), - startsWith("https://github.com/login/oauth")); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.FOUND); + assertThat(entity.getHeaders().getLocation().toString()) + .startsWith("https://github.com/login/oauth"); } } diff --git a/spring-boot-samples/spring-boot-sample-web-secure-jdbc/src/test/java/sample/web/secure/jdbc/SampleWebSecureCustomApplicationTests.java b/spring-boot-samples/spring-boot-sample-web-secure-jdbc/src/test/java/sample/web/secure/jdbc/SampleWebSecureCustomApplicationTests.java index eba294b82d..62cb371c61 100644 --- a/spring-boot-samples/spring-boot-sample-web-secure-jdbc/src/test/java/sample/web/secure/jdbc/SampleWebSecureCustomApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-web-secure-jdbc/src/test/java/sample/web/secure/jdbc/SampleWebSecureCustomApplicationTests.java @@ -38,9 +38,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * Basic integration tests for demo application. @@ -63,9 +61,9 @@ public class SampleWebSecureCustomApplicationTests { ResponseEntity<String> entity = new TestRestTemplate().exchange( "http://localhost:" + this.port, HttpMethod.GET, new HttpEntity<Void>(headers), String.class); - assertEquals(HttpStatus.FOUND, entity.getStatusCode()); - assertTrue("Wrong location:\n" + entity.getHeaders(), - entity.getHeaders().getLocation().toString().endsWith(port + "/login")); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.FOUND); + assertThat(entity.getHeaders().getLocation().toString()) + .endsWith(this.port + "/login"); } @Test @@ -75,9 +73,8 @@ public class SampleWebSecureCustomApplicationTests { ResponseEntity<String> entity = new TestRestTemplate().exchange( "http://localhost:" + this.port + "/login", HttpMethod.GET, new HttpEntity<Void>(headers), String.class); - assertEquals(HttpStatus.OK, entity.getStatusCode()); - assertTrue("Wrong content:\n" + entity.getBody(), - entity.getBody().contains("_csrf")); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(entity.getBody()).contains("_csrf"); } @Test @@ -92,23 +89,22 @@ public class SampleWebSecureCustomApplicationTests { "http://localhost:" + this.port + "/login", HttpMethod.POST, new HttpEntity<MultiValueMap<String, String>>(form, headers), String.class); - assertEquals(HttpStatus.FOUND, entity.getStatusCode()); - assertTrue("Wrong location:\n" + entity.getHeaders(), - entity.getHeaders().getLocation().toString().endsWith(port + "/")); - assertNotNull("Missing cookie:\n" + entity.getHeaders(), - entity.getHeaders().get("Set-Cookie")); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.FOUND); + assertThat(entity.getHeaders().getLocation().toString()) + .endsWith(this.port + "/"); + assertThat(entity.getHeaders().get("Set-Cookie")).isNotNull(); } private HttpHeaders getHeaders() { HttpHeaders headers = new HttpHeaders(); ResponseEntity<String> page = new TestRestTemplate() .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"); headers.set("Cookie", cookie); - Matcher matcher = Pattern.compile("(?s).*name=\"_csrf\".*?value=\"([^\"]+).*") - .matcher(page.getBody()); - assertTrue("No csrf token: " + page.getBody(), matcher.matches()); + Pattern pattern = Pattern.compile("(?s).*name=\"_csrf\".*?value=\"([^\"]+).*"); + Matcher matcher = pattern.matcher(page.getBody()); + assertThat(matcher.matches()).as(page.getBody()).isTrue(); headers.set("X-CSRF-TOKEN", matcher.group(1)); return headers; } @@ -117,8 +113,8 @@ public class SampleWebSecureCustomApplicationTests { public void testCss() throws Exception { ResponseEntity<String> entity = new TestRestTemplate().getForEntity( "http://localhost:" + this.port + "/css/bootstrap.min.css", String.class); - assertEquals(HttpStatus.OK, entity.getStatusCode()); - assertTrue("Wrong body:\n" + entity.getBody(), entity.getBody().contains("body")); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(entity.getBody()).contains("body"); } } diff --git a/spring-boot-samples/spring-boot-sample-web-secure/src/test/java/sample/web/secure/SampleSecureApplicationTests.java b/spring-boot-samples/spring-boot-sample-web-secure/src/test/java/sample/web/secure/SampleSecureApplicationTests.java index 92948514a2..3f3d6d0624 100644 --- a/spring-boot-samples/spring-boot-sample-web-secure/src/test/java/sample/web/secure/SampleSecureApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-web-secure/src/test/java/sample/web/secure/SampleSecureApplicationTests.java @@ -38,9 +38,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * Basic integration tests for demo application. @@ -63,9 +61,9 @@ public class SampleSecureApplicationTests { ResponseEntity<String> entity = new TestRestTemplate().exchange( "http://localhost:" + this.port, HttpMethod.GET, new HttpEntity<Void>(headers), String.class); - assertEquals(HttpStatus.FOUND, entity.getStatusCode()); - assertTrue("Wrong location:\n" + entity.getHeaders(), - entity.getHeaders().getLocation().toString().endsWith(port + "/login")); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.FOUND); + assertThat(entity.getHeaders().getLocation().toString()) + .endsWith(this.port + "/login"); } @Test @@ -75,9 +73,8 @@ public class SampleSecureApplicationTests { ResponseEntity<String> entity = new TestRestTemplate().exchange( "http://localhost:" + this.port + "/login", HttpMethod.GET, new HttpEntity<Void>(headers), String.class); - assertEquals(HttpStatus.OK, entity.getStatusCode()); - assertTrue("Wrong content:\n" + entity.getBody(), - entity.getBody().contains("_csrf")); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(entity.getBody()).contains("_csrf"); } @Test @@ -92,23 +89,22 @@ public class SampleSecureApplicationTests { "http://localhost:" + this.port + "/login", HttpMethod.POST, new HttpEntity<MultiValueMap<String, String>>(form, headers), String.class); - assertEquals(HttpStatus.FOUND, entity.getStatusCode()); - assertTrue("Wrong location:\n" + entity.getHeaders(), - entity.getHeaders().getLocation().toString().endsWith(port + "/")); - assertNotNull("Missing cookie:\n" + entity.getHeaders(), - entity.getHeaders().get("Set-Cookie")); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.FOUND); + assertThat(entity.getHeaders().getLocation().toString()) + .endsWith(this.port + "/"); + assertThat(entity.getHeaders().get("Set-Cookie")).isNotNull(); } private HttpHeaders getHeaders() { HttpHeaders headers = new HttpHeaders(); ResponseEntity<String> page = new TestRestTemplate() .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"); headers.set("Cookie", cookie); - Matcher matcher = Pattern.compile("(?s).*name=\"_csrf\".*?value=\"([^\"]+).*") - .matcher(page.getBody()); - assertTrue("No csrf token: " + page.getBody(), matcher.matches()); + Pattern pattern = Pattern.compile("(?s).*name=\"_csrf\".*?value=\"([^\"]+).*"); + Matcher matcher = pattern.matcher(page.getBody()); + assertThat(matcher.matches()).as(page.getBody()).isTrue(); headers.set("X-CSRF-TOKEN", matcher.group(1)); return headers; } @@ -117,8 +113,8 @@ public class SampleSecureApplicationTests { public void testCss() throws Exception { ResponseEntity<String> entity = new TestRestTemplate().getForEntity( "http://localhost:" + this.port + "/css/bootstrap.min.css", String.class); - assertEquals(HttpStatus.OK, entity.getStatusCode()); - assertTrue("Wrong body:\n" + entity.getBody(), entity.getBody().contains("body")); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(entity.getBody()).contains("body"); } } diff --git a/spring-boot-samples/spring-boot-sample-web-static/src/test/java/sample/webstatic/SampleWebStaticApplicationTests.java b/spring-boot-samples/spring-boot-sample-web-static/src/test/java/sample/webstatic/SampleWebStaticApplicationTests.java index 037db3756d..dd1285fe27 100644 --- a/spring-boot-samples/spring-boot-sample-web-static/src/test/java/sample/webstatic/SampleWebStaticApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-web-static/src/test/java/sample/webstatic/SampleWebStaticApplicationTests.java @@ -18,20 +18,19 @@ package sample.webstatic; import org.junit.Test; import org.junit.runner.RunWith; -import org.springframework.boot.test.WebIntegrationTest; import sample.web.staticcontent.SampleWebStaticApplication; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.TestRestTemplate; +import org.springframework.boot.test.WebIntegrationTest; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * Basic integration tests for demo application. @@ -51,9 +50,8 @@ public class SampleWebStaticApplicationTests { public void testHome() throws Exception { ResponseEntity<String> entity = new TestRestTemplate() .getForEntity("http://localhost:" + this.port, String.class); - assertEquals(HttpStatus.OK, entity.getStatusCode()); - assertTrue("Wrong body (title doesn't match):\n" + entity.getBody(), - entity.getBody().contains("<title>Static")); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(entity.getBody()).contains("<title>Static"); } @Test @@ -63,11 +61,10 @@ public class SampleWebStaticApplicationTests { "http://localhost:" + this.port + "/webjars/bootstrap/3.0.3/css/bootstrap.min.css", String.class); - assertEquals(HttpStatus.OK, entity.getStatusCode()); - assertTrue("Wrong body:\n" + entity.getBody(), entity.getBody().contains("body")); - assertEquals("Wrong content type:\n" + entity.getHeaders().getContentType(), - MediaType.valueOf("text/css;charset=UTF-8"), - entity.getHeaders().getContentType()); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(entity.getBody()).contains("body"); + assertThat(entity.getHeaders().getContentType()) + .isEqualTo(MediaType.valueOf("text/css;charset=UTF-8")); } } diff --git a/spring-boot-samples/spring-boot-sample-web-ui/src/test/java/sample/ui/SampleWebUiApplicationTests.java b/spring-boot-samples/spring-boot-sample-web-ui/src/test/java/sample/ui/SampleWebUiApplicationTests.java index 2a9cc77b4b..b24c4eb3b3 100644 --- a/spring-boot-samples/spring-boot-sample-web-ui/src/test/java/sample/ui/SampleWebUiApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-web-ui/src/test/java/sample/ui/SampleWebUiApplicationTests.java @@ -20,12 +20,12 @@ import java.net.URI; import org.junit.Test; import org.junit.runner.RunWith; -import org.springframework.boot.test.WebIntegrationTest; import sample.web.ui.SampleWebUiApplication; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.boot.test.TestRestTemplate; +import org.springframework.boot.test.WebIntegrationTest; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.test.annotation.DirtiesContext; @@ -33,9 +33,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.MultiValueMap; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * Basic integration tests for demo application. @@ -55,11 +53,9 @@ public class SampleWebUiApplicationTests { public void testHome() throws Exception { ResponseEntity<String> entity = new TestRestTemplate() .getForEntity("http://localhost:" + this.port, String.class); - assertEquals(HttpStatus.OK, entity.getStatusCode()); - assertTrue("Wrong body (title doesn't match):\n" + entity.getBody(), - entity.getBody().contains("<title>Messages")); - assertFalse("Wrong body (found layout:fragment):\n" + entity.getBody(), - entity.getBody().contains("layout:fragment")); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(entity.getBody()).contains("<title>Messages"); + assertThat(entity.getBody()).doesNotContain("layout:fragment"); } @Test @@ -69,16 +65,15 @@ public class SampleWebUiApplicationTests { map.set("summary", "FOO"); URI location = new TestRestTemplate() .postForLocation("http://localhost:" + this.port, map); - assertTrue("Wrong location:\n" + location, - location.toString().contains("localhost:" + this.port)); + assertThat(location.toString()).contains("localhost:" + this.port); } @Test public void testCss() throws Exception { ResponseEntity<String> entity = new TestRestTemplate().getForEntity( "http://localhost:" + this.port + "/css/bootstrap.min.css", String.class); - assertEquals(HttpStatus.OK, entity.getStatusCode()); - assertTrue("Wrong body:\n" + entity.getBody(), entity.getBody().contains("body")); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(entity.getBody()).contains("body"); } } diff --git a/spring-boot-samples/spring-boot-sample-web-velocity/src/test/java/sample/web/velocity/SampleWebVelocityApplicationTests.java b/spring-boot-samples/spring-boot-sample-web-velocity/src/test/java/sample/web/velocity/SampleWebVelocityApplicationTests.java index 6ea68371bb..4e39dc3b02 100644 --- a/spring-boot-samples/spring-boot-sample-web-velocity/src/test/java/sample/web/velocity/SampleWebVelocityApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-web-velocity/src/test/java/sample/web/velocity/SampleWebVelocityApplicationTests.java @@ -34,8 +34,7 @@ import org.springframework.http.ResponseEntity; import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; /** * Basic integration tests for Velocity application. @@ -56,9 +55,8 @@ public class SampleWebVelocityApplicationTests { public void testVelocityTemplate() throws Exception { ResponseEntity<String> entity = new TestRestTemplate() .getForEntity("http://localhost:" + this.port, String.class); - assertEquals(HttpStatus.OK, entity.getStatusCode()); - assertTrue("Wrong body:\n" + entity.getBody(), - entity.getBody().contains("Hello, Andy")); + assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.OK); + assertThat(entity.getBody()).contains("Hello, Andy"); } @Test @@ -71,9 +69,9 @@ public class SampleWebVelocityApplicationTests { "http://localhost:" + this.port + "/does-not-exist", HttpMethod.GET, requestEntity, String.class); - assertEquals(HttpStatus.NOT_FOUND, responseEntity.getStatusCode()); - assertTrue("Wrong body:\n" + responseEntity.getBody(), - responseEntity.getBody().contains("Something went wrong: 404 Not Found")); + assertThat(responseEntity.getStatusCode()).isEqualTo(HttpStatus.NOT_FOUND); + assertThat(responseEntity.getBody()) + .contains("Something went wrong: 404 Not Found"); } } diff --git a/spring-boot-samples/spring-boot-sample-websocket-jetty/src/test/java/samples/websocket/jetty/SampleWebSocketsApplicationTests.java b/spring-boot-samples/spring-boot-sample-websocket-jetty/src/test/java/samples/websocket/jetty/SampleWebSocketsApplicationTests.java index a104a69961..71afa54ef0 100644 --- a/spring-boot-samples/spring-boot-sample-websocket-jetty/src/test/java/samples/websocket/jetty/SampleWebSocketsApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-websocket-jetty/src/test/java/samples/websocket/jetty/SampleWebSocketsApplicationTests.java @@ -24,7 +24,6 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.junit.Test; import org.junit.runner.RunWith; -import org.springframework.boot.test.WebIntegrationTest; import samples.websocket.jetty.client.GreetingService; import samples.websocket.jetty.client.SimpleClientWebSocketHandler; import samples.websocket.jetty.client.SimpleGreetingService; @@ -34,6 +33,7 @@ import org.springframework.boot.CommandLineRunner; import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.test.SpringApplicationConfiguration; +import org.springframework.boot.test.WebIntegrationTest; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -42,7 +42,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.web.socket.client.WebSocketConnectionManager; 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) @SpringApplicationConfiguration(SampleJettyWebSocketsApplication.class) @@ -66,8 +66,9 @@ public class SampleWebSocketsApplicationTests { AtomicReference<String> messagePayloadReference = context .getBean(ClientConfiguration.class).messagePayload; context.close(); - assertEquals(0, count); - assertEquals("Did you say \"Hello world!\"?", messagePayloadReference.get()); + assertThat(count).isEqualTo(0); + assertThat(messagePayloadReference.get()) + .isEqualTo("Did you say \"Hello world!\"?"); } @Test @@ -81,8 +82,8 @@ public class SampleWebSocketsApplicationTests { AtomicReference<String> messagePayloadReference = context .getBean(ClientConfiguration.class).messagePayload; context.close(); - assertEquals(0, count); - assertEquals("Reversed: !dlrow olleH", messagePayloadReference.get()); + assertThat(count).isEqualTo(0); + assertThat(messagePayloadReference.get()).isEqualTo("Reversed: !dlrow olleH"); } @Configuration diff --git a/spring-boot-samples/spring-boot-sample-websocket-jetty/src/test/java/samples/websocket/jetty/echo/CustomContainerWebSocketsApplicationTests.java b/spring-boot-samples/spring-boot-sample-websocket-jetty/src/test/java/samples/websocket/jetty/echo/CustomContainerWebSocketsApplicationTests.java index 946021bfc3..23476b8c9d 100644 --- a/spring-boot-samples/spring-boot-sample-websocket-jetty/src/test/java/samples/websocket/jetty/echo/CustomContainerWebSocketsApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-websocket-jetty/src/test/java/samples/websocket/jetty/echo/CustomContainerWebSocketsApplicationTests.java @@ -24,7 +24,6 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.junit.Test; import org.junit.runner.RunWith; -import org.springframework.boot.test.WebIntegrationTest; import samples.websocket.jetty.SampleJettyWebSocketsApplication; import samples.websocket.jetty.client.GreetingService; import samples.websocket.jetty.client.SimpleClientWebSocketHandler; @@ -38,6 +37,7 @@ import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory; import org.springframework.boot.context.embedded.jetty.JettyEmbeddedServletContainerFactory; import org.springframework.boot.test.SpringApplicationConfiguration; +import org.springframework.boot.test.WebIntegrationTest; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -47,7 +47,7 @@ import org.springframework.util.SocketUtils; import org.springframework.web.socket.client.WebSocketConnectionManager; 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) @SpringApplicationConfiguration({ SampleJettyWebSocketsApplication.class, @@ -72,8 +72,9 @@ public class CustomContainerWebSocketsApplicationTests { AtomicReference<String> messagePayloadReference = context .getBean(ClientConfiguration.class).messagePayload; context.close(); - assertEquals(0, count); - assertEquals("Did you say \"Hello world!\"?", messagePayloadReference.get()); + assertThat(count).isEqualTo(0); + assertThat(messagePayloadReference.get()) + .isEqualTo("Did you say \"Hello world!\"?"); } @Test @@ -87,8 +88,8 @@ public class CustomContainerWebSocketsApplicationTests { AtomicReference<String> messagePayloadReference = context .getBean(ClientConfiguration.class).messagePayload; context.close(); - assertEquals(0, count); - assertEquals("Reversed: !dlrow olleH", messagePayloadReference.get()); + assertThat(count).isEqualTo(0); + assertThat(messagePayloadReference.get()).isEqualTo("Reversed: !dlrow olleH"); } @Configuration diff --git a/spring-boot-samples/spring-boot-sample-websocket-jetty/src/test/java/samples/websocket/jetty/snake/SnakeTimerTests.java b/spring-boot-samples/spring-boot-sample-websocket-jetty/src/test/java/samples/websocket/jetty/snake/SnakeTimerTests.java index 149978e313..bdb14a0c98 100644 --- a/spring-boot-samples/spring-boot-sample-websocket-jetty/src/test/java/samples/websocket/jetty/snake/SnakeTimerTests.java +++ b/spring-boot-samples/spring-boot-sample-websocket-jetty/src/test/java/samples/websocket/jetty/snake/SnakeTimerTests.java @@ -20,8 +20,7 @@ import java.io.IOException; import org.junit.Test; -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; +import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.BDDMockito.willThrow; import static org.mockito.Matchers.anyString; import static org.mockito.Mockito.mock; @@ -35,7 +34,7 @@ public class SnakeTimerTests { SnakeTimer.addSnake(snake); SnakeTimer.broadcast(""); - assertThat(SnakeTimer.getSnakes().size(), is(0)); + assertThat(SnakeTimer.getSnakes()).hasSize(0); } } diff --git a/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/test/java/samples/websocket/tomcat/SampleWebSocketsApplicationTests.java b/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/test/java/samples/websocket/tomcat/SampleWebSocketsApplicationTests.java index 20b8380a12..d64d42f953 100644 --- a/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/test/java/samples/websocket/tomcat/SampleWebSocketsApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/test/java/samples/websocket/tomcat/SampleWebSocketsApplicationTests.java @@ -24,7 +24,6 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.junit.Test; import org.junit.runner.RunWith; -import org.springframework.boot.test.WebIntegrationTest; import samples.websocket.tomcat.client.GreetingService; import samples.websocket.tomcat.client.SimpleClientWebSocketHandler; import samples.websocket.tomcat.client.SimpleGreetingService; @@ -34,6 +33,7 @@ import org.springframework.boot.CommandLineRunner; import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.test.SpringApplicationConfiguration; +import org.springframework.boot.test.WebIntegrationTest; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -42,7 +42,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.web.socket.client.WebSocketConnectionManager; 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) @SpringApplicationConfiguration(SampleTomcatWebSocketApplication.class) @@ -66,8 +66,9 @@ public class SampleWebSocketsApplicationTests { AtomicReference<String> messagePayloadReference = context .getBean(ClientConfiguration.class).messagePayload; context.close(); - assertEquals(0, count); - assertEquals("Did you say \"Hello world!\"?", messagePayloadReference.get()); + assertThat(count).isEqualTo(0); + assertThat(messagePayloadReference.get()) + .isEqualTo("Did you say \"Hello world!\"?"); } @Test @@ -81,8 +82,8 @@ public class SampleWebSocketsApplicationTests { AtomicReference<String> messagePayloadReference = context .getBean(ClientConfiguration.class).messagePayload; context.close(); - assertEquals(0, count); - assertEquals("Reversed: !dlrow olleH", messagePayloadReference.get()); + assertThat(count).isEqualTo(0); + assertThat(messagePayloadReference.get()).isEqualTo("Reversed: !dlrow olleH"); } @Configuration diff --git a/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/test/java/samples/websocket/tomcat/echo/CustomContainerWebSocketsApplicationTests.java b/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/test/java/samples/websocket/tomcat/echo/CustomContainerWebSocketsApplicationTests.java index 8db59d37a1..16b2b814a8 100644 --- a/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/test/java/samples/websocket/tomcat/echo/CustomContainerWebSocketsApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/test/java/samples/websocket/tomcat/echo/CustomContainerWebSocketsApplicationTests.java @@ -24,7 +24,6 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.junit.Test; import org.junit.runner.RunWith; -import org.springframework.boot.test.WebIntegrationTest; import samples.websocket.tomcat.SampleTomcatWebSocketApplication; import samples.websocket.tomcat.client.GreetingService; import samples.websocket.tomcat.client.SimpleClientWebSocketHandler; @@ -38,6 +37,7 @@ import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory; import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory; import org.springframework.boot.test.SpringApplicationConfiguration; +import org.springframework.boot.test.WebIntegrationTest; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -47,7 +47,7 @@ import org.springframework.util.SocketUtils; import org.springframework.web.socket.client.WebSocketConnectionManager; 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) @SpringApplicationConfiguration({ SampleTomcatWebSocketApplication.class, @@ -72,8 +72,9 @@ public class CustomContainerWebSocketsApplicationTests { AtomicReference<String> messagePayloadReference = context .getBean(ClientConfiguration.class).messagePayload; context.close(); - assertEquals(0, count); - assertEquals("Did you say \"Hello world!\"?", messagePayloadReference.get()); + assertThat(count).isEqualTo(0); + assertThat(messagePayloadReference.get()) + .isEqualTo("Did you say \"Hello world!\"?"); } @Test @@ -87,8 +88,8 @@ public class CustomContainerWebSocketsApplicationTests { AtomicReference<String> messagePayloadReference = context .getBean(ClientConfiguration.class).messagePayload; context.close(); - assertEquals(0, count); - assertEquals("Reversed: !dlrow olleH", messagePayloadReference.get()); + assertThat(count).isEqualTo(0); + assertThat(messagePayloadReference.get()).isEqualTo("Reversed: !dlrow olleH"); } @Configuration diff --git a/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/test/java/samples/websocket/tomcat/snake/SnakeTimerTests.java b/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/test/java/samples/websocket/tomcat/snake/SnakeTimerTests.java index eecf2ad6d8..92249d618c 100644 --- a/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/test/java/samples/websocket/tomcat/snake/SnakeTimerTests.java +++ b/spring-boot-samples/spring-boot-sample-websocket-tomcat/src/test/java/samples/websocket/tomcat/snake/SnakeTimerTests.java @@ -20,8 +20,7 @@ import java.io.IOException; import org.junit.Test; -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; +import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.BDDMockito.willThrow; import static org.mockito.Matchers.anyString; import static org.mockito.Mockito.mock; @@ -35,6 +34,6 @@ public class SnakeTimerTests { SnakeTimer.addSnake(snake); SnakeTimer.broadcast(""); - assertThat(SnakeTimer.getSnakes().size(), is(0)); + assertThat(SnakeTimer.getSnakes()).hasSize(0); } } diff --git a/spring-boot-samples/spring-boot-sample-websocket-undertow/src/test/java/samples/websocket/undertow/SampleWebSocketsApplicationTests.java b/spring-boot-samples/spring-boot-sample-websocket-undertow/src/test/java/samples/websocket/undertow/SampleWebSocketsApplicationTests.java index 65edef653b..8c4a125248 100644 --- a/spring-boot-samples/spring-boot-sample-websocket-undertow/src/test/java/samples/websocket/undertow/SampleWebSocketsApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-websocket-undertow/src/test/java/samples/websocket/undertow/SampleWebSocketsApplicationTests.java @@ -24,7 +24,6 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.junit.Test; import org.junit.runner.RunWith; -import org.springframework.boot.test.WebIntegrationTest; import samples.websocket.undertow.client.GreetingService; import samples.websocket.undertow.client.SimpleClientWebSocketHandler; import samples.websocket.undertow.client.SimpleGreetingService; @@ -34,6 +33,7 @@ import org.springframework.boot.CommandLineRunner; import org.springframework.boot.autoconfigure.PropertyPlaceholderAutoConfiguration; import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.test.SpringApplicationConfiguration; +import org.springframework.boot.test.WebIntegrationTest; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -42,7 +42,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.web.socket.client.WebSocketConnectionManager; 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) @SpringApplicationConfiguration(SampleUndertowWebSocketsApplication.class) @@ -66,8 +66,9 @@ public class SampleWebSocketsApplicationTests { AtomicReference<String> messagePayloadReference = context .getBean(ClientConfiguration.class).messagePayload; context.close(); - assertEquals(0, count); - assertEquals("Did you say \"Hello world!\"?", messagePayloadReference.get()); + assertThat(count).isEqualTo(0); + assertThat(messagePayloadReference.get()) + .isEqualTo("Did you say \"Hello world!\"?"); } @Test @@ -81,8 +82,8 @@ public class SampleWebSocketsApplicationTests { AtomicReference<String> messagePayloadReference = context .getBean(ClientConfiguration.class).messagePayload; context.close(); - assertEquals(0, count); - assertEquals("Reversed: !dlrow olleH", messagePayloadReference.get()); + assertThat(count).isEqualTo(0); + assertThat(messagePayloadReference.get()).isEqualTo("Reversed: !dlrow olleH"); } @Configuration diff --git a/spring-boot-samples/spring-boot-sample-websocket-undertow/src/test/java/samples/websocket/undertow/echo/CustomContainerWebSocketsApplicationTests.java b/spring-boot-samples/spring-boot-sample-websocket-undertow/src/test/java/samples/websocket/undertow/echo/CustomContainerWebSocketsApplicationTests.java index ce73a6a8e5..0d1a8598f3 100644 --- a/spring-boot-samples/spring-boot-sample-websocket-undertow/src/test/java/samples/websocket/undertow/echo/CustomContainerWebSocketsApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-websocket-undertow/src/test/java/samples/websocket/undertow/echo/CustomContainerWebSocketsApplicationTests.java @@ -24,7 +24,6 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.junit.Test; import org.junit.runner.RunWith; -import org.springframework.boot.test.WebIntegrationTest; import samples.websocket.undertow.SampleUndertowWebSocketsApplication; import samples.websocket.undertow.client.GreetingService; import samples.websocket.undertow.client.SimpleClientWebSocketHandler; @@ -38,6 +37,7 @@ import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory; import org.springframework.boot.context.embedded.undertow.UndertowEmbeddedServletContainerFactory; import org.springframework.boot.test.SpringApplicationConfiguration; +import org.springframework.boot.test.WebIntegrationTest; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -47,7 +47,7 @@ import org.springframework.util.SocketUtils; import org.springframework.web.socket.client.WebSocketConnectionManager; 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) @SpringApplicationConfiguration({ SampleUndertowWebSocketsApplication.class, @@ -72,8 +72,9 @@ public class CustomContainerWebSocketsApplicationTests { AtomicReference<String> messagePayloadReference = context .getBean(ClientConfiguration.class).messagePayload; context.close(); - assertEquals(0, count); - assertEquals("Did you say \"Hello world!\"?", messagePayloadReference.get()); + assertThat(count).isEqualTo(0); + assertThat(messagePayloadReference.get()) + .isEqualTo("Did you say \"Hello world!\"?"); } @Test @@ -87,8 +88,8 @@ public class CustomContainerWebSocketsApplicationTests { AtomicReference<String> messagePayloadReference = context .getBean(ClientConfiguration.class).messagePayload; context.close(); - assertEquals(0, count); - assertEquals("Reversed: !dlrow olleH", messagePayloadReference.get()); + assertThat(count).isEqualTo(0); + assertThat(messagePayloadReference.get()).isEqualTo("Reversed: !dlrow olleH"); } @Configuration diff --git a/spring-boot-samples/spring-boot-sample-websocket-undertow/src/test/java/samples/websocket/undertow/snake/SnakeTimerTests.java b/spring-boot-samples/spring-boot-sample-websocket-undertow/src/test/java/samples/websocket/undertow/snake/SnakeTimerTests.java index 64bbd24bf3..4fcd726549 100644 --- a/spring-boot-samples/spring-boot-sample-websocket-undertow/src/test/java/samples/websocket/undertow/snake/SnakeTimerTests.java +++ b/spring-boot-samples/spring-boot-sample-websocket-undertow/src/test/java/samples/websocket/undertow/snake/SnakeTimerTests.java @@ -20,8 +20,7 @@ import java.io.IOException; import org.junit.Test; -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; +import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.BDDMockito.willThrow; import static org.mockito.Matchers.anyString; import static org.mockito.Mockito.mock; @@ -35,6 +34,6 @@ public class SnakeTimerTests { SnakeTimer.addSnake(snake); SnakeTimer.broadcast(""); - assertThat(SnakeTimer.getSnakes().size(), is(0)); + assertThat(SnakeTimer.getSnakes()).hasSize(0); } } diff --git a/spring-boot-samples/spring-boot-sample-ws/src/test/java/sample/ws/SampleWsApplicationTests.java b/spring-boot-samples/spring-boot-sample-ws/src/test/java/sample/ws/SampleWsApplicationTests.java index 2a2a79dc37..2f71d01d59 100644 --- a/spring-boot-samples/spring-boot-sample-ws/src/test/java/sample/ws/SampleWsApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-ws/src/test/java/sample/ws/SampleWsApplicationTests.java @@ -32,8 +32,7 @@ import org.springframework.boot.test.WebIntegrationTest; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.ws.client.core.WebServiceTemplate; -import static org.hamcrest.Matchers.containsString; -import static org.junit.Assert.assertThat; +import static org.assertj.core.api.Assertions.assertThat; @RunWith(SpringJUnit4ClassRunner.class) @SpringApplicationConfiguration(SampleWsApplication.class) @@ -68,7 +67,7 @@ public class SampleWsApplicationTests { StreamResult result = new StreamResult(System.out); this.webServiceTemplate.sendSourceAndReceiveToResult(source, result); - assertThat(this.output.toString(), containsString("Booking holiday for")); + assertThat(this.output.toString()).contains("Booking holiday for"); } } diff --git a/spring-boot-samples/spring-boot-sample-xml/src/test/java/sample/xml/SampleSpringXmlApplicationTests.java b/spring-boot-samples/spring-boot-sample-xml/src/test/java/sample/xml/SampleSpringXmlApplicationTests.java index 0b25755ac0..b8d8094e99 100644 --- a/spring-boot-samples/spring-boot-sample-xml/src/test/java/sample/xml/SampleSpringXmlApplicationTests.java +++ b/spring-boot-samples/spring-boot-sample-xml/src/test/java/sample/xml/SampleSpringXmlApplicationTests.java @@ -21,7 +21,7 @@ import org.junit.Test; import org.springframework.boot.test.OutputCapture; -import static org.junit.Assert.assertTrue; +import static org.assertj.core.api.Assertions.assertThat; public class SampleSpringXmlApplicationTests { @@ -32,7 +32,7 @@ public class SampleSpringXmlApplicationTests { public void testDefaultSettings() throws Exception { SampleSpringXmlApplication.main(new String[0]); String output = this.outputCapture.toString(); - assertTrue("Wrong output: " + output, output.contains("Hello World")); + assertThat(output).contains("Hello World"); } }