DATAKV-225 - Add support for immutable objects.

Add return type to KeyValueOperations.insert/update methods to return potentially changed object instances. Return KeyValueOperations.insert/update method result in SimpleKeyValueRepository.save(…).
This commit is contained in:
Mark Paluch
2018-07-03 16:30:27 +02:00
committed by Oliver Gierke
parent c2da46a5b7
commit 4f49fe98f4
4 changed files with 44 additions and 16 deletions

View File

@@ -110,6 +110,15 @@ public class KeyValueTemplateUnitTests {
verify(adapterMock, times(1)).put("1", FOO_ONE, Foo.class.getName());
}
@Test // DATACMNS-225
public void insertShouldReturnInsertedObject() {
ClassWithStringId object = new ClassWithStringId();
assertThat(template.insert(object), is(object));
assertThat(template.insert("1", object), is(object));
}
@Test // DATACMNS-525
public void insertShouldThrowExceptionWhenObectWithIdAlreadyExists() {
@@ -225,6 +234,16 @@ public class KeyValueTemplateUnitTests {
verify(adapterMock, times(1)).put("1", FOO_TWO, Foo.class.getName());
}
@Test // DATAKV-225
public void updateShouldReturnUpdatedObject() {
ClassWithStringId object = new ClassWithStringId();
object.id = "foo";
assertThat(template.update(object), is(object));
assertThat(template.update("1", object), is(object));
}
@Test(expected = IllegalArgumentException.class) // DATACMNS-525
public void updateShouldThrowExceptionWhenGivenNullId() {
template.update(null, FOO_ONE);