code format

This commit is contained in:
jesus-dayo 2016-08-15 13:44:56 +08:00
parent 4fff6716e5
commit a9d714c389
10 changed files with 91 additions and 113 deletions

View File

@ -23,5 +23,4 @@ public class MyResourceNotFoundException extends RuntimeException {
super(cause);
}
}

View File

@ -13,7 +13,6 @@ import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter
@Import(PersistenceConfig.class)
public class Application extends WebMvcConfigurerAdapter {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}

View File

@ -26,10 +26,7 @@ public class PersistenceConfig {
@Bean
public DataSource dataSource() {
EmbeddedDatabaseBuilder builder = new EmbeddedDatabaseBuilder();
EmbeddedDatabase db = builder
.setType(EmbeddedDatabaseType.HSQL)
.addScript("db/sql/data.sql")
.build();
EmbeddedDatabase db = builder.setType(EmbeddedDatabaseType.HSQL).addScript("db/sql/data.sql").build();
return db;
}

View File

@ -16,8 +16,7 @@ public class StudentDirectoryRestController {
@Autowired
private StudentService service;
@RequestMapping(value = "/student/get", params = { "page",
"size" }, method = RequestMethod.GET, produces = "application/json")
@RequestMapping(value = "/student/get", params = { "page", "size" }, method = RequestMethod.GET, produces = "application/json")
public Page<Student> findPaginated(@RequestParam("page") int page, @RequestParam("size") int size) {
Page<Student> resultPage = service.findPaginated(page, size);

View File

@ -2,6 +2,6 @@ package org.baeldung.web.service;
import org.baeldung.web.entity.Student;
public interface StudentService extends IOperations<Student>{
public interface StudentService extends IOperations<Student> {
}

View File

@ -15,7 +15,7 @@ public class StudentServiceImpl implements StudentService {
@Override
public Page<Student> findPaginated(int page, int size) {
return dao.findAll(new PageRequest(page,size));
return dao.findAll(new PageRequest(page, size));
}
}

View File

@ -24,58 +24,42 @@ public class StudentServiceTest {
@Test
public void givenRequestForStudents_whenPageIsOne_expectContainsNames() {
given().params("page", "0", "size", "2").get(ENDPOINT)
.then()
.assertThat().body("content.name", hasItems("Bryan", "Ben"));
given().params("page", "0", "size", "2").get(ENDPOINT).then().assertThat().body("content.name", hasItems("Bryan", "Ben"));
}
@Test
public void givenRequestForStudents_whenSizeIsTwo_expectTwoItems() {
given().params("page", "0", "size", "2").get(ENDPOINT)
.then()
.assertThat().body("size", equalTo(2));
given().params("page", "0", "size", "2").get(ENDPOINT).then().assertThat().body("size", equalTo(2));
}
@Test
public void givenRequestForStudents_whenSizeIsTwo_expectNumberOfElementsTwo() {
given().params("page", "0", "size", "2").get(ENDPOINT)
.then()
.assertThat().body("numberOfElements", equalTo(2));
given().params("page", "0", "size", "2").get(ENDPOINT).then().assertThat().body("numberOfElements", equalTo(2));
}
@Test
public void givenRequestForStudents_whenResourcesAreRetrievedPaged_thenExpect200() {
given().params("page", "0", "size", "2").get(ENDPOINT)
.then()
.statusCode(200);
given().params("page", "0", "size", "2").get(ENDPOINT).then().statusCode(200);
}
@Test
public void givenRequestForStudents_whenPageOfResourcesAreRetrievedOutOfBounds_thenExpect500() {
given().params("page", "1000", "size", "2").get(ENDPOINT)
.then()
.statusCode(500);
given().params("page", "1000", "size", "2").get(ENDPOINT).then().statusCode(500);
}
@Test
public void givenRequestForStudents_whenPageNotValid_thenExpect500() {
given().params("page", RandomStringUtils.randomNumeric(5), "size", "2").get(ENDPOINT)
.then()
.statusCode(500);
given().params("page", RandomStringUtils.randomNumeric(5), "size", "2").get(ENDPOINT).then().statusCode(500);
}
@Test
public void givenRequestForStudents_whenPageSizeIsFive_expectFiveItems() {
given().params("page", "0", "size", "5").get(ENDPOINT)
.then()
.body("content.size()", is(5));
given().params("page", "0", "size", "5").get(ENDPOINT).then().body("content.size()", is(5));
}
@Test
public void givenResourcesExist_whenFirstPageIsRetrieved_thenPageContainsResources() {
given().params("page", "0", "size", "2").get(ENDPOINT)
.then()
.assertThat().body("first", equalTo(true));
given().params("page", "0", "size", "2").get(ENDPOINT).then().assertThat().body("first", equalTo(true));
}
}