Use AssertJ in spring-boot-samples
See gh-5083
This commit is contained in:
@@ -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");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user