Skip to content

Commit 54c7603

Browse files
schaudermp911de
authored andcommitted
DATAKV-330 - Implement CrudRepository.deleteAllById(Iterable<ID> ids).
Original pull request: #52.
1 parent 9fc180f commit 54c7603

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

src/main/java/org/springframework/data/keyvalue/repository/support/SimpleKeyValueRepository.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,14 @@ public void deleteAll(Iterable<? extends T> entities) {
216216
entities.forEach(this::delete);
217217
}
218218

219+
@Override
220+
public void deleteAllById(Iterable<? extends ID> ids) {
221+
222+
Assert.notNull(ids, "The given Iterable of Ids must not be null!");
223+
224+
ids.forEach(this::deleteById);
225+
}
226+
219227
/*
220228
* (non-Javadoc)
221229
* @see org.springframework.data.repository.CrudRepository#deleteAll()

src/test/java/org/springframework/data/keyvalue/repository/SimpleKeyValueRepositoryUnitTests.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package org.springframework.data.keyvalue.repository;
1717

18+
import static java.util.Arrays.*;
1819
import static org.assertj.core.api.Assertions.*;
1920
import static org.mockito.ArgumentMatchers.*;
2021
import static org.mockito.Mockito.*;
@@ -46,6 +47,7 @@
4647
/**
4748
* @author Christoph Strobl
4849
* @author Eugene Nikiforov
50+
* @author Jens Schauder
4951
*/
5052
@RunWith(MockitoJUnitRunner.class)
5153
public class SimpleKeyValueRepositoryUnitTests {
@@ -94,7 +96,7 @@ public void multipleSave() {
9496
Foo one = new Foo("one");
9597
Foo two = new Foo("two");
9698

97-
repo.saveAll(Arrays.asList(one, two));
99+
repo.saveAll(asList(one, two));
98100
verify(opsMock, times(1)).insert(eq(one));
99101
verify(opsMock, times(1)).insert(eq(two));
100102
}
@@ -118,6 +120,15 @@ public void deleteById() {
118120
verify(opsMock, times(1)).delete(eq("one"), eq(Foo.class));
119121
}
120122

123+
@Test // DATAKV-330
124+
public void deleteAllById() {
125+
126+
repo.deleteAllById(asList("one", "two"));
127+
128+
verify(opsMock, times(1)).delete(eq("one"), eq(Foo.class));
129+
verify(opsMock, times(1)).delete(eq("two"), eq(Foo.class));
130+
}
131+
121132
@Test // DATACMNS-525
122133
public void deleteAll() {
123134

@@ -131,7 +142,7 @@ public void deleteAll() {
131142
public void findAllIds() {
132143

133144
when(opsMock.findById(any(), any(Class.class))).thenReturn(Optional.empty());
134-
repo.findAllById(Arrays.asList("one", "two", "three"));
145+
repo.findAllById(asList("one", "two", "three"));
135146

136147
verify(opsMock, times(3)).findById(anyString(), eq(Foo.class));
137148
}

src/test/java/org/springframework/data/map/AbstractRepositoryUnitTests.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
* @author Oliver Gierke
4444
* @author Thomas Darimont
4545
* @author Mark Paluch
46+
* @author Jens Schauder
4647
*/
4748
public abstract class AbstractRepositoryUnitTests<T extends AbstractRepositoryUnitTests.PersonRepository> {
4849

0 commit comments

Comments
 (0)