#381 - Adapt examples to immutable object support.

Provide mutable property accessors to allow object mutation.
This commit is contained in:
Mark Paluch
2018-07-26 11:07:42 +02:00
parent e2d2bdf6bc
commit 1c56cf8fba
5 changed files with 29 additions and 14 deletions

View File

@@ -18,6 +18,7 @@ package example.springdata.rest.stores;
import static org.springframework.data.mongodb.core.index.GeoSpatialIndexType.*;
import lombok.Value;
import lombok.experimental.Wither;
import java.util.UUID;
@@ -30,12 +31,14 @@ import org.springframework.data.mongodb.core.mapping.Document;
* Entity to represent a {@link Store}.
*
* @author Oliver Gierke
* @author Mark Paluch
*/
@Value
@Wither
@Document
public class Store {
@Id UUID id = UUID.randomUUID();
@Id UUID id;
String name;
Address address;

View File

@@ -21,6 +21,7 @@ import lombok.extern.slf4j.Slf4j;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.UUID;
import org.springframework.batch.item.ExecutionContext;
import org.springframework.batch.item.file.FlatFileItemReader;
@@ -37,6 +38,7 @@ import org.springframework.stereotype.Component;
* Component initializing a hand full of Starbucks stores and persisting them through a {@link StoreRepository}.
*
* @author Oliver Gierke
* @author Mark Paluch
*/
@Slf4j
@Component
@@ -84,7 +86,7 @@ public class StoreInitializer {
Address address = new Address(fields.readString("Street Address"), fields.readString("City"),
fields.readString("Zip"), location);
return new Store(fields.readString("Name"), address);
return new Store(UUID.randomUUID(), fields.readString("Name"), address);
});
lineMapper.setLineTokenizer(tokenizer);

View File

@@ -20,6 +20,8 @@ import static org.junit.Assert.*;
import example.springdata.rest.stores.Store.Address;
import java.util.UUID;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -37,6 +39,7 @@ import org.springframework.test.context.junit4.SpringRunner;
* Integration tests for {@link StoreRepository}.
*
* @author Oliver Gierke
* @author Mark Paluch
*/
@RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class)
@@ -54,7 +57,7 @@ public class StoreRepositoryIntegrationTests {
public void findsStoresByLocation() {
Point location = new Point(-73.995146, 40.740337);
Store store = new Store("Foo", new Address("street", "city", "zip", location));
Store store = new Store(UUID.randomUUID(), "Foo", new Address("street", "city", "zip", location));
store = repository.save(store);