@@ -40,10 +40,10 @@ public class Application {
|
||||
|
||||
public @PostConstruct void init() {
|
||||
|
||||
Customer dave = customers.save(new Customer("Dave", "Matthews", Gender.MALE, //
|
||||
var dave = customers.save(new Customer("Dave", "Matthews", Gender.MALE, //
|
||||
new Address("4711 Some Place", "54321", "Charlottesville", "VA")));
|
||||
|
||||
Order order = new Order();
|
||||
var order = new Order();
|
||||
|
||||
order.setCustomer(dave);
|
||||
order.add(new LineItem("Lakewood guitar", new BigDecimal(1299.0)));
|
||||
|
||||
@@ -46,7 +46,7 @@ public class Customer {
|
||||
this.gender = null;
|
||||
}
|
||||
|
||||
static enum Gender {
|
||||
MALE, FEMALE;
|
||||
enum Gender {
|
||||
MALE, FEMALE
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,13 +15,12 @@
|
||||
*/
|
||||
package example.springdata.rest.projections;
|
||||
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Integration tests to bootstrap the application.
|
||||
*
|
||||
@@ -35,8 +34,8 @@ public class ApplicationIntegrationTests {
|
||||
@Test
|
||||
public void initializesRepositoryWithSampleData() {
|
||||
|
||||
Iterable<Order> result = repository.findAll();
|
||||
var result = repository.findAll();
|
||||
|
||||
assertThat(result, is(iterableWithSize(1)));
|
||||
assertThat(result).hasSize(1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,9 +15,6 @@
|
||||
*/
|
||||
package example.springdata.rest.projections;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.*;
|
||||
import static org.hamcrest.MatcherAssert.*;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -27,6 +24,8 @@ import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.data.projection.ProjectionFactory;
|
||||
import org.springframework.data.projection.SpelAwareProxyProjectionFactory;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Test cases showing the programatic use of a {@link ProjectionFactory}.
|
||||
*
|
||||
@@ -40,16 +39,16 @@ class SimpleProjectionTests {
|
||||
@Test
|
||||
void createMapBackedProjection() {
|
||||
|
||||
Customer customer = factory.createProjection(Customer.class);
|
||||
var customer = factory.createProjection(Customer.class);
|
||||
customer.setFirstname("Dave");
|
||||
customer.setLastname("Matthews");
|
||||
|
||||
// Verify accessors work
|
||||
assertThat(customer.getFirstname(), is("Dave"));
|
||||
assertThat(customer.getLastname(), is("Matthews"));
|
||||
assertThat(customer.getFirstname()).isEqualTo("Dave");
|
||||
assertThat(customer.getLastname()).isEqualTo("Matthews");
|
||||
|
||||
// Verify evaluating a SpEL expression
|
||||
assertThat(customer.getFullName(), is("Dave Matthews"));
|
||||
assertThat(customer.getFullName()).isEqualTo("Dave Matthews");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -59,11 +58,11 @@ class SimpleProjectionTests {
|
||||
backingMap.put("firstname", "Dave");
|
||||
backingMap.put("lastname", "Matthews");
|
||||
|
||||
Customer customer = factory.createProjection(Customer.class, backingMap);
|
||||
var customer = factory.createProjection(Customer.class, backingMap);
|
||||
|
||||
// Verify accessors work
|
||||
assertThat(customer.getFirstname(), is("Dave"));
|
||||
assertThat(customer.getLastname(), is("Matthews"));
|
||||
assertThat(customer.getFirstname()).isEqualTo("Dave");
|
||||
assertThat(customer.getLastname()).isEqualTo("Matthews");
|
||||
}
|
||||
|
||||
interface Customer {
|
||||
|
||||
Reference in New Issue
Block a user